0

I am using titlesec to format the titles in my document. I have spent about one hour trying to draw a line below the title that spans the entire width of the text block on the page. So far I have managed to get this far:

\titleformat*{\subsection}
{\large\bfseries
\titlerule[0.8pt]%
\bfseries}
\let\stdsubsection\subsection
\renewcommand\subsection{\newpage\stdsubsection}

Using this cdoe, the line is drawn above the title. I have tried many many different ways to fix this, but had no success. All of the examples I can find don't use the redefine subsection command that I am using out of necessity, to get a new page for each subsection.

Here is how it looks:

enter image description here

  • Your query is not quite clear: do you want subsections to start a newpage? Also, please post a full compilable code. – Bernard Jan 3 '18 at 9:55
  • Got it. Next time I will post a full compilable code. – Kit Johnson Jan 4 '18 at 2:18
1

You have to use the extended syntax of titlesec, and if you want subsections to start a new page, change the class of subsections (normally straight) to top, like chapters. The horizontal rule is obtained with the last (optional) argument of \titleformat:

\documentclass[a4paper, 11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{titlesec}

\titleformat{\subsection}{\large\bfseries}{\arabic{subsection}.}{0.5em}{}[\titlerule]
\titlespacing{\subsection}{0pt}{-3ex}{4ex}
\titleclass{\subsection}{top}

\usepackage{lipsum}

\begin{document}

\lipsum[1-4]

\subsection{Consider the consequences}

\lipsum[5]

\end{document} 

enter image description here

| improve this answer | |
  • Thank you so much for solving this for me. I searched through the titlesec documentation for \arabic but couldn't find anything. What is this used for? – Kit Johnson Jan 4 '18 at 2:20
  • Changing the class of subsection to 'top' (\titleclass{\subsection}{top}) means that subsection headers no-longer appear on even pages. A blank page is now inserted so that it comes at the next odd page. I can't find a way to undo this, despite searching the manual. (I would like subsection headers to appear at the start of a new page regardless of whether it is even or odd.) – Kit Johnson Jan 4 '18 at 2:30
  • @KitJohnson: My example code shows this is not necessarily the case. You have something in your preamble which induces this behaviour. That's why it's so important to post full minimal examples when one asks questions – Bernard Jan 4 '18 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.