TeX - LaTeX Asked on November 6, 2021
So I decided to try TikZ With titlesec
by customising the section header design. This is what I have so far.
documentclass[10pt]{article}
usepackage{tikz}
usepackage{titlesec}
usepackage{titletoc}
usepackage[
a4paper,
twoside,
portrait,
top=1.6cm,
bottom=1.6cm,
left=0.75in,
right=0.75in,
headheight=15pt,
includehead, includefoot,
footskip=1.4cm, % Space from the bottom margin to the baseline of the footer
headsep=10pt, % Space from the top margin to the baseline of the header
heightrounded
]{geometry}
usepackage{blindtext}
usepackage{fontspec}
usepackage{xcolor}
usepackage{tcolorbox}
setmainfont[
BoldFont = Roboto-Bold
]{Roboto}
defaultfontfeatures{Ligatures=TeX}
defaultfontfeatures{Scale = MatchLowercase}
titleformat{section}
{Largebfseriescolor{black}}
{
begin{tikzpicture}
node (rect) at (0pt,0pt) [draw,thick,minimum width=4pt,minimum height=4pt] {thesection};
end{tikzpicture}
}
{0.4em}
{}
begin{document}
section{Test Section}
blindtext[2]
end{document}
And here is the output:
Which is great and all, but it would be nice if I could shift that box so that it is either level or inline with the section name horizontally. Is there a way to do this?
I have commented out fontspec to avoid lua compilation and instead of tikz I used tcolorbox which works fine --use the baseline option for shifting the number box up or down
documentclass[10pt]{article}
usepackage{tikz}
usepackage{titlesec}
usepackage{titletoc}
usepackage[
a4paper,
twoside,
portrait,
top=1.6cm,
bottom=1.6cm,
left=0.75in,
right=0.75in,
headheight=15pt,
includehead, includefoot,
footskip=1.4cm, % Space from the bottom margin to the baseline of the footer
headsep=10pt, % Space from the top margin to the baseline of the header
heightrounded
]{geometry}
usepackage{blindtext}
usetikzlibrary{calc}
%usepackage{fontspec}
usepackage{xcolor}
usepackage{tcolorbox}
%setmainfont[
% BoldFont = Roboto-Bold
%]{Roboto}
%defaultfontfeatures{Ligatures=TeX}
%defaultfontfeatures{Scale = MatchLowercase}
%titleformat{section}
% {Largebfseriescolor{black}}
% {
% begin{tikzpicture}
% node (rect) at (0pt,0pt) [draw,
% thick,
% minimum width=4pt,
% minimum height=4pt,
%% remember picture,
% baseline={([yshift=-15pt]thesection.east)}] {thesection};
% end{tikzpicture}
% }
% {0.4em}
% {}
titleformat{section}
{normalfontLargesffamilybfseriescolor{black}}
{tcbox[colback=blue!30, colframe=blue!50, coltext=black, on line, boxsep=0pt, left=4pt, right=4pt, top=4pt, bottom=4pt,baseline=2pt]{thesection}}{0.4em}{}
begin{document}
section{Test Section}
blindtext[2]
end{document}
edit --using tikz as a solution
documentclass[10pt]{article}
usepackage{tikz}
usepackage{titlesec}
usepackage{titletoc}
usepackage[
a4paper,
twoside,
portrait,
top=1.6cm,
bottom=1.6cm,
left=0.75in,
right=0.75in,
headheight=15pt,
includehead, includefoot,
footskip=1.4cm, % Space from the bottom margin to the baseline of the
footer
headsep=10pt, % Space from the top margin to the baseline of the header
heightrounded
]{geometry}
usepackage{blindtext}
usetikzlibrary{calc}
%usepackage{fontspec}
usepackage{xcolor}
usepackage{tcolorbox}
%setmainfont[
% BoldFont = Roboto-Bold
% ]{Roboto}
%defaultfontfeatures{Ligatures=TeX}
%defaultfontfeatures{Scale = MatchLowercase}
titleformat{section}
{Largebfseriescolor{black}}
{
begin{tikzpicture}
node (rect) at (0pt,0pt) [draw,
thick,
minimum width=4pt,
minimum height=4pt,
remember picture,
overlay,
baseline=
(rect.base),
anchor=base,yshift=4pt]
{thesection};
end{tikzpicture}
}
{0.4em}
{}
begin{document}
section{Test Section}
blindtext[2]
end{document}
Answered by js bibra on November 6, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP