# What creates the white space between the top margin and TOC heading?

I am trying to take control over the white spacing around chapter headings, more specifically between TOC heading and the top margin. However, I seem to have some spacing I can't control, would anyone be able to point me to which nob I should turn?

With the following code I thought I removed all white space around chapter headings (ie. TOC, Bibliography headings and whatnot):

\documentclass{report}
\usepackage{biblatex}
\usepackage{titlesec}
\usepackage{etoolbox}
\usepackage{showframe}

\usepackage{filecontents}

\begin{filecontents}{refs.bib}
@misc{ref,
title = {A title},
author = {Doe, J.},
year = {2000},
}
\end{filecontents}
\nocite{*}

\titleformat{\chapter}{
\sffamily\fontsize{18pt}{18pt}
\bfseries
}{\thechapter}{0pt}{}
\titlespacing{\chapter}{0pt}{0pt}{0pt}
\titlespacing{name=\chapter,numberless}{0pt}{-15pt}{0pt}
\setlength{\parskip}{0pt}
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}

\begin{document}
\tableofcontents
\listoffigures
\clearpage
\section{first}
\begin{figure}
Text in figure
\caption{First figure}
\label{fig:Fig1}
\end{figure}
\begin{figure}
Text in figure
\caption{Second figure}
\label{fig:Fig2}
\end{figure}
\section{second}
\section{third}
\clearpage
\end{document}

But this is the result I get:

The sections don't seem to have this problem:

For many reasons, titlesec continues to use the default \@makechapterhead macro for typesetting the chapter title when the chapter style is display. ... \@makechapterhead adds a 50pt space above the title and 40pt after it.

But adding the proposed -50pt to \titlespacing doesn't seem to do the trick. Adding -15pt seems to work though, does this mean something has changed in titlesec or is this another case where some other solution would be preferable?

EDIT: However I just noticed a problem with the solution above, when using printing additional "List of ..."s such as figures on the same page (see updated code above), the title of the next list will clip into the TOC as such:

How can I prevent this while still placing the TOCs chapter at the very top of the page?

• Have you considered inserting the instruction \vspace*{25pt} immediately before \listoffigures? – Mico Jan 9 '18 at 2:25
• No I haven't but that would of course work, I was hoping I could tackle it by formatting through \titlesec or something similar. But if there is no such solution, adding vspace will probably be the solution. – Christian Eriksson Jan 9 '18 at 2:29
• Incidentally, the third argument of \titleformat shouldn't be {\thechapter}; instead, it should probably be either {\thechapter\space} or {\thechapter\quad}. – Mico Jan 9 '18 at 2:31
• The instructions \patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{} suppress the automatic switching to a new page at the start of each chapter. You therefore need to provide manual controls for those cases where a chapter-level header, in fact, does not occur at the start of a page. – Mico Jan 9 '18 at 2:38
• Incidentally, the directive \fontsize{18pt}{18pt} is asking for trouble if a chapter-level header ever takes up more than 1 line. Something like \fontsize{18pt}{21pt} is probably more appropriate. If you make this adjustment, you should probably also change \titlespacing{name=\chapter,numberless}{0pt}{-15pt}{0pt} to \titlespacing{name=\chapter,numberless}{0pt}{-18pt}{0pt}. Plus, for the sake of consistency, you should probably change \titlespacing{\chapter}{0pt}{0pt}{0pt} to \titlespacing{\chapter}{0pt}{-18pt}{0pt}. – Mico Jan 9 '18 at 2:50

Ok so here is a solution to the question I presented. I'm not sure I'll actually use it because, as cfr pointed out in the comments, I might be better of just changing document class. I need to check if/what else breaks if I do, this solution seems to work though.

What I did to remove X extra space from chapter headings at the top of the page and keep other chapter headings as is headings was:

1. redefine the \chapter macro to add X vertical space to those chapters that do not sit at the top of the page.
2. remove X vertical space from all chapter headings.

this way X extra space was removed from chapter headings at the top of the page and the other chapter headings did not move. I could then also use

\titlespacing*{\chapter}{0pt}{0pt}{0pt}
\titlespacing*{name=\chapter,numberless}{0pt}{0pt}{0pt}

to get visually 0pt spacing around the chapter heading, rather than using -15pt as before. Here is how I redefined it:

\makeatletter
\let\oldchapter\chapter
\renewcommand*\chapter{%
\@ifstar{\starchapter}{\@dblarg\nostarchapter}
}
\makeatother
\newcommand*\starchapter[1]{\vspace{15pt}\vspace*{-15pt}\oldchapter*{#1}}
\def\nostarchapter[#1]#2{\vspace{15pt}\vspace*{-15pt}\oldchapter[{#1}]{#2}}

Note that I'm not sure that 15pt is the "correct" ammount, rather it's what looked best. And here is the full example:

\documentclass{report}
\usepackage{biblatex}
\usepackage{titlesec}
\usepackage{etoolbox}
\usepackage{showframe}

\usepackage{filecontents}

\begin{filecontents}{refs.bib}
@misc{ref,
title = {A title},
author = {Doe, J.},
year = {2000},
}
\end{filecontents}
\nocite{*}

\def\chpfontsize{18pt}
\def\extrachpspc{15pt}

\titleformat{\chapter}{
\sffamily\fontsize{\chpfontsize}{\chpbaselineskip}
\bfseries
\titlespacing*{\chapter}{0pt}{0pt}{0pt}
\titlespacing*{name=\chapter,numberless}{0pt}{0pt}{0pt}
\setlength{\parskip}{0pt}
\patchcmd{\chapter}{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}

\makeatletter
\let\oldchapter\chapter
\renewcommand*\chapter{%
\@ifstar{\starchapter}{\@dblarg\nostarchapter}
}
\makeatother
\newcommand*\starchapter[1]{\vspace{\extrachpspc}\vspace*{-\extrachpspc}\oldchapter*{#1}}
\def\nostarchapter[#1]#2{\vspace{\extrachpspc}\vspace*{-\extrachpspc}\oldchapter[{#1}]{#2}}

\begin{document}
\tableofcontents
\listoffigures
\clearpage
\chapter{My Chapter}
\section{first}
\begin{figure}
Text in figure
\caption{First figure}
\label{fig:Fig1}
\end{figure}
\begin{figure}
Text in figure
\caption{Second figure}
\label{fig:Fig2}
\end{figure}
\section{second}
\section{third}
\clearpage