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 \addchap
in 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
.
There are two and a half solutions (only the second one is valid if you need to use \include
):
- Use
\input
instead of \include
(if you don't need the functionality of \include
).
- Put
\appendices
into appendixA.tex
.
Manually configure the TOC file from
\contentsline {chapter}{\numberline {1}First things}{1}
\contentsline {chapter}{\numberline {A}The initial stuff}{3}
\contentsline {section}{\numberline {A.1}A section within the initial appendix}{3}
\contentsline {chapter}{Appendices}{3}
\contentsline {chapter}{\numberline {B}Another addendum}{5}
to
\contentsline {chapter}{\numberline {1}First things}{1}
\contentsline {chapter}{Appendices}{3}
\contentsline {chapter}{\numberline {A}The initial stuff}{3}
\contentsline {section}{\numberline {A.1}A section within the initial appendix}{3}
\contentsline {chapter}{\numberline {B}Another addendum}{5}
The package manual states:
There is an unfortunate interaction between the LaTeX kernel commands \include
and \addcontentsline
. […]
Things work as expected if the \addcontentsline
command is placed
within the \included
file, or if the imported file is \input
ed instead of \includ
ed.
On another note: appencides
is an environment not a macro, so you better use \appendices … \endappendices
or \begin{appendices} … \end{appendices}
.
Best Answer
\appendix
only changes the chapter numbering toAlph
; it doesn't add a page break. Solution: Add\cleardoublepage
before\appendix
. (This is appropriate for a document using theopenright
class option; foropenany
, use\clearpage
.)EDIT: Personally, I wouldn't add a "pseudo chapter" to the ToC that doesn't correspond to an existing chapter (there is no chapter called "Appendix" in your example). Consider to add an unnumbered "Appendix" part to the main text and the ToC instead.