0

I'm trying to control the position and format of the different headings using the awesome package titlesec. However, I am having trouble controlling the vertical space above a \chapter. It always seems to add a small vertical space of approximately 4.8 mm from the top of the body.

Here is my MWE where I have disabled all spacing, with geometry's showframe and a \fbox around the chapter label:

\documentclass[11pt]{book}

\usepackage[showframe]{geometry}

\usepackage{titlesec} \titleformat{\chapter}[display]{}{\fbox{Chapter \thechapter}}{0mm}{\bf} \titlespacing*{\chapter}{0mm}{0mm}{0mm}

\begin{document}

\chapter{Display of Heading Levels}

Some paragraph

\end{document}

Vspace with chapter

For comparison, if I comment out the line \chapter{Display of Heading Levels}, it perfectly aligns with the top of the document.

No vertical space without chapter

What's going on here? I have tried solutions of other question, e.g. this one, but I couldn't get it to work.

André
  • 3

1 Answers1

0

Try this

\documentclass[11pt]{book}

\usepackage{geometry}

\usepackage{showframe} \usepackage{titlesec}

\titleformat{\chapter}[display]{}{Chapter \thechapter}{0mm}{\bf} \titlespacing{\chapter}{0mm}{-3}{0mm}

\begin{document}

\chapter{Display of Heading Levels}

Some paragraph

\end{document}

a

"In the ⟨before-sep⟩ argument this is equivalent to n ex with some stretchability and a minute shrinkability" (pag. 5) so *-3 equal -3ex plus and minus some glue.

Obviously the stretch and shrink parts do not matter for a chapter, that will start a new page. It will make sense although in section or subsection.

When using 3ex instead of an absolute dimension, the spacing will scale with the font size. See the numbers below.

xx

Simon Dispa
  • 39,141
  • Well, yes, this works. But why shouldn't 0mm just result in 0mm? I have exact instructions for the spacings, and therefore it bothers me that titlesec doesn't use this exact height. – André Feb 15 '21 at 08:20
  • Do the instructions include to use titlesec to format the titles? The package has defaults to format a chapter heading . They provided you a template or only specifications? – Simon Dispa Feb 15 '21 at 13:39
  • Only specifications. Would you recommend using something other than titlesec instead? – André Feb 15 '21 at 14:35
  • Each package has its hassles. If you already master titleec, go ahead. I personally use memoir to write books. It emulates many packages, so there are fewer compatibility issues. A comment: usually the chapter headings have some space before and after, plus bigger fonts. Look at different printed books. – Simon Dispa Feb 15 '21 at 15:41
  • Yes, I don't want to eliminate the space altogether, but I'm just trying to get full control of them. It is therefore very annoying that when I enter, say, 50mm as vertical space, it actually will place it at around 54.8mm. I will look at the memoir class though, thanks for the heads up! – André Feb 15 '21 at 18:44
  • You are not alone. See on this subject https://tex.stackexchange.com/a/63393/161015 – Simon Dispa Feb 15 '21 at 19:21