# Is there a way to have a constant space between the (sub)section number and the heading in the ToC

I have a document which unfortunately has a section 10.13 and a subsection 10.13.1 and I'm sure there will be many other such examples.

Unfortunately, this makes for an extremely ugly table of contents, where the section and subsection numbers are too wide and collide with the section and subsection headings:

So, to fix it, I used the tocloft package (I was using it anyway) and went for:

\renewcommand*\cftsecnumwidth{3em}
\renewcommand*\cftsubsecindent{4.5em}
\renewcommand*\cftsubsecnumwidth{3.8em}


This solves the problem with the the numbers that are too wide:

But it creates a problem with numbers that aren't this wide. Look at how silly chapter 2 now looks, the gap between the numbers and the headings is just too big and what's worse is that it's inconsistent with later gaps:

Is there no way to set a nice even space of, say, 0.5em between the number and the heading?

MWE:

\documentclass[12pt,openany]{book}
\usepackage[margin=1.8cm]{geometry}
\geometry{a4paper}
\usepackage[parfill]{parskip}
\usepackage{tocloft}
\usepackage{fontspec,xltxtra,xunicode}

\setmainfont[ItalicFont={CharisSIL-I.ttf}, BoldFont={CharisSIL-B.ttf}, BoldItalicFont={CharisSIL-BI.ttf}]{CharisSIL-R.ttf}

\renewcommand\cftpartpresnum{Part~}
\renewcommand*\cftsecnumwidth{3em}
\renewcommand*\cftsubsecindent{4.5em}
\renewcommand*\cftsubsecnumwidth{3.8em}

\renewcommand\frontmatter{\clearpage\pagenumbering{roman}}
\renewcommand\mainmatter{\clearpage\pagenumbering{arabic}}

\title{Notes on the Hindi Language}
\date{}

\begin{document}

\maketitle

\frontmatter

\tableofcontents

\mainmatter

\part{}

\chapter{Introduction}
\section{Summary}

\chapter{The Sounds of Hindi and the Devanagari Script}
\section{Introduction}
\section{Vowels}
\subsection{Other Character}
\subsection{\textit{Visarga}}

\part{}

\setcounter{chapter}{9}
\chapter{Syntax}
\section{Questions}
\setcounter{section}{9}
\section{Word Order and Possessives}
\section{\textit{Tō}}
\section{Some Constructions with \textit{Kō}}
\section{\textit{Kō} with Oblique Arguments and Direct Objects}
\subsection{\textit{Kō} with Oblique Arguments}
\subsection{\textit{Kō} with Direct Objects}

\end{document}


You can put the commands to change the TOC format into the file that creates the TOC. That way, you can change the format part way through.

Move the \renewcommand*\cft… commands from the top of your file to here:

...
\setcounter{chapter}{9}


• You could parcel up the \addtocontents commands into a macro in your document preamble, if you want to keep your main document "cleaner," of course. The problem with trying to redefine the TOC format on the fly would be that you want to look ahead - for example you don't know how much space section "10.1" needs till you can see whether there is a section "10.10" or not. – alephzero Aug 18 '18 at 18:36
• \show\enspace will show you the width of one digit in your font in your log file. (For the computer modern fonts that was 0.5em, but for other fonts it might be different). When you know that, you can get the numbers "exactly right" rather than "guessing". – alephzero Aug 18 '18 at 18:51
• I tried \show\enspace and it gave me > \enspace=macro: ->\kern .5em . l.72 \show\enspace ? but I'm not precisely sure how to use this to get the numbers exactly right, would it be possible to be more specific? =) – Au101 Aug 18 '18 at 20:02