TransWikia.com

Removing extra vertical space before chapter heading

TeX - LaTeX Asked by Richard Townsend on September 14, 2020

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]%
  {sffamilyHuge}% 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]%
  {sffamilyHuge}% 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

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]%
  {sffamilyHuge}% 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]%
  {sffamilyHuge}% 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

Correct answer by Bernard on September 14, 2020

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

Answered by hesham on September 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP