Menu

HowTo_TocChapterPrefix

How to prepend a “Chapter” to the number of chapter entries in the table of contents.

This can be done in KOMA-Script primarily by redefining \addchaptertocentry. In this case, if a number has been specified, i.e. the first argument is not empty, it is best to insert \chapapp followed by a whitespace character, i.e.:

\renewcommand*{\addchaptertocentry}[2]{%
  \IfArgIsEmpty{#1}{% no number:
    \addtocentrydefault{chapter}{#1}{#2}% as before.
  }{% with number:
    \addtocentrydefault{chapter}{\chapapp\ #1}{#2}%
  }%
}

Additionally you have to make sure that there is enough space for the number. This can be done in KOMA-Script with the help of \DeclareTOCStyleEntry:

\DeclareTOCStyleEntry[numwidth=5.5em]{chapter}{chapter}

or \RedeclareSectionCommand:

\RedeclareSectionCommand[tocnumwidth=5.5em]{chapter}

can be achieved.

I myself prefer \RedeclareSectionCommand, because you don't need to know, i.e. look up in the KOMA-Script manual, that there is a style chapter for chapter entries, which has to be specified as the first mandatory argument to \DeclareTOCStyleEntry.

All in all, this results in:

\documentclass{scrbook}
\usepackage{blindtext}

\renewcommand*{\addchaptertocentry}[2]{%
  \IfArgIsEmpty{#1}{% no number:
    \addtocentrydefault{chapter}{#1}{#2}% as before.
  }{% with number:
    \addtocentrydefault{chapter}{\chapapp\ #1}{#2}%
  }%
}

\RedeclareSectionCommand[tocnumwidth=5.5em]{chapter}

\begin{document}
\tableofcontents
\blinddocument
\addchap{Heading of not numbered chapter}
\blindtext
\end{document}

Why \chapapp was used instead of a static string “chapter” should become clear if you read the explanation of this statement in the KOMA-Script manual or in the German KOMA-Script book.

If the prefix should also be set for unnumbered entries and at the same time the text of the entry should be indented as for numbered entries, rather use the property entrynumberformat for \DeclareTOCEntryStyle or tocentrynumberformat for \RedeclareSectionCommand and additionally set option toc=numberline:

\documentclass[toc=numberline]{scrbook}
\usepackage{blindtext}

\newcommand*{\chapterentrynumberwithprefix}[1]{\chapapp\ #1}
\RedeclareSectionCommand[tocnumwidth=5.5em,tocentrynumberformat=\chapterentrynumberwithprefix]{chapter}

\begin{document}
\tableofcontents
\blinddocument
\addchap{heading of not numbered chapter}
\blindtext
\end{document}

Without the toc=numberline option, using tocentrynumberformat will only affect the numbered chapter entries.

The solution using entrynumberformat and \DeclareTOCStyleEntry also works with the standard classes with some adjustments. Of course, package tocbasic must then be loaded explicitly. The numberline property is then set for the table of contents via \setuptoc:

\documentclass{book}
\usepackage{blindtext}
\usepackage{tocbasic}

\renewcommand*{\tableofcontents}{\listoftoc[\contentsname]{toc}}% use tocbasic for the ToC
\setuptoc{toc}{numberline}
\newcommand*{\chapterentrynumberwithprefix}[1]{\csname @chapapp\endcsname\ #1}% \chapapp is unknown → use \@chapapp
\DeclareTOCStyleEntry[numwidth=5.5em,entrynumberformat=\chapterentrynumberwithprefix]{tocline}{chapter}% style chapter is unknown → use style tocline

\begin{document}
\tableofcontents
\blinddocument
\chapter*{Heading of not numbered chapter}
\addxcontentsline{toc}{chapter}{Heading of not numbered chapter}
\blindtext
\end{document}

Related

Wiki (English): HowTo_ToCConfiguration
Wiki (English): HowTo_TocAppendixPrefix
Wiki (English): HowTo_TocPartPrefix

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.