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
.
In the arguments of \titlecontents
, replace \chaptername
with \@chapapp
. Also, at the beginning of the appendices
environment a changed definition of \@chapapp
(to \appendixname
) must be forwarded to the .toc
file. Last, but not least, remove the titletoc
option from the appendix
package.
\documentclass{book}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{appendix}
\makeatletter
\titlecontents{chapter}%
[0em]%
{\addvspace{2em}}%
{\bfseries\@chapapp\ \thecontentslabel\quad}%
{\hspace{-0em}}%
{\hfill\contentspage}%
[\addvspace{0pt}]%
\g@addto@macro\appendices{%
\addtocontents{toc}{\protect\renewcommand{\protect\@chapapp}{\appendixname}}%
}
\makeatother
\usepackage{lipsum}
%
\begin{document}
\tableofcontents
\chapter{First chapter}\lipsum[1]
\section{First section}\lipsum[2]
\subsection{First subsection}\lipsum[3]
\chapter{Second chapter}\lipsum[4]
\section{Second section}\lipsum[5]
\subsection{Second subsection}\lipsum[6]
\subsection{Third subsection}\lipsum[7]
%appendices
\begin{appendices}
\chapter{First appendix}\lipsum[1]
\section{Some section}\lipsum[2]
\subsection{Some subsection}\lipsum[3]
\subsection{Some subsection}\lipsum[4]
\chapter{Second appendix}\lipsum[5]
\section{Some section}\lipsum[6]
\subsection{Some subsection}\lipsum[7]
\end{appendices}
%
\end{document}
Best Answer
Here is a solution using
etoc
package