my problem is related to the number of pages in the table of contents, list of figures and list of contents. Everything in my .pdf works well except that! I don't understand why!
Could you help me?
In the following my main:
\begin{document}
\hyphenation{Com-po-si-to-ri}
\hyphenation{Giu-sep-pe}
\hyphenation{Ba-lu-stra-des}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt}
\fancypagestyle{plain}{
\fancyhead{}
\renewcommand{\headrulewidth}{0pt} % e la linea
}
\includepdf[pages={1}]{Frontespizio.pdf}
\newpage
\thispagestyle{empty}
\clearpage{\pagestyle{empty}\cleardoublepage}
\selectlanguage{english}
\tableofcontents
\clearpage{\pagestyle{empty}\cleardoublepage}
\listoffigures
\clearpage{\pagestyle{empty}\cleardoublepage}
\listoftables
\clearpage{\pagestyle{empty}\cleardoublepage}
\large
\setcounter{secnumdepth}{-1}
\selectlanguage{italian}
\input{Sommario}
\clearpage{\pagestyle{empty}\cleardoublepage}
\selectlanguage{english}
\input{Acronym.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{Abstract}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{Introduction.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\clearpage
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{4}
\onehalfspacing
\input{Iso.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{Literature.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{Storia.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{IRMeasurement.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{ComputerModelling.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{Discussion.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{Conclusions.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{Bibliografia.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\input{Ringraziamenti.tex}
\clearpage{\pagestyle{empty}\cleardoublepage}
\end{document}
Best Answer
You need at least two up to three (or more) LaTeX runs to get the table of contents right:
During one LaTeX run the following happens:
\begin{document}
: The.aux
files are read, entries for the table of contents or list of figures/tables are ignored (because of\let\@writefile\@gobbletwo
).\tableofcontents
/\listoffigures
/\listoftables
call\@startoc{<ext>}
(<ext>
=toc
,lof
, orlot
).It reads the file
\jobname.<ext>
, the table of contents (or list of ...) is set.The
\jobname.<ext>
is cleared and opened for writing.\chapter
,\section
,\caption
, ... internally call \addcontentsline{}{...}{...}and
\addtocontents{}{...}. These write
\@writefile{}{...}commands into the
.auxfile. This can also happen before
\tableofcontents` and friends are called.\end{document}
. After the last page is shipped out, the.aux
file is closed and read in again. Now the\@writefile{<ext>}{<contents>}
commands are executed and the<contents>
is written to the correspondent\jobname.<ext>
file or ignored, if\jobname.<ext>
is not opened. For example, if there are figure captions, but\listoffigures
is not called, then\jobname.lof
is not written.That means the printed table of contents (list of figures, ...) has the status of the previous LaTeX run. In the first LaTeX run, the
\jobname.<ext>
files are not yet written and the table of contents and the lists are empty. Thus the minimal requirement are two LaTeX runs.If the table of contents and the lists are not numbered independently, then it can happen, that there are so many entries, that there are more pages than an empty list would need. Then the following page number after the lists increases as all following entries for the lists. Then another LaTeX run is needed.
For example, two side setting with
\cleardoublepage
:An empty table of contents needs one page for the title (
Contents
) and an empty page (because of\cleardoublepage
). The table of contents is three pages long:First LaTeX run:
Second LaTeX run:
Thus the page number is wrong, but LaTeX does not warn.
Third LaTeX run:
Now, the table of contents is correct.
Rerun warnings
LaTeX does not warn, if another LaTeX run is needed for the table of contents and the other lists. There is a package
rerunfilecheck
that uses\pdfmdfivesum
ofpdfTeX
(both DVI or PDF mode) to calculate a MD5 checksum over an auxiliary file at the beginning and the end of the job. If something has changed, then the package prints a rerun warning:The first and second run generates the warnings:
The third run is successful without warnings.