29

I'm using the simple ordinary \tableofcontents command to produce a table of contents, and I find that the resulting spacing between the section number and the section title is too small:

enter image description here

Can someone tell me how to fix this, please. My documentclass is memoir, if that matters.

1

2 Answers 2

25

The width for the section numbers in the ToC is defined by the length called \cftKnumwidth, where K should be replaced by the sectioning level, i.e. chapter, section, etc. You can change it with \setlength, e.g.

\setlength\cftsectionnumwidth{4em}

See section 9.2.2 Typesetting the entries of the memoir manual for more on this.

A complete example:

\documentclass{memoir}
% \setlength\cftsectionnumwidth{4em} % uncomment to see difference
\begin{document}
\tableofcontents
\chapter{A chapter}
\setcounter{section}{999} % just for this example
\section{A section}
\end{document}

Or if you are using the book class, as per https://tex.stackexchange.com/a/336618/50702 and Torbjørn T.'s comment below:

\documentclass{book}
% note you need the subfigure option if you are using the subfigure package
%\usepackage[subfigure]{tocloft}
\usepackage{tocloft}

\setlength\cftsecnumwidth{4em}

\begin{document}
\tableofcontents
\chapter{A chapter}
\setcounter{section}{999} 
\section{A section}
\end{document}
8
  • 2
    Thanks very much. I got the result I wanted after a lot of iterative fiddling with the length parameter. This is one of those occasions where a visual interface would have been very useful. Or, maybe Latex could be smarter about this: the minimum space would be a much easier parameter to work with, rather than thr indent distance. But, anyway, it works, after some fiddling. Thanks again.
    – bubba
    Jul 14, 2013 at 13:21
  • 2
    Could it be that this solution does not work in the book class? I get ! Undefined control sequence. <argument> \cftsectionnumwidth \setlength #1#2->#1 #2\relax l.113 \setlength \cftsectionnumwidth{4em} Feb 11, 2017 at 20:23
  • 1
    @Zelphir Yes, that is correct, the \cft.. macros are not defined in book. The tocloft defines similar commands for customizing the ToC though, so try adding \usepackage{tocloft}. Feb 11, 2017 at 20:38
  • 2
    @rasha I probably misremembered, as stated in the tocloft manual the corresponding length is \cftsecnumwidth, i.e. sec instead of section. Change that, and it works. Aug 31, 2020 at 16:34
  • 1
    @PatrickElPollo Did you read the other comments just above yours? Aug 3, 2021 at 7:40
18

If you have huge numbers in the ToC, you can use the \cftsetindents command (texdoc memoir, page 153) in the preamble, to control the space before and after the numbers, with this syntax:

\cftsetindents{kind}{indent}{numwidth}

Where kind in the sectioning level (e.g., subsection) indent is the length of the indent (space before the numbers) and numwidth is the space for the numbers and the separation of section titles.

For example:

\cftsetindents{section}{1em}{3em}

MWE

2
  • Thanks for your answer. If I had huge numbers in my toc, will the previous answer (using \cftKnumwidth) not work? What are the pros and cons of the two solutions?
    – bubba
    Jul 14, 2013 at 10:25
  • @bubba. Torbjørn T. answer works. I made this answer in parallel and I hesitated to left because this, but I left anyway because for huge numbers and long titles could be interesting a higher numwith but also a lower indent value (even 0em) and I think that this solution is more flexible but not less "user friendly".
    – Fran
    Jul 14, 2013 at 10:48

You must log in to answer this question.

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