The answers using tocloft
works fine if you are not using the \include
command. The problem is the delayed write mechanism used inside the \addtocontents
to put stuff in the toc usualy ends up after the include contents. Solutions that works under all conditions are:
(1) It is the default behaviour of the amsbook
class
(2) With memoir
it can be obtain by putting the following in your preamble:
\renewcommand*{\cftpartname}{PART~}
\renewcommand*{\cftchaptername}{\chaptername~}
\renewcommand*{\cftappendixname}{\appendixname~}
\renewcommand*{\cftchapteraftersnum}{.}% dot after the number
\setlength{\cftchapternumwidth}{2em}
(3) With the standard book
class you need a lot of changes. The following is from c.t.t. and was the basis of the code that ended up in memoir
\documentclass{book}
\makeatletter
%% Add a conditional to \appendix. Could also use \@chapp.
\newif\if@inappendix\@inappendixfalse
\let\oldappendix=\appendix
\renewcommand*{\appendix}{\oldappendix\@inappendixtrue}
%% User defined number width in TOC (\tocchpnumwdth)
%% Add inserts for Chapter and Appendix. Define to
%% \relax if standard output is needed.
\newlength{\tocchpnumwdth}
\setlength{\tocchpnumwdth}{1.5em}
\newcommand*{\tocchapinsert}{\chaptername\space}
\newcommand*{\tocappinsert}{\appendixname\space}
%% Small change in \@chapter. Write write different contents
%% line for Chapter and Appendix. Add inerts to \numberline.
\def\@chapter[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\if@inappendix
\addcontentsline{toc}{appendix}%<-- THIS IS NEW
{\protect\numberline{\tocappinsert\thechapter}#1}%<-
\else
\addcontentsline{toc}{chapter}%
{\protect\numberline{\tocchapinsert\thechapter}#1}%<-
\fi
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\chaptermark{#1}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi}
%% Creates a \l@appendix identical to \l@chapter. Add the
%% width of the inserts to the width of the \numberline
%% box (\@tempdima).
\renewcommand*\l@chapter{\l@@chapter{\tocchapinsert}}
\newcommand*\l@appendix{\l@@chapter{\tocappinsert}}%<-- NEW
\newcommand*\l@@chapter[3]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode \bfseries
\settowidth{\@tempdima}{#1}% <- change
\addtolength\@tempdima{\tocchpnumwdth}%<- change
\advance\leftskip\@tempdima
\hskip -\leftskip
#2\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #3}\par
\penalty\@highpenalty
\endgroup
\fi}
%% Keep hyperref happy
\def\toclevel@appendix{0}
\makeatother
\usepackage[breaklinks=true, % for long names
]{hyperref}
\begin{document}
\frontmatter
\chapter{Preface}
\tableofcontents
\chapter{Nomenclature}
\mainmatter
\chapter{First Chapter}
\section{First Section}
\appendix
\chapter{First Appendix}
\section{First Appendix Section}
\backmatter
\chapter{Data Tables}
\end{document}
Appendix.tex
andIntro.tex
and you do not post them. You should have made your code simpler if you just made examples of a\chapter
before and inside theappendices
environment, without the need of extra files.