2

I'm using titlesec to change the style of my section titles. Sometimes, when the title is long, but just short enough to fit on one line, some extra vertical spaces is add. The following MWE illustrates the problem:

\documentclass{book}
\usepackage[a4paper]{geometry}
\usepackage[explicit]{titlesec}

\titleformat{\section}[block]{\Large\normalfont\bfseries}{#1}{.5em}{}

\begin{document}
  \section{This is a short title}
  This is a paragraph.

  \section{This is a purposely long title that shows some odd behavior}
  This is a paragraph.
\end{document}

This is rendered as follows:

enter image description here

Clearly, there is too much space below the second section title. I've played around with \ignorespaces and \ignorespacesafterend, but can't seem to get rid of the extra space. What to do?

  • This is because the book class use '\flushbottom'. Put in the command '\raggedbottom' after \begin{document}. – Sveinung Jul 30 '14 at 9:13
  • @Sveinung: I don't think that is the issue. To be sure, I tried adding \raggedbottom after \begin{document}, but this does not resolve anything. Also, I tried what happens when I duplicate the sections, and the problem remains: there is more vertical space under sections with long titles than under the other sections. – yyzz Jul 30 '14 at 9:38
  • I should have written: "It might be because you are using ..." =:-). But Bernhard had a solution! – Sveinung Jul 30 '14 at 21:08
3

This is above all due to the bad syntax in:

\titleformat{\section}[block]{\Large\normalfont\bfseries}{#1}{.5em}{}

You've put #1 at the place reserved for formatting the label. A correct syntax would be, e.g.:

\titleformat{\section}[block]{\Large\normalfont\bfseries}{\arabic{section}.}{.5em}{#1}

enter image description here

  • Aaaahhhhh how stupid of me. Thanks so much for pointing that out! I've spent so much time on this :) – yyzz Jul 30 '14 at 9:45
  • It's not easy to remember all those parameters. And your code couldn't produce any error message on compiling… The label being actually the title, it added a (invisible, of course) space of 0.5 em on next line. – Bernard Jul 30 '14 at 9:53
  • Yes, I now realize that replacing .5em by 0pt will do the trick too. Thanks! – yyzz Jul 30 '14 at 16:41

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.