0

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:

enter image description here

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:

enter image description here

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:

enter image description here

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}
1

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}

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

\chapter{Syntax}
...

Note, the image below was run with the default fonts, because I don't have your font installed:

enter image description here

  • Nice approach! +1 It's a bit hacky, I'll definitely have to be careful when moving chapters around, and the width left for the numbers is still chosen by eye, but it's definitely a great solution to the immediate problem and if there's no better way then it definitely does the job – Au101 Aug 18 '18 at 18:31
  • 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
  • Indeed yes, what might be nice is if a package let you have a ToC where there was a fixed space between the number and the heading, so the headings wouldn't all be aligned with each other, but would be a fixed distance from the number. Or, if that does turn out to be less pretty, if there were at least a way to make sure that the distance between 11 and Heading was the same as the distance between 1 and Heading and so on for 12 and 2 and so on, without me picking a number that looks about right :P – Au101 Aug 18 '18 at 18:39
  • \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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.