Background

A manual with chapters, sections, subsections, and sub-subsections. Using KOMA Script v2.

Problem

The spacing between the heading title and its number is too close to the number in some cases:

After reading the tocloft package, I do not see how to adjust the spacing between the heading title and the number.

Question

How do you increase the space before the section title a consistent amount?

Ideas

Tried including the following package:

\usepackage[tocindentauto]{tocstyle}


Tried setting linewidth:

\setlength{\linewidth}{15em}


Tried setting the dottedtocline:

\makeatletter
\renewcommand*{\l@section}{\@dottedtocline{1}{4.5em}{5.3em}}
\makeatother


The last attempt looks promising, but it is tricky to adjust the margins correctly.

References

Current KOMA-Script release provides options tocindent and tocnumwidth for \RedeclareSectionCommand that allows to change the indent and the space reserved for the entry number without breaking any feature of the KOMA-Script classes.

\documentclass{scrbook}

\RedeclareSectionCommand[tocnumwidth=2.6em]{section}
\RedeclareSectionCommand[tocindent=4.1em,tocnumwidth=3.5em]{subsection}

\begin{document}
\tableofcontents
% Only some dummy test code:
\clearpage
\setcounter{chapter}{15}
\setcounter{section}{9}
\section{Classes}
\subsection{Abstract}
\subsection{Concrete}
\subsection{Exception}
\section{Automation}
\section{Summary}
\end{document}


e.g., would result in:

For me, tocstyle produces correct horizontal spacing with both standard and KOMA-script classes. Try to compile my example with three or even four LaTeX runs -- maybe the makefile you use doesn't recognize that tocstyle needs yet another LaTeX run to calculate the ToC spacing.

\documentclass{scrreprt}

\usepackage{tocstyle}

\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}

\begin{document}

\tableofcontents

\setcounter{chapter}{100}
\chapter{bla}
\setcounter{section}{200}
\section{blubb}
\setcounter{subsection}{300}
\subsection{foo}
\setcounter{subsubsection}{400}
\subsubsection{bar}

Some text.

\end{document}

• Thanks for this. I'm not sure if this is an exact reproduction of the problem, though. The preamble for this manual is 1000 lines long. Inside I have set different fonts. Also, I'm using tocloft, not tocstyle (if that matters). – Dave Jarvis Mar 17 '11 at 0:27
• @Dave: Yes, it matters. My suggestion boils down to use tocstyle instead of tocloft. – lockstep Mar 17 '11 at 0:33
• @Dave: One of the features of tocstyle is automatic calculation of ToC spacing instead of using fixed pre-set values. – lockstep Mar 17 '11 at 0:37
• Substituting tocstyle for tocloft results in a lot of "Undefined control sequence" errors that I have neither the time nor inclination to resolve. One day, perhaps, latex will generate errors that are a bit more meaningful to the lay person. I do appreciate you taking the time to suggest an alternative, though! – Dave Jarvis Mar 17 '11 at 0:45

When using tocloft is a requirement, the \cftsetindents command solves the given issue, for example:

\cftsetindents{section}{0em}{2.5em}
\cftsetindents{subsection}{1em}{3.5em}


With this solution, different indents and numwidths can be set for each level. This command can also be used for figures; for more see the tocloft package manual.

• Is this compatible with KOMA-script classes as requested in the question? – Werner Feb 23 '18 at 0:49

Add the following to the preamble:

\usepackage[tocindentauto]{tocstyle}


followed by

\usetocstyle{standard}


or by

\usetocstyle{KOMAlike}

• tocstyle is a never supported alpha package. The KOMA-Script author recommends to not longer use it and declared to never release a version 1. You should use package tocbasic (see the accepted answer) instead. – Schweinebacke Jun 7 '17 at 19:18