[Tex/LaTex] Overfull \hbox warning for TOC entries when using memoir documentclass

spacingtable of contentswarnings

I get Overfull warning for TOC entries when using memoir documentclass. They seem to occur when the page number for chapter title entries (highlighted in bold text) exceeds 2-digits or section page number exceeds 3-digits.

I do not get the warning for chapter headings if I switch to book documentclass. But it still happens for sections heading.

How can I fix this?

\documentclass[oneside, draft]{memoir}

\usepackage[showframe]{geometry}
\usepackage{lipsum}

\newcommand{\repeattext}[1]{#1 #1 #1 #1 #1 #1}

\begin{document}

\tableofcontents

\chapter{Chapter 1}         \lipsum
    \section{Section 1.1}   \repeattext{\repeattext{\lipsum[1-150]}}

\chapter{Chapter 2}         \lipsum[2]
    \section{Section 2.1}   \repeattext{\repeattext{\lipsum[1-150]}}

\chapter{Chapter 3}         \lipsum[2]
    \section{Section 3.1}   \lipsum[2]

\end{document}

Best Answer

There are three internal LATEX commands that are used in the typesetting the table of contents, lof, lot etc. They are (with their default values):

  • \@pnumwidth = 1.55em
  • \@tocrmarg = 2.55em
  • \@dotsep = 4.5

The page number is typeset flushright in a box of width \@pnumwidth, and the box is at the righthand margin. If the page number is too long to fit into the box it will stick out into the righthand margin. This is what is happening in your case.

The title text is indented from the righthand margin by an amount given by \@tocrmarg.

\@dotsep gives the distance (in math units) between the dots in the leader.

Your problem is due to big numbers which can not be fitted into the box defined by the default value of \@pnumwidth. Hence if we make the box bigger everything will be alright. We add the following in the preamble:

\makeatletter
\renewcommand{\@pnumwidth}{3em} 
\renewcommand{\@tocrmarg}{4em}
\makeatother

Note that \@pnumwidth should be always smaller than \@tocrmarg.

For memoir these can be changed by

\renewcommand*{\cftdotsep}{1}
\setpnumwidth{3em}
\setrmarg{4em}

without any need for \makeatletter construct.

enter image description here