1

I want do exactly this: http://www.latex-community.org/forum/viewtopic.php?f=44&p=42626

But as a general command for all subsection titles.

I have the feeling that I am going to use the \titleformat command, but not sure how. All other properties of subsections must stay the same; the only change I want is the addition of a line from where the title ends and extending all the way to the end of the line.

Steeven
  • 1,407

1 Answers1

2

This can be achieved for example with a small patch to the \@sect command, which is responsible for the typesetting of the section title.

The specific section type must be filtered and then \xrfill with a raising of about half of the letter height (0.5ex), a rule width and a rule colour (see the package documentation) (For this question I used some code from my answer to this question here: Underline subsection heading)

\documentclass{article}

\usepackage{xhfill}

\newlength{\subsectionrulewidth}
\newlength{\subsectionruleraise}
\setlength{\subsectionrulewidth}{2pt}
\setlength{\subsectionruleraise}{0.5ex}
\newcommand{\subsectionrulecolour}{blue}


\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@sect}{%
  #8%
}{%
  \ifstrequal{#1}{subsection}{%
    #8 \xrfill[\subsectionruleraise]{\subsectionrulewidth}[\subsectionrulecolour]%
  }{%
    #8 %
  }%
}{\typeout{successful patching}}{\typeout{Nope}}
\makeatother

\begin{document}
\tableofcontents
\section{First}
\subsection{Some Title}
\subsection{Some other title}
\subsubsection{No line}

\end{document}

enter image description here