How can i make a titleformat that fills in the whole line? Something like that:

«counter» «name» « ------ rule fill --------»

Normal text....

I managed to do it using the runin type but it has several problems:

\newcommand{\crulefill}{\leavevmode\leaders\hrule height 0.7ex depth\dimexpr 0.5pt-0.7ex\hfill\kern 0pt}

\titleformat{\section}[runin] {\bfseries\Large} {\fboxrule=0.5pt\fcolorbox{black}{white!0}{{\color{black}\thesection.}}\rule[.7ex]{10pt}{.5pt}\ } {0pt} {\upshape\bfseries\Large} [\ \crulefill\vspace*{1.5ex}~\\hspace*{6pt}]

  1. \vspace defines the separation between the normal text and the section.
  2. \hspace defines the separation in the first line of the normal text (the indentation)
  3. When there is no text between a section and a subsection, the space is too large, but when there is text, the space is fine.

Note the space between 1.1 and 1.1.1 when there is no text

1 Answer 1


A solution with the default hang style,and the explicit option:




\newcommand{\crulefill}{\leavevmode\leaders\hrule height 0.7ex depth\dimexpr 0.5pt-0.7ex\hfill\kern 0pt}

\titleformat{\section}{\bfseries\Large} {\fboxrule=0.5pt\fcolorbox{black}{white!0}{{\color{black}\thesection.}}\rule[.7ex]{10pt}{.5pt} } {0pt} {\upshape\bfseries\Large#1 \ \crulefill}%

\titleformat{\subsection}{\bfseries\large} {\thesubsection.\enspace\color{LightSteelBlue}\vrule}{0.6em} {#1}




enter image description here

  • \color{LightSteelBlue}\vrule\color{black} should be {\color{LightSteelBlue}\vrule}
    – egreg
    Jul 17, 2018 at 21:33
  • @egreg: That's right. I thought I had to revert to the default colour, but you're right. I've changed the code. Thanks for the tip!
    – Bernard
    Jul 17, 2018 at 21:37

You must log in to answer this question.

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