5

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

0

3 Answers 3

4

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.

17
  • Thanks for help, but the MWE doesnt work and I got this "! LaTeX Error: \addchaptertocentry undefined."
    – Diaa
    Jul 7, 2012 at 1:32
  • Strange, The MWE works on my system (updated MikTeX on Win 7). What is your version of koma-script?
    – Sveinung
    Jul 7, 2012 at 7:44
  • After updating the Miktex 2.9 packages, the same error appears. Regarding the Koma version, here is the line from log file: Document Class: scrbook 2010/09/17 v3.07 KOMA-Script document class (book
    – Diaa
    Jul 7, 2012 at 18:12
  • @Diaa Current version of komascript is 3.11a. My scrbook reports: scrbook 2012/05/15 v3.11 KOMA-Script document class (book). If your miktex that does not update your packages correctly, or maybe you have a copy of scrbook in your texmf-local (or whatever you have named your private TeX directory). The code need a recent version of komascript.
    – Sveinung
    Jul 7, 2012 at 20:22
  • 1
    I fixed it by removing the option "bibliography=totoc" and inserting "\addcontentsline{toc}{chapter}{References}" after \bibliography{<bibfile.bib>}. If available, can you tell me why does this awkward entry appear in case of using the class option ?
    – Diaa
    Jul 9, 2012 at 0:36
4

Thanks to the answer of the question \chaptername is used even for appendix chapters in ToC

the syntax of

\usepackage{tocloft,calc}
\renewcommand{\cftchappresnum}{\chaptername\space}
\setlength{\cftchapnumwidth}{\widthof{\textbf{Appendix~999~}}}
\makeatletter
\g@addto@macro\appendix{%
  \addtocontents{toc}{%
    \protect\renewcommand{\protect\cftchappresnum}{\appendixname\space}%
  }%
}
\makeatother

has a successful result in prefixing the chapters entries in TOC with the word "Chapter" (same for appendices).

For the running headings in the in the appendices environment, the following syntax changes

Chapter to Appendix

\begin{document}

\appendix
\renewcommand{\chaptermark}[1]{\markboth{Appendix\ \thechapter.\ #1}{}}
\chapter{Appendix A}
\chapter{Appendix B}

\end{document}
3

Here is a suggestion that also works if you use chapters in frontmatter or options like listof=totoc, listof=chapterentry or if you use \addchap.

\documentclass[
  chapterprefix,
  %numbers=noenddot,
  %toc=indentunnumbered,
  listof=totoc,
  %listof=chapterentry
]{scrbook}[2016/05/10]

\usepackage[english]{babel}

\usepackage{xpatch}
\xpatchcmd{\addchaptertocentry}{%
    \addtocentrydefault{chapter}{#1}{#2}%
  }{%
    \ifstr{#1}{}
      {\addtocentrydefault{chapter}{#1}{#2}}%<- unnumbered chapters in TOC
      {\addtocentrydefault{chapter}{\chapapp{} #1}{#2}}%<- numbered chapters in TOC
  }{}{\PatchFailed}

\RedeclareSectionCommand[
    tocdynnumwidth
]{chapter}

\usepackage{blindtext}
\begin{document}
\frontmatter
\tableofcontents
\listoftables
\chapter{This is a chapter in frontmatter}
\mainmatter
\blinddocument
\begin{table}%
  \begin{tabular}{l}
  \Huge X
  \end{tabular}
\caption{A table}
\end{table}
\addchap{This is an unnumbered chapter}
\addsec{This is an unnumbered section}
\appendix
\blinddocument
\end{document}

Result:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .