2

There are already many questions here about the space after a number in a table of contents. This one already displays the problem I am facing, but I don't like the solution provided.

What I'd like is all TOC texts after numbers to have the same distance to the numbers, instead of setting one static value for one level, which results in different distances, when the numbers begin to take more space, because of more digits. In other words, I would like the space after the TOC numbers to be always equal.

How can I achieve that?

Here is a tiny example of the wanted result:

...

9. [space equal] TEXT
10. [space equal] TEXT

...

100. [space equal] TEXT

...

100000. [space equal] TEXT

Instead of the space varying the text moves further to the right, to allow the same space everywhere.

Edits

  • I am using the book class.
  • My document does not have thousands of chapters, it is only an example to make the meaning even more obvious : ) A general solution to such a problem independent of the range of chapter /section / subsection / ... numbers would be great though, as I imagine there might be others who could want this in the future.
  • 1
    Could you post a fully compilable code? – Bernard Feb 11 '17 at 20:35
  • Does your document really have 100000 sections? Seriously, does it have more than 99 sections? – Mico Feb 11 '17 at 20:47
  • @Mico No, it's just an example to make it even more clear, but the effect already appears at number 10, when we are in a system with base 10. – Zelphir Kaltstahl Feb 11 '17 at 20:48
  • So, realistically speaking, the only spacing transition that might arise is from 9. to 10.? – Mico Feb 11 '17 at 20:50
  • @Mico Yes, most likely. A general solution to any number range might be nicer though. I could live with a solution that somehow triggers at number 10 though, although that might feel more like a "hack". – Zelphir Kaltstahl Feb 11 '17 at 20:51
  • 2
    This shifted indentation of the entries does not look nice, to start with! –  Feb 11 '17 at 20:53

1 Answers1

6

You can use the rightlabels option of titletoc:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[showframe]{geometry} %
\usepackage{fourier, erewhon}
\usepackage{lipsum}

\usepackage[rightlabels, dotinlabels]{titletoc}

    \titlecontents{chapter}[1.7em]{\medskip\bfseries}%
    {\contentslabel{1.7em} }
    {}%numberless%
    {\enspace\hfill\contentspage}[\smallskip]%

    \dottedcontents{section}[4.38em]{\smallskip}{3em}{0.6pc}

\begin{document}

    \tableofcontents
\setcounter{chapter}{8}
    \chapter{Test chapter 9}
        \section{Test section}
    \lipsum[1]
    \chapter{Test chapter 10}
        \lipsum[1]
        \section{Test section 1}
        \lipsum[1]

\end{document} 

enter image description here

Bernard
  • 271,350