2

It seems like the table of contents of standard classes (nor with titlesec loaded) do not adjust the spacing reserved for page numbers depending on the font used.

The example is the following:

\documentclass[draft]{book}

\usepackage{kpfonts}

\begin{document}

\tableofcontents

\setcounter{page}{100}

\chapter{LoL}
\section{whatever}
\subsection{dunno lol}

\end{document}

Which results in:

example

The same does not happen with the default Computer Modern font. So the question is how do I adjust the width of the page numbers boxes to fit a three digits number, possibly in a way that works across different fonts?

I'm using titlesec to style everything in the real document so a titlesec/titletoc answer would be preferred. Never used titletoc specifically, though, so I do not know where to start from apart the docs which are quite terse.

Note this is not a duplicate of this question since the overfull \hbox is in the page numbers, not the titles.

3
  • 5
    If you're using titletoc in your real document, it might be a good idea to also use it in your MWE here. Without titletoc you can change \@pnumwidth to something bigger than 1.55em (the default), to not get overfull boxes. So your MWE is solved by using \makeatletter\renewcommand\@pnumwidth{2em}\makeatother in your preamble.
    – Skillmon
    Commented Oct 20, 2018 at 8:01
  • A perhaps better solution without titletoc could be \usepackage{etoolbox}\makeatletter\patchcmd\@dottedtocline{\hfil}{\hss}{}{}\makeatother.
    – Skillmon
    Commented Oct 20, 2018 at 8:45
  • I mentioned titletoc because I use titlesec to style section titles, but I don't use specifically titletoc because I didn't style the table of contents, yet. However, in the future I'll use it to customize the ToC as well, hence a titletoc solution will save me time later. Commented Oct 20, 2018 at 8:47

1 Answer 1

2
\documentclass{book}

\usepackage{kpfonts}

\usepackage[titles]{tocloft}
\cftsetpnumwidth{2em}

\begin{document}

\tableofcontents

\setcounter{page}{100}

\chapter{LoL}
\section{whatever}
\subsection{dunno lol}

\end{document}

enter image description here

1
  • titles option (somewhat counterintuitively) instructs tocloft not to fiddle with the typesetting of the TOC title (i.e. "Contents") (same for list of figures and list of tables).
    – user4686
    Commented Oct 20, 2018 at 9:25

You must log in to answer this question.

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