0

I would like to fix a little dots glitch in my ToC. Here's a MWE showing the issue:

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot]{geometry}
\usepackage{microtype}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage[nottoc,notlof]{tocbibind}
\usepackage[titles]{tocloft}

\renewcommand{\cftdotsep}{2}
\makeatletter  % To fix a spacing problem with page number.
\renewcommand{\@pnumwidth}{2em} %
\makeatother
\setcounter{tocdepth}{2}

% Chapters spacement :
\renewcommand{\cftchapaftersnumb}{\newline}
\setlength{\cftchapindent}{0em} % Spacement to left of chapter number.
\setlength{\cftchapnumwidth}{0em} %

% Sections spacement :
\renewcommand{\cftsecpresnum}{\hfill} % \quad
\renewcommand{\cftsecaftersnum}{\hspace{0.75em}} % \enskip = 0.5em = demi \quad
\setlength{\cftsecindent}{0em} %
\setlength{\cftsecnumwidth}{4em} %
%\addtolength{\cftsecnumwidth}{0em} %

\begin{document}

\microtypesetup{protrusion=false} % To fix extra dots in ToC
\tableofcontents

\setcounter{chapter}{14}
\setcounter{page}{561}
\chapter{Title}
\section{Section title}
\newpage
\section{A new section title}
\newpage
\section{Another section title}

\end{document}

Preview (the issue is shown in red):

enter image description here

In this case, I get a relatively large space after the section title (as shown in red), and yet there appears to be space for one more dot. This is occuring frequently in my full ToC, and it irritates me a bit. How can I tell LaTeX to use a smaller space after the section title to add an extra dot? Of course, the dots must all stay aligned at right (as currently shown).

2 Answers 2

1

The problem that you're running into is that there's no extra space to put another dot as far as LaTeX can tell. Think of the dots as being in little boxes with equal amounts of space on either side of the . The actual amount is \@dotsep mu (one mu is 1/18 of an em, book sets \@dotsep to 4.5, so you've got effectively half an em of space between dots).

You could redefine \@dottedtocline to make the spacing around the box with the dot asymmetrical.

\def\@dottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{.}\mkern \@dotsep % ⬅︎
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5%
                        \kern-\p@\kern\p@}%
     \par}%
  \fi}

I marked the relevant line in the copied definition with ⬅︎. You could change this to have \@ldotsep and \@rdotsep defined appropriately, (you can't just do a prefix before the \@dotsep since \@dotsep is just a macro holding a number and not a length or glue that could be multiplied). Alternatively, you could add a kern before the \leaders to tighten that space.

An ugly solution would be to do something like

\section[Another section title\kern-.1em]{Another section title}

to tighten the spacing there to get the additional dot, but if it's just a single instance, that might be the quickest solution.

1
  • The problem with the ugly solution is that I'll have to apply it to many section titles. My issue is occurring for several sections in the ToC. So there's no "natural" way of fixing this, in LaTeX?
    – Cham
    Commented Jun 2, 2021 at 17:35
1

The tocloft package lets you change the separation between the dots in the leaders.

\usepackage{tocloft}
\renewcommand{\cftdotsep}{3.5} % normally 4.5

which will make the dots closer together and may cure your problem.

However, if you change the dotted leader to fix one perceived infelicity in the ToC layout it may well lead to different infelicities in other entries.

My suggestion is to live with what you have got but tell nobody about your "glitch".

3
  • Oh, I already tested this solution. It often gives the same issue. So should I understand that there's no "natural" fix for my issue?
    – Cham
    Commented Jun 2, 2021 at 17:32
  • @Cham I can't think of a natural fix. The space between the title and the page number is filled by a sequence of dots with fixed spacing. You could start the dots a little to the left but then they would finish more to the left of the page number. Perhaps the "nautural" fix is to have no dots (cftnodots). Commented Jun 2, 2021 at 17:46
  • Well, I could try a larger spacing on the right (next to the page number), but only if that space is constant. So what do you propose to begin the dots closer to the left? If the spacing is variable next to the page number, then it would be worst!
    – Cham
    Commented Jun 2, 2021 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .