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{
    \node[draw, rounded corners=1mm](a){\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?

2
  • 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
    Commented May 26, 2021 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
    Commented May 26, 2021 at 18:20

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .