Menu

HowTo_NoNumberNotHanging

How to print unnumbered entries in the table of contents without hanging indentation

With the KOMA-Script classes, you can either set unnumbered entries in the table of contents with the same indentation as numbered entries, i.e. with an empty number, or you can set them indented to the left to the beginning of the number. In both cases, however, multi-line entries are indented from the second line onwards by the width that would normally be reserved for the number. This is called a hanging indent.

To set unnumbered entries in all lines flush left with the numbers of the numbered entries instead, you can define a new entry type and only use this for the unnumbered entries, i.e. the entries with an empty number:

\documentclass{scrbook}
\DeclareTOCStyleEntry[%
  level=\sectiontocdepth,
  indent:=section,
  numwidth=0pt
]{section}{addsec}
\renewcommand*{\addsectiontocentry}[2]{%
  \IfArgIsEmpty{#1}{%
    \addtocentrydefault{addsec}{}{#2}%
  }{%
    \addtocentrydefault{section}{#1}{#2}%
  }%
}


\begin{document}

\tableofcontents

\chapter{Test}

\section{Short Entry}
\section{Very, Very, Very, Very, Very, Very, Very, Very, Very, Very, Very, Very, Very,
   Very, Very, Very, Very, Very, Very Long Entry}

\addsec{Short Entry}
\addsec{Very, Very, Very, Very, Very, Very, Very, Very, Very, Very, Very, Very, Very,
   Very, Very, Very, Very, Very, Very Long Entry}

\end{document}

You can proceed in the same way for other levels. It is useful that you do not need to know the indent of the respective level in order to set it for the new type. Instead, simply use option indent: and pass the name of a known level as the value so that its value is used.


Related

Wiki (English): HowTo_ToCConfiguration

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.