Chapter 1 First chapter
1.1 First section
Appendix A First appendix
A.1 .....
You can tweak tocloft/memoir but the difference in width of Chapter and
Appendix ('Hoofstuk' and 'Bylae' in Afrikaans) causes a problem. The
following example uses a new TOC item, \l@appendix, to obtain the
desired result. This is much simpler than the elaborate AMS procedures
of writing the widths to a file and then reading it back.
I hope someone finds it usefull
%======================================================
\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[plainpages=false,% for page i and 1, ii and 2, etc.
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}
--
Danie Els
(Substitude initials DNJ for first name in e-address)
Some nice code by Danie Els but if you use memoir or tocloft you can get
away with a lot less code.
% \documentclass[...]{report/book} \usepackage{tocloft}
% \documentclass[...]{memoir}
%% in the preamble, this handles the Chapter entries
\renewcommand*{\cftchappresnum}{\chaptername\space}
\setlength{\cftchapnumwidth}{6em} % change length to suit
%% this will handle the Appendix entries
\DeclareRobustCommand{\changetoapp}{%
\renewcommand*{\cftchappresnum}{\apendixname\space}%
\setlength{\cftchapnumwidth}{7em}}
%% modify the \appendix macro to add code to the ToC
\let\oldappendix\appendix
\renewcommand*{\appendix}{\oldappendix
\addtocontents{toc}{\changetoapp}}
...
\begin{document}
...
\chapter{A chapter}
...
\appendix
\chapter{An appendix}
...
\end{document}
Peter W.
--
The English FAQ is at: http://www.tex.ac.uk/faq
Examples of all symbols:
http://www.ctan.org/tex-archive/info/symbols/comprehensive
\appendix
\include{App-A}
I'm not sure if this is a bug or a feature of LaTeX, but it is well
known. That's the reason why I don't use information written to the
toc. To overcome this, the \appendix must be inside the included file,
and that is not in the spirit of general markup.
> ...
> \begin{document}
> ...
> \chapter{A chapter}
> ...
> \appendix
> \chapter{An appendix}
> ...
> \end{document}
>
> Peter W.
Danie Els (dnjels at sun dot ac dot za)