[Tex/LaTex] How to fit the table of contents into a single page

page-breakingspacingtable of contents

When I use \tableofcontents I get all my contents in a single page except for a line that goes on the other page, how can I make all in the same page?

Best Answer

Add the following code line in the main text immediately before the chapter/section entry that starts a new ToC page:

\addtocontents{toc}{\protect\enlargethispage{\baselineskip}}

This will enlarge the first ToC page by the value of \baselineskip (i.e. one line), which should make the last ToC entry fit on this page.

EDIT: For top-level-entries (e.g. chapters in books) that add some vertical space before their respective ToC entry, a larger value (say, 2\baselineskip) may be needed.

EDIT 2: I have no satisfying answer why the page number is still positioned the way it is, but a workaround. Ignore my first answer and instead add the following to your preamble:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@chapter}{1.0em}{0.8em}{}{}
\makeatother

This will reduce the vertical space between chapter ToC entries from 1.0em to 0.8em, which hopefully is enough to make your ToC fit on one page.

EDIT 3: And here's a "satisfying" answer for the observed behaviour of my first solution -- quoting from source2e:

\enlargethispage{<dim>} [a]dds <dim> to the height of the current column only. On the printed page the bottom of this column is extended downwards by exactly <dim> without having any effect on the placement of the footer; this may result in an overprinting.