# Fixing overfull hbox in table of contents removes too many dots

This question on the memoir table of contents has an answer that works well, however, the dots end too soon (in my opinion).

Is there a way to make the dots more like the default without triggering the overfull hboxes? (The WME is take directly from the above question):

\documentclass[oneside, draft]{memoir}

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

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

\makeatletter
\renewcommand{\@pnumwidth}{3em} %even adjusting this down doesn't really help
\renewcommand{\@tocrmarg}{4em}
\makeatother

\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}


Here's some example images (first has the dots I like, but an overfull hbox, second removes the hbox but doesn't have enough dots):

I found this in texdoc memman

\newcommand*{\l@section}{\@dottedtocline{1}{1.5em}{2.3em}}


Perhaps those sizes are involved in the spacing.

-
BTW, I found a command \setpnumwidth{} so that you don't need to use \makeatletter. –  John Kormylo Mar 15 '14 at 17:05
Also, the easiest way to create a thousand page document is to \addtocounter{page}{1000} –  John Kormylo Mar 16 '14 at 14:47

The memoir documentation mentions (section 9.1 General ToC methods, p 142):

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.

The default for \@pnumwidth is set to 1.55em, which can be adjusted using \setpnumwidth{<len>}.

Here is another approach: Set the page number in a box with a white background fill:

\documentclass[oneside, draft]{memoir}

\usepackage{geometry}
\usepackage{lipsum,xcolor}

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

\makeatletter

\newcommand{\pnumformat}[1]{{\setlength{\fboxsep}{0pt}\llap{\colorbox{white}{#1}}}}
\setpnumwidth{.5em}% Just a small enough length
\renewcommand{\cftchapterformatpnum}[1]{%
\cftchapterformatpnumhook{#1}%
\hb@xt@\@pnumwidth{\hfil\pnumformat{\cftchapterpagefont #1}}}
\renewcommand{\cftsectionformatpnum}[1]{%
\cftsectionformatpnumhook{#1}%
\hb@xt@\@pnumwidth{\hfil\pnumformat{\cftsectionpagefont #1}}}

\renewcommand{\@tocrmarg}{4em}
\makeatother

\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}

-
This works great! How do I link to a particular answer? –  bombcar Mar 17 '14 at 15:17
@bombcar: Click on the "share" button at the bottom of the answer to receive a personalized link to this answer. –  Werner Mar 17 '14 at 16:11
Now I notice that there is a very small part of the overlapped period showing - is there a way to make \colorbox slightly larger? –  bombcar Mar 19 '14 at 1:24

3em is too much for pnumwidth. It is enough to keep it at 2.5em

\makeatletter
\renewcommand{\@pnumwidth}{2.5em} %even adjusting this down doesn't really help
\renewcommand{\@tocrmarg}{4em}
\makeatother


If you have page numbers exceeding 1000, you have to live with that. If you want to have more fots, you can adjust the separation between the dots by

\renewcommand*{\cftdotsep}{2}


For memoir, you can change the pnumwidth and tocmarg by the commands

\setpnumwidth{2.5em}
\setrmarg{4em}

-
Actually, as far as I can tell, memoir doesn't use \@dotsep for anything. –  John Kormylo Mar 15 '14 at 17:00
So there's no way to make that first line go closer to the 3 even though it wouldn't on the last one? I only have 300 pages but it does lookt a bit weird. –  bombcar Mar 15 '14 at 19:14
It looks like \newcommand*{\l@section}{\@dottedtocline{1}{1.5em}{2.3em}} may be able to do something, investigating. –  bombcar Mar 15 '14 at 19:19