Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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):

Image of overfull hbox Image of not 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.

share|improve this question
    
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

2 Answers 2

up vote 3 down vote accepted

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:

enter image description here

\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}
share|improve this answer
    
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

enter image description here

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}

enter image description here

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

\setpnumwidth{2.5em}
\setrmarg{4em}
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
http://tex.stackexchange.com/questions/165726/fixing-overfull-hbox-in-table-of-contents-removes-too-many-dots/165825
tex.stackexchange.com
crawl=CC-MAIN-2015-27
83761
application/http; msgtype=response
sha1:7JDJ3CU7JCUGFA4P55T4IDO5AJA3WVE4
<urn:uuid:498ff956-a640-4355-ac9d-0d83fe0eefaf>
2015-07-04T20:45:23Z
104.16.12.13
sha1:ES6MKJ3D4ZLTUNTT5Y2DLJLS7QCQODFI
<urn:uuid:2a64f2c9-b0ec-4e5b-a930-955b2a310ec2>
http://tex.stackexchange.com/questions/165726/fixing-overfull-hbox-in-table-of-contents-removes-too-many-dots/165825
length
response
<urn:uuid:1781494c-18e6-4826-b8e7-79020fd0b938>
robots: classic
hostname: ip-10-179-60-89.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2015-27
operator: CommonCrawl Admin
description: Wide crawl of the web for June 2015
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf