Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
First chapter appearing before first line in table of contents

I am having issues with inserting a line into the TOC when including external files. \input and \include behave differently in this case.

My MWE

\documentclass{report}

\begin{filecontents}{appen.tex}
\chapter{Appendix 1}
This is the appendix
\end{filecontents}

\begin{document}
\tableofcontents
\chapter{Main}
This is the main part.

\appendix
\part*{Appendix}                                                    
\addtocontents{toc}{%
\protect\contentsline{chapter}{Appendix}{}{}}

\input{appen}

\end{document}

works like a charm and does what I want it to. When I change the \input command into an \include, however, the note "Appendix" appears AFTER the chapter "Appendix 1".

I could just work with \inputing the first chapter of the appendix and \includeing the rest (which does work fine), but I wonder if anyone can explain this behaviour and maybe has a solution, so that I can \include the first appendix chapter, too.

share|improve this question

marked as duplicate by Harish Kumar, cmhughes, Guido, Kurt, Werner Dec 27 '12 at 3:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

I personally think you are over complicating things, you shouldn't need to manually add to the TOC.

If you are insistent on using the \begin{filecontents} to simulate external files, I did notice that it doesn't overwrite if the file exists, this may be giving you a false negative. Incidentally, the overwrite error is one of the reasons the filecontents package was developed, so try the below.

\documentclass{report}
\usepackage{filecontents}

\begin{filecontents*}{appen.tex}
    \chapter{An Appendix Chapter}
    This is the appendix
\end{filecontents*}

\begin{document}
\tableofcontents

\chapter{Main}
This is the main part.

\appendix
\include{appen}
\end{document}
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.