To customize the appearance of our Table of contents we use the tocloft package.
One point we would like to implement is to underline the chapter entries in the ToC.
However, if we use the \cftchapaftersnum
command to specify a horizontal line we always get a weird overfull hbox warning. (Weird, because if I shorten the line, the overfull hbox is shown in the middle of the page.
Small example compiled with MikTeX and pdfLaTeX:
\documentclass[draft]{book} % use draft to show overfull hboxes
\usepackage{tocloft}
% underline chapter entries:
\renewcommand{\cftchapaftersnum}{\hspace{4mm}\rule[-0.5mm]{0.5\textwidth}{.4pt}}
\begin{document}
\tableofcontents
\chapter{Antelope}
Antelope is a term referring to many even-toed ungulate
species found all over the world.
\rule[-0.5mm]{0.5\textwidth}{.4pt}
This \verb|\rule| does not generate a warning!
\section{Impala}
An impala is a medium-sized African antelope.
\emph{fin \dots}
\end{document}
Note that I've placed 0.5\textwidth
as ruler width in the example above. This way, my draft PDF shows the black rectangle for the overfull box in the middle of the page (just at the end of the \rule
)
What's going on here?
Best Answer
The documentation for
tocloft
makes this clear.What this means is that the box is constructed like
Your box is wider than
\cftchapnumwidth
.If you change
to
then the infinite shrinkability causes the warning to go away.
Edit: You should probably not be using spacing of
4mm
and instead using something proportional to the size of the font. Better still would be to use\cftchapaftersnumb
(note the b at the end):Using
-0.5mm
is also probably a bad idea.