0

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}
3
  • 2
    Try to delete all aux files and compile your main file twice.
    – Sigur
    Jun 24 '13 at 16:40
  • Not really an answer to your question but did you consider using \include instead of \input? The way you are putting together your document looks as if \include may be the better option.
    – vaettchen
    Jun 24 '13 at 17:19
  • All those \clearpage{\pagestyle{empty}\cleardoublepage} can be avoided by \usepackage{emptypage}.
    – egreg
    Jun 24 '13 at 19:34
4

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, or lot).

    1. It reads the file \jobname.<ext>, the table of contents (or list of ...) is set.

    2. 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:

\begin{document}
\tableofcontents
\cleardoublepage
\chapter{...}
...

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:

  1. First LaTeX run:

    1. Page: Contents <otherwise empty>
    2. Page: <empty>
    3. Page: Chapter 1 ...
    
  2. Second LaTeX run:

    1. Page: Contents, Chapter 1 -> page 3, <other entries>
    2. Page: <other entries>
    3. Page: <other entries>
    4. Page: <empty>
    5. Page: Chapter 1 ...
    

    Thus the page number is wrong, but LaTeX does not warn.

  3. Third LaTeX run:

    1. Page: Contents, Chapter 1 -> page 5, <other entries>
    2. Page: <other entries>
    3. Page: <other entries>
    4. Page: <empty>
    5. Page: Chapter 1 ...
    

    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 of pdfTeX (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:

\documentclass{book}

\usepackage[starttoc]{rerunfilecheck}

\newcommand*{\cleardoubleemptypage}{%
  \clearpage
  \begingroup
    \pagestyle{empty}%
    \cleardoublepage
  \endgroup
}

\begin{document}
Title page
\cleardoubleemptypage
\tableofcontents
\cleardoubleemptypage
\listoffigures
\cleardoubleemptypage
\listoftables
\cleardoubleemptypage
\chapter{First chapter}
\begin{figure}
\caption{First figure}
\end{figure}
\addtocontents{toc}{\protect\clearpage}% short for many \chapter/\section/... entries
\chapter{Second chapter}
\addtocontents{toc}{\protect\clearpage}% short for many \chapter/\section/... entries
\chapter{Third chapter}
\end{document}

The first and second run generates the warnings:

Package rerunfilecheck Warning: File `test.toc' has changed. Rerun.
Package rerunfilecheck Warning: File `test.lof' has changed. Rerun.

The third run is successful without warnings.

2
  • Thank you all! Now everithing work well even if I can't understand why..Yesterday I rum my main much more than twice, but the problem was still there. Today I decided to look in my toc, and the number of pages were rigth, even if the pdf output was wrong! I can't really explain! Then I tried to chang \input with \include, but it wasn't good, because my pdf was almost empty..at last I repalced again \include with the previous \input..and..magic! All page numbering works well..
    – Lisa
    Jun 25 '13 at 5:57
  • My problem is also solved by remove lof and toc, then regenerate.
    – Junchen
    Feb 10 '17 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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