# Adding a line to the TOC before the appendix [duplicate]

Possible Duplicate:

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}
\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.

-

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

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}

-