17

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:

enter image description here

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

4 Answers 4

5

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:

enter image description here

6

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}
5
  • 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). Commented Mar 17, 2011 at 0:27
  • @Dave: Yes, it matters. My suggestion boils down to use tocstyle instead of tocloft.
    – lockstep
    Commented Mar 17, 2011 at 0:33
  • @Dave: One of the features of tocstyle is automatic calculation of ToC spacing instead of using fixed pre-set values.
    – lockstep
    Commented Mar 17, 2011 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! Commented Mar 17, 2011 at 0:45
  • tocstyle is deprecated and not longer provides by the TeX distriutions.
    – cabohah
    Commented Jun 6, 2023 at 9:03
1

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.

1
  • 1
    Is this compatible with KOMA-script classes as requested in the question?
    – Werner
    Commented Feb 23, 2018 at 0:49
0

Add the following to the preamble:

\usepackage[tocindentauto]{tocstyle}

followed by

\usetocstyle{standard}

or by

\usetocstyle{KOMAlike}
1
  • 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. Commented Jun 7, 2017 at 19:18

You must log in to answer this question.

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