If the length of a contents line is a bit too much, but not much too much, LaTeX squeezes it in before the page number. This looks pretty awful to me.
How can I persuade it to break the line in this case, as it would if the line were just a bit longer and couldn't be squeezed in?
Please note that my real document uses etoc and I need a solution which is consistent with that usage. (I'm using it both to generate multiple tables of contents and to flexibly fade parts of them.)
MWE:
\documentclass[a4paper]{book}
\usepackage{geometry}
\begin{document}
\tableofcontents
\chapter{In the beginning}
\section{The emptiness of nothingness and the blue ovoidness of avoiding voiding kangaroos}
\section{The emptiness of nothingness and the blue ovoidness of avoiding voiding kangaroos and jumping counts}
\section{Counting kangaroos and jumping counts}
\chapter{In the middle}
\setcounter{page}{50}
\section{The emptiness of nothingness and the blue ovoidness of avoiding voiding kangaroos}
\section{The emptiness of nothingness and the blue ovoidness of avoiding voiding kangaroos and jumping counts}
\section{Counting kangaroos and jumping counts}
\chapter{In the end}
\setcounter{page}{100}
\section{The emptiness of nothingness and the blue ovoidness of avoiding voiding kangaroos}
\section{The emptiness of nothingness and the blue ovoidness of avoiding voiding kangaroos and jumping counts}
\section{Counting kangaroos and jumping counts}
\end{document}
I can't imagine this hasn't been asked before, but I'm not finding a good solution. How can I force long chapter names (including page numbers) to stay in the margins on the table of contents? concerns the same problem, but I'm already loading hyphenation patterns for UK English and Welsh, I'm using pdfLaTeX, but I'm not using hyperref. So that leaves the manual solution of adding in hyphenation points, which would be very far from an optimal solution. The other suggestion in the comments there is to shorten titles, but that's not an option here: I didn't name the thing I'm including and I can't re-title it.
Is there a better solution? 'Better' means the solution is automatic (does not require inserting hyphenation points in words LaTeX knows how to hyphenate elsewhere) and does not require rewriting things to be shorter (or longer).





etocpackage but have you tried thetocloftpackage? However the 3 answers below are all good, especially by @Kuttens. – Peter Wilson Jan 28 '18 at 18:55