[texhax] \addcontentsline -- line added to TOC appears in wrong place -- ANSWER

Niall Mansfield texhax at uit.co.uk
Thu May 8 10:09:50 CEST 2008


The answer is:
(a) The description below isn't accurate -- the \chapter*'s
     are in fact \include'd in the main file.
(b) The LaTeX Companion explicitly describes the problem of
     \addtocontents when used at the same level as \include,
     on p49 (Second Ed.).  It says, in effect, "don't do it".
(c) \input instead of \include does seem to work OK, and lets
     us keep the same file organization.

	Niall


   > - Using book.cls.
   > - Redefined \appendix, to add an "Appendixes" heading line to
   >    the TOC, as follows:
   >
   > \renewcommand\appendix{
   >    \addcontentsline{toc}{chapter}{Appendixes}	%% this is the new line
   >    \par
   >    \setcounter{chapter}{0}%
   >    \setcounter{section}{0}%
   >    \gdef\@chapapp{\appendixname}%
   >    \gdef\thechapter{\@Alph\c at chapter}}
   >
   > When we run this on a .tex file of the form:
   >
   > 	\chapter{Last chap}
   > 	...
   > 	\appendix
   > 	\chapter*{APX-1}
   > 	...
   > 	\chapter*{APX-2}
   > 	...
   >
   > we get the "Appendixes" line in the wrong place.
   > The .toc file shows this:
   >
   > \contentsline {chapter}{\numberline {A}APX-1}{53}
   > \contentsline {chapter}{Appendixes}{53}
   > \contentsline {chapter}{\numberline {B}APX-2}{57}
   >
   > What's happening?


More information about the texhax mailing list