1

I am trying to achieve something like this for the section title

----------
| title |-------------------------------------------------------------------
----------

So far I have this code using the tikz library, which I would like to use because of the flexibility and elegance it provides

\documentclass[12pt]{article}

\usepackage[sfdefault]{roboto} \usepackage[top=1cm, left=0.5cm, right=0.5cm, bottom=0.5cm]{geometry} \usepackage[explicit]{titlesec} \usepackage{tikz} \definecolor{seccolor}{RGB}{41,48,57} \titleformat{\section} [hang] {\Large\bfseries} {} {0pt} {\tikz{ \nodedraw, rounded corners=1mm{\Large\bfseries\textcolor{seccolor}{}#1}; \node[draw=none] (b) at (\textwidth-2em,0) {}; \draw[] (a)--(b)}} \begin{document}

\section{Summary}

\section{Literature Review}

\end{document}

which basically works. However a couple of this I would like to improve:

  1. I would like to increate the line thickness.
  2. I would like the line to end exactly at the right margin I specified, which isn't achieved using the above code for different section's titles' lengths.

How can I achieve these two improvements?

BlackMath
  • 169
  • To increase the width of the line forming the rounded corner box, you can use line width, as for example in \node[draw, rounded corners=1mm, line width=2pt]. – leandriis May 26 '21 at 18:12
  • @leandriis Right. Thanks. I tried it before, but apparently I used it in the dummy node, which has draw=none, and I was wondering why it wasn't working. What about the line length, how can I dynamically control it based on the box size so that it ends exactly at the end of the text width? – BlackMath May 26 '21 at 18:20

1 Answers1

3
 \documentclass[12pt]{article}
\usepackage[sfdefault]{roboto}
\usepackage[top=1cm, left=0.5cm, right=0.5cm, bottom=0.5cm]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\definecolor{seccolor}{RGB}{41,48,57}
 \titleformat{\section}
    [hang]
    {\Large\bfseries}
    {}
    {0pt}
    {\tikz{
    \node[draw, rounded corners=1mm,text depth=0.2ex,line width=2pt,anchor=west](a){\Large\bfseries\textcolor{seccolor}{}#1};
    \coordinate (b) at (\textwidth-2em,0);
    \draw[line width=2pt] (a)--(b);}}

\begin{document}

\section{Summary}

\section{Literature Review}

\end{document}

section title

vi pa
  • 3,394