Sie sind hier

Problem adding "Chapter #" to every chapter entry in TOC

Hi,

First of all, I apologize because I do not speak German so I have to ask in English.

I have made this minimal example where I'm trying to put "Chapter" + "it's number" in front of every chapter in the TOC.

\documentclass[chapterprefix]{scrbook}
 
\newcommand\chapterentrynumberformat[1]{\chapapp\ #1}
\RedeclareSectionCommand[
    tocentrynumberformat=\chapterentrynumberformat,
    tocnumwidth=5.5em
]{chapter}
 
\usepackage{blindtext}
\begin{document}
\frontmatter
\tableofcontents
\listoftables
\mainmatter
\blinddocument
\appendix
\blinddocument
\end{document}

It works well except because it uses "Chapter" and not "Appendix" in front of appendix entries. I attach an image to show it.
I have tried with:

\newcommand\chapterentrynumberformat[1]{\chapappifchapterprefix\ #1}

but there is no change.

I'm using koma-script 3.25.
What I can be wrong?

Thank you.

[Admin-Edit:]

  1. Replaced <pre>…</pre> by <blockcode>…</blockcode> (see Format Tipps)

AnhangGröße
Image icon toc.png66.12 KB

The \tableofcontents of you document is at the main part of your document, not at the appendix. So while the \tableofcontents in your document is executed, \chapapp ist “Chapter”, not “Appendix” while usage of \chapterentrynumberformat for the whole table of contents. You need to add \chapapp to the writing of the entries not the reading of them. You can do this, changing \addchaptertocentry, e.g.:

\documentclass[chapterprefix]{scrbook}
 
\RedeclareSectionCommand[
  tocnumwidth=6em% 5.5 is not enough
]{chapter}
\let\originaladdchaptertocentry\addchaptertocentry
\renewcommand*{\addchaptertocentry}[2]{%
  \IfArgIsEmpty{#1}{% entry without number
    \originaladdchaptertocentry{#1}{#2}%
  }{% entry with number
    \originaladdchaptertocentry{\chapapp~#1}{#2}%
  }%
}
 
\usepackage{blindtext}
\begin{document}
\frontmatter
\tableofcontents
\listoftables
\mainmatter
\blinddocument
\appendix
\blinddocument
\end{document}

Compare the *.toc file with and without this change to see the difference.

Comments for "Problem adding &quot;Chapter #&quot; to every chapter entry in TOC" abonnieren