My Table of Contents does not fit on one page, two chapters go to a new page and the rest of the page is empty, is it somehow possible to fix this?
3 Answers
You can reduce the space set before each chapter title in the ToC. The default is 1em. Either use tocloft
\usepackage{tocloft}
\setlength{\cftbeforechapskip}{0.8em}
or via an etoolbox patch
\usepackage{etoolbox}
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@chapter}{1.0em}{0.8em}{}{}
\makeatother
Here's a minimal example:
\documentclass{report}
\usepackage[a5paper]{geometry}
\usepackage{tocloft}
\setlength{\cftbeforechapskip}{0.8em}
\begin{document}
\tableofcontents
\chapter{First chapter}
\chapter{Second chapter}
\chapter{Third chapter}
\chapter{Fourth chapter}
\chapter{Fifth chapter}
\chapter{Sixth chapter}
\chapter{Seventh chapter}
\chapter{Eighth chapter}
\chapter{Ninth chapter}
\chapter{Tenth chapter}
\chapter{Eleventh chapter}
\chapter{Twelfth chapter}
\chapter{Thirteenth chapter}
\chapter{Fourteenth chapter}
\end{document}
Before the update:
After the update:
You can tweak the adjusted spacing to make things fit your setup. For example, if you have sections in the ToC as well, you may not want to adjust the value of \cftbeforechapskip quite as much, and perhaps also adjust \cftbeforesecskip.
The above should work for both book and report document classes. If you're using memoir, you can do something similar to what tocloft provides. In the preamble, adjust \cftbeforechapterskip:
\documentclass[...]{memoir}
\setlength{\cftbeforechapterskip}{0.8em}% Change to suit your needs...
...
- 603,163
Using this old answer of mine (which defines the \fitbox macro -- its name should be self-explanatory) you could do:
\makeatletter
\let\oldtableofcontents\tableofcontents
\renewcommand\tableofcontents{%
\begingroup
\@fileswfalse
\fitbox\textheight{\oldtableofcontents}
\endgroup
\if@filesw
\expandafter\newwrite\csname tf@toc\endcsname
\immediate\openout \csname tf@toc\endcsname \jobname.toc\relax
\fi
}
\makeatother
Complete example
\documentclass{article}
\usepackage{lipsum}
\renewcommand{\rmdefault}{ppl}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{fp,graphicx}
\setlength\unitlength{1cm}
\makeatletter
\def\accur@cy{0.999}
\newcommand{\fitbox}[3][\textwidth]{%
\@tempdima#2
\edef\@wd{\strip@pt\dimexpr#1\relax}
\def\r@tio{1}
\@temptokena={\scalebox{\r@tio}{\parbox{\@wd pt}{{#3}}}}
\setbox0=\vbox{\the\@temptokena}
\@tempdimb=\dimexpr\ht0+\dp0\relax
\FPdiv\r@tio{\strip@pt\@tempdima}{\strip@pt\@tempdimb}
\FProot\r@tio{\r@tio}{2}
\FPdiv\@wd{\@wd}{\r@tio}
\fitbox@adjust
\setbox0=\vbox{\the\@temptokena}
\box0
}
\newcommand{\fitbox@adjust}{%
\@tempcnta\z@
\def\rel@rror@rec{0}
\fitbox@adjust@
}
\newcommand{\fitbox@adjust@}{%
\advance\@tempcnta by 1
\ifnum\@tempcnta<10
\FPiflt\rel@rror@rec\accur@cy
\setbox0=\vbox{\the\@temptokena}
\@tempdimb=\dimexpr\ht0+\dp0\relax
\FPdiv\rel@rror@rec{\strip@pt\@tempdimb}{\strip@pt\@tempdima}
\FPdiv\r@tio{\r@tio}{\rel@rror@rec}
\FPmul\@wd{\@wd}{\rel@rror@rec}
\fitbox@adjust@
\fi
\fi
}
\let\oldtableofcontents\tableofcontents
\renewcommand\tableofcontents{%
\begingroup
\@fileswfalse
\fitbox\textheight{\oldtableofcontents}
\endgroup
\if@filesw
\expandafter\newwrite\csname tf@toc\endcsname
\immediate\openout \csname tf@toc\endcsname \jobname.toc\relax
\fi
}
\makeatother
\begin{document}
\tableofcontents
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\end{document}
Output
Before
After
Consider this MWE reproducing the problem:
\documentclass[oneside]{book}
\usepackage{tikz,lipsum} % for dummy text loop
\begin{document}
\tableofcontents
\foreach \x in {1,2,...,21} {\chapter{blabla\x} \lipsum[\x]}
\end{document}
For consistency with the rest of the book, I would avoid changes in the layout (margins and/or space around title, \enlargethispage{}, etc.) or resizing a box containing the ToC, as this might produce a non standard font size (that will be not used in the rest of the book).
My suggestion is simpler: use a smaller standard font (e.g., \footnotesize), reduce a little the interline spacing (e.g., \linespread{.85}) or mix both approaches for a more subtle style change:
\documentclass[oneside]{book}
\usepackage{tikz,lipsum} % for dummy text loop
\begin{document}
{\linespread{.95}\small\tableofcontents}
\foreach \x in {1,2,...,21} {\chapter{blabla\x} \lipsum[\x]}
\end{document}
- 80,769






titletocortocloftto play with the vertical spacings and/or font size. – Bernard Jan 18 '17 at 19:01\documentclassare you using? – Werner Jan 18 '17 at 19:36