In “How to prepend a 'chapter' to the number of chapter entries in the table of contents” both normal chapters and appendix chapters are prefixed in the table of contents. Sometimes, however, this is only requested for the appendix. So this is similar to the usage of option appendixprefix=true
for the headings in the text.
Anyway, this works in the same way as already shown in the post linked above. However, we need to distinguish between entries in the appendix and entries outside the appendix. We make this distinction via a suitable definition of \appendixmore
:
\newcommand*{\tocchapapp}{}
\newcommand*{\appendixmore}{%
\renewcommand*{\tocchapapp}{\chapapp\ }%
\addtocontents{\csname ext@toc\endcsname}{%
\string\DeclareTOCStyleEntry[numwidth+=5em]{chapter}{chapter}%
}%
}
So here by calling \appendix
firstly the command \tocchapapp
is suitably redefined, namely with prefix plus following space. Secondly, a change of width for numbering is written into the current table of contents file defined by \ext@toc
.
What is then missing is the replacement of \chapapp\
with the new \tocchapapp
. This changes the first example to:
\documentclass{scrbook}
\usepackage{blindtext}
\newcommand*{\tocchapapp}{}
\newcommand*{\appendixmore}{%
\renewcommand*{\tocchapapp}{\chapapp\ }%
\addtocontents{\csname ext@toc\endcsname}{%
\string\DeclareTOCStyleEntry[numwidth+=5em]{chapter}{chapter}%
}%
}
\renewcommand*{\addchaptertocentry}[2]{%
\IfArgIsEmpty{#1}{% keine Nummer:
\addtocentrydefault{chapter}{#1}{#2}% wie bisher
}{% mit Nummer:
\addtocentrydefault{chapter}{\tocchapapp#1}{#2}%
}%
}
\begin{document}
\tableofcontents
\blinddocument
\addchap{Heading of not numbered chapter}
\blindtext
\appendix
\blinddocument
\addchap{Heading of not numbered appendix}
\blindtext
\end{document}
In the second example, where unnumbered entries are to be prefixed as well, the whole thing actually makes no sense. Nevertheless, I want to show the appropriate code here:
\documentclass[toc=numberline]{scrbook}
\usepackage{blindtext}
\newcommand*{\tocchapapp}{}
\newcommand*{\appendixmore}{%
\addtocontents{\csname ext@toc\endcsname}{%
\string\DeclareTOCStyleEntry[numwidth+=5em,
entrynumberformat=\string\appendixprefixformat]{chapter}{chapter}%
}%
}
\newcommand*{\appendixprefixformat}[1]{\appendixname\ #1}
\begin{document}
\tableofcontents
\blinddocument
\addchap{Heading of not numbered chapter}
\blindtext
\appendix
\blinddocument
\addchap{Heading of not numbered appendix}
\blindtext
\end{document}
Wiki (English): HowTo_ToCConfiguration
Wiki (English): HowTo_TocChapterPrefix