Page Layout ⇒ Problem with page number spacing in table of contents
Problem with page number spacing in table of contents
I'm using 12pt, twoside, a4paper book class and I'm *not* using any ToC customization package (such as tocloft or similar). Strange enough, I have this problem only with the ToC. List of figures and list of tables both have correct spacing between the text and the page number.
I have googled a bit, and found topics dealing with spacing between text and section number, but none dealing with text and page number. How can I fix this? Is it possible to add additional spacing between section text and page number? Or if not possible (or troublesome) is it possible to manually force line breaks in conflicting entries?
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Problem with page number spacing in table of contents
Might take a while, but sooner or later your document will have about ten lines and the cause will be obvious. This method is called preparing a minimal working example.
Re: Problem with page number spacing in table of contents
EDIT: Preparing a MWE for this problem is tricky, because it must have at least 100 pages for page numbers to start almost overlapping text...
Any suggestions?
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Problem with page number spacing in table of contents
But, fortunately, there is a package that allows you to style your toc. The documentation lists different styles and their visual appearance, please have a look and pick the one that you like best.
Please be aware, that you need to run latex multiple times (3 in my case) so that the spaces can be calculated correctly. Hint, you can click on »Open in WriteLaTeX« directly above the code to see the compiled output.
Code: Select all
\documentclass{book}
\usepackage{blindtext}
\usepackage{pgffor}
\usepackage{tocstyle}
\begin{document}
\tableofcontents
\foreach \n in {1,...,37}{\chapter{chapter numero \n}
\blindtext[10]
}
\chapter{a chapter with a very very long and exhausting title,
do people want to read this far?}
\blindtext[2]
\end{document}
Problem with page number spacing in table of contents
BTW I already got a MWE and was going to post it. Just because I took the trouble of writing it, I'll post it

Code: Select all
\documentclass[12pt, twoside, a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[spanish,english]{babel}
\usepackage{blindtext}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\Blinddocument
\selectlanguage{spanish}
\chapter{Implementación práctica del detector de asfalto seco/mojado}
\section{Máquina de Vectores Soporte}
\subsection{Construcción de los conjuntos de entrenamiento y prueba}
\end{document}
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Re: Problem with page number spacing in table of contents
Re: Problem with page number spacing in table of contents
Anyway, changing the style to KOMAlike luckily fixes the problem. I'll maybe just set that style and do not look back...