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
.
The following code will remove the phrase "Appendix. " in front of "Bibliography" in the table of contents when using the LaTeX amsbook
class or the LyX document class book (AMS)
.
\usepackage{xstring}
\renewcommand{\tocappendix}[3]{%
\indentlabel{\IfStrEq{#3}{Bibliography}{}{#1}\@ifnotempty{#2}{ #2.\quad}}#3}
For LyX, this code can be inserted into the LaTeX Preamble ("Document > Settings...").
Background:
For typesetting the table of contents, the ".toc" file is used (it can be found in the "tmpdir" / "tmpbuf" directory of LyX). It contains lines like
\contentsline {chapter}{\tocappendix {Appendix}{A}{My First Appendix}}{3}
\contentsline {chapter}{\tocappendix {Appendix}{}{Bibliography}}{3}{appendix*.1}
Furthermore, the class file amsbook.cls
defines
\newcommand{\tocappendix}[3]{%
\indentlabel{#1\@ifnotempty{#2}{ #2}.\quad}#3}
By redefining the command \tocappendix
we can omit the printing of the first argument (e.g., "Appendix") if the third argument is "Bibliography". For string comparison, the xstring
package is used. Furthermore, the bracket }
in front of .\quad
was moved behind \quad
.
Best Answer
\addcontentsline
is written to the toc when the page is "shipped out". If the command is on an empty page which is not written to the pdf or dvi it gets lost - it wouldn't have much sense anyway as without page there is no sensible page number.