TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
ToC numbering problem

My LaTeX document is acting strangely. Here is a simplified version of it:




\addcontentsline{toc}{part}{A Part of My Document}


And in includedfile.tex:

\section{My Section Title}

Clearly, in the table of contents, the heading for the part should precede the one for the section, but it doesn't! What's wrong?

share|improve this question

marked as duplicate by Martin Scharrer May 9 '12 at 10:37

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.

Discussed on SO here: stackoverflow.com/questions/1217080/latex-toc-numbering-problem. I got a solution that worked, but it was more of a workaround and less of a fix for the real problem. – Ben Alpert Jul 26 '10 at 19:34
up vote 8 down vote accepted

Try \input instead of \include -- it's as if you typed in the contents of the file there. I believe \include does some additional processing, so maybe that's causing your problem.

share|improve this answer
Again, like on SO, this works but doesn't really explain how to fix the problem and why I can't use \include. – Ben Alpert Jul 31 '10 at 20:55
@BenAlpert, Reid: See When should I use \input vs. \include? for more details on the difference. – Martin Scharrer May 9 '12 at 10:35

The \include macro is intended for inputting chapters in long documents. Thus any file used with \include really should start


It also automatically starts a new page (which will confuse the order of things with your \addcontentlines instruction, I think). What you want is \input. This simply places the contents of the subfile into the TeX source at the current location, with no additional stuff going on. If you replace \include with \input then all is well. (Note: I'm trying to 'flesh out' the answer given by Reid Priedhorsky here: the end result is of course the same.)

share|improve this answer

The problem is to do with the \newpage command. If you remove it, I think you'll get exactly the output you're looking for.

share|improve this answer
An explanation of why this works would be very helpful. – Novelocrat Jul 26 '10 at 21:40
I agree, but didn't include one because I'm not sure of the reason. My guess is that since there is no content between \newpage and \addcontentsline, the previous page has ended but a new one hasn't been created yet, so there isn't a page to associate with the contents line. \include is then called, which creates the new page, and in turn gives the contents line something to reference, but unfortunately after the included content. It may also be related to the fact that \tableofcontents adds a page break automatically, so \newpage is trying to create a second blank page in a row. – Michael Underwood Jul 27 '10 at 17:40

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