0

I'm trying to remove some extraneous extra space that appears before chapter headings in the book class. I've used titlesec to set the space-above to 0pt, but there is still about one line's worth of space (that doesn't appear, e.g., if I use \section instead of \chapter).

This MWE shows the problem, with geometry frames drawn to indicate the positioning of the headers:

\documentclass{book}
\usepackage{geometry}
\usepackage{titlesec}

\geometry{showframe}

\titleformat{\chapter}[hang]%
  {\sffamily\Huge}% format applied to label+text
  {\thechapter}%% label
  {0.5em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\titleformat{\section}[hang]%
  {\sffamily\Huge}% format applied to label+text
  {\thesection}%% label
  {0.5em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\titlespacing*{\chapter}{0pt}{0pt}{0pt}
\titlespacing*{\section}{0pt}{0pt}{0pt}

\begin{document}

\chapter{A Chapter}

Notice the white space above the heading.

\newpage

\section{A Section}

But no white space in this case.

\end{document}

2 Answers 2

1

To have a code that doesn't depend on the fontsize, you may use a unit that depends on the font. It happens titlesec defines a shortcut for such a unit, to be used in \titlespacing: *n means n ex, with a minute stretchability and shrinkability if required to ensure the bottoms of all pages for testing). This being said, I wouldn't recommend no vertical spacing below titles, for æsthetic reasons

\documentclass{book}
\usepackage[showframe]{geometry}
\usepackage{titlesec}

\geometry{showframe}

\titleformat{\chapter}[hang]%
  {\sffamily\Huge}% format applied to label+text
  {\thechapter}%% label
  {0.5em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\titleformat{\section}[hang]%
  {\sffamily\Huge}% format applied to label+text
  {\thesection}%% label
  {0.5em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\titlespacing*{\chapter}{0pt}{*-3.5}{*0}
\titlespacing*{\section}{0pt}{0pt}{0pt}

\begin{document}

\chapter{Ä \v Chapter}

Notice no white space above the heading.

\newpage

\section{A Section}

But no white space in this case.

\section{A First Section}

\end{document} 

enter image description here

1
0

In your code just reduce further the "before chapter title spacing" to -ve value (e.g. -20pt):

\titlespacing*{\chapter}{0pt}{-20pt}{0pt}

enter image description here

2
  • Thanks for the suggestion -- this is certainly a workaround, but I wonder whether there is a more robust way of doing it? The amount of negative space required depends on the font size of the chapter heading. I'd also like to understand what's causing the space in the first place. Aug 15, 2020 at 17:55
  • I think may be the 0 value in titlespacing restores the before chpater title spacing to the default of the class (book class in your case), thats why there's still some spacing appears while 0 is used. This means to absolutely cancel out the before spacing we have to insert a negative of that default (around -20pt here). To know the exact default of before spacing value for book class you may have to check its documentation.
    – hesham
    Aug 15, 2020 at 19:03

You must log in to answer this question.

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