[Tex/LaTex] Add chapter/appendix prefix in table of contents of scrbook with correct appendix running head

appendicesheader-footerscrbooktable of contents

My first question is how to add the chapter or appendix prefix in the table of contents of scrbook class instead of the its default appearance.

For example, in the figure below, I want to change the chapter entry in TOC to Chapter 1. Introduction.

and the same goes for the appendix entry in TOC, which means typesetting Appendix A. Electro… instead of the figure below.

Additionally, I have used \appendix before starting my appendices, so it treats all the subsequent chapters as chapters A, B, etc. However, I want to treat them as appendices to appear correctly in the page headings as "Appendix A. Electro…" instead of "Chapter A. Electro…" in the page heading as shown below.

enter image description here

Thanks in advance

Best Answer

Your first question can be solved by using the tocstyle-package included in the KOMAscript-bundle. Try

 texdoc tocstyle

at an command prompt to see the documentation.

By redefining some internal variables, if I understand your question correctly, you will have the answer to your first question. Put this commands in your preamble:

\usepackage{tocstyle}
\renewcommand*{\addchaptertocentry}[2]{%
  \addtocentrydefault{chapter}{\chapapp\nobreakspace #1}{#2}%
}
\usetocstyle{KOMAlike}

Your second question was:

However, I want to treat them as appendices to appear correctly in the page headings as "Appendix A. Electro..."

This be solved by using the class-option chapterprefix=true or appendixprefix=true, if I understand your question correctly.

A complete MWE, which (hopefully) solve all questions:

\documentclass[appendixprefix=true]{scrbook}
\usepackage{blindtext}
\usepackage{tocstyle}
\renewcommand*{\addchaptertocentry}[2]{%
  \addtocentrydefault{chapter}{\chapapp\nobreakspace #1}{#2}%
}

\usetocstyle{KOMAlike}

\begin{document}
\tableofcontents
\blinddocument
\appendix

\blinddocument

\end{document}

If you are using \chapter in \fronmatter, remember to use the starred version to avoid a Chapter . with empty number in your Table of Contents. Also, if you are using the command \addchapin you document, use the starred version (\addchap*}.

For further reading, see page 80 in the English manual, and this discussion at the KOMAscript homepage.

NB! This code needs a recent version of komascript.