GeneralTOC "Appendices" comes after 1st appendix entry

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

TOC "Appendices" comes after 1st appendix entry

Post by murraye »

I use the appendix package with its toc option for a book document. If the first of several appendices is inserted by using \include, then the "Appendices" heading in the TOC incorrectly appears after the entries for the first appendix.

This happens no matter whether I use the \appendices command, as shown below, or else the appendices environment.

The same thing happens if I don't use the appendix package but instead just the \appendix command and use an \addcontentsline to insert the "Appendices" item in the TOC.

This behavior does not occur if the body of the appendix is inserted directly in the main document.

The behavior does not occur, either, if instead of using \include for the first appendix, I use \input. However, I really do want to use \include since my actual book-length document uses an \includeonly for selective processing of various chapters, including appendices, as I work.

Here's a MWE:

Code: Select all

\documentclass{book}
\usepackage[toc]{appendix}

\begin{document}

\frontmatter
\tableofcontents

\mainmatter

\chapter{First things}
This comes first.

\appendices

\include{appendixA}

\chapter{Another addendum}
This is some more information.

\end{document}
The included file:

Code: Select all

\chapter{The initial stuff}
All about `A'.

\section{A section within the initial appendix}
Yet more.
\endinput
(In the main file, I have a 2nd appendix right there, but it makes no difference if I put that in a separate file and use another \include for it.)

In the actual situation, I have a number of appendices and each has many pages, so inserting their body in the main document is not really an option.

Is there some other work-around?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

TOC "Appendices" comes after 1st appendix entry

Post by murraye »

A resolution of this issue appears at http://tex.stackexchange.com/questions/74039/.

Briefly: there's a documented conflict betwen \include and \addcontentsline.

Possible workarounds are:

(1) use \input instead of \include (which is what I was trying to avoid);

(2) keep \include but move the \appendix and \addcontentsline{toc}{chapter}{Appendices} inside that included file (or, equivalently if using the appendix package, move the \appendices or corresponding environment into the included file);

(3) manually edit the .toc file so as to move up the line \contentsline {chapter}{Appendices}{...} before the entry for the first appendix.

None of these workarounds is especially palatable, but apparently they are the only solutions.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

TOC "Appendices" comes after 1st appendix entry

Post by Stefan Kottwitz »

Hi murraye,

nice to see that you found it out, thanks for posting the solution. Btw. we had the same already here: Appendix not appearing in the table of contents.

Stefan
LaTeX.org admin
murraye
Posts: 34
Joined: Sat Aug 15, 2009 6:25 pm

TOC "Appendices" comes after 1st appendix entry

Post by murraye »

Stefan_K wrote:Hi murraye,

nice to see that you found it out, thanks for posting the solution. Btw. we had the same already here: Appendix not appearing in the table of contents.

Stefan
That post on this forum did not appear to be quite the same issue: it dealt with the title of a particular appendix not appearing in the TOC. In my issue, the title of the particular appendix as well as the entry "Appendices" both appeared; it was just that the latter was out of order.
Post Reply