[Tex/LaTex] Wrong page numbering for list of figures and list of tables in Table of Contents!

table of contents

I know other people have asked this question but having scanned through the answers there seems to be two solutions: compiling 3 or 4 times and trying out some snippets of code involving the \markboth command. I have tried both and can't seem to fix it.

It seems to me (with my superficial understanding of Latex) that this is a problem of forward referencing and the more you compile the more accurate the pointers become. I re-compiled up to 7 times and couldn't get this problem to go away.

Here's my master file where I call every other component:

\documentclass[12pt, a4paper,twoside]{./a4LaTex/tesi_upf}
\input{Latex/Macros/Macrofile}
\usepackage[latin1]{inputenc}
\usepackage[english,french]{babel}
\usepackage{textgreek} %%%%% greek letters in text mode
\usepackage{fixltx2e} %%%%%% sub/superscript type face in text mode
\usepackage[a4paper]{geometry}
\usepackage{graphicx}%%%%% including figures
\usepackage[Bjarne]{fncychap}%%%%% fancy chapter names
\pagestyle{plain} %UPF DONT CHANGE

\usepackage{makeidx}
\usepackage{hyperref}%%%%% for links to references
\usepackage{textcomp}
\usepackage{natbib}%%%%% for bibliography
\renewcommand{\bibsection}{\chapter{\bibname}}
\usepackage{verbatim}
\usepackage[LGR,OT1]{fontenc}%%%%% font
\usepackage{epigrafica}%%%%% font
\usepackage{fancyhdr}
\usepackage{multirow}
\usepackage{fancybox}
\usepackage{lettrine} % for the beginning of chapters
\usepackage{hyphenat} %%%making life easier with hyphenation
\usepackage{amsmath}  %%%making life easier writing math equations
\usepackage{array}
\usepackage{pdfpages}
\usepackage{boxedminipage}
\usepackage{subfigure}
\usepackage{floatrow}
\usepackage{longtable}
\usepackage{pdfpages}  % for inserting PDF files into Latex
\usepackage{morefloats}


%%%%% Colors of the links
\hypersetup{colorlinks=true,citecolor=black,menucolor=black,linkcolor=black}

\makeindex
\selectlanguage{english}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\hyphenation{biology}
\selectlanguage{english}
\frontmatter % UPF
\maketitle
\clearpage % UPF

% sets line spacing
\renewcommand{\baselinestretch}{1.0}
\baselineskip=18pt

\chapter*{Glossary} % top level followed by section, subsection
\label{glossary}
\addcontentsline{toc}{chapter}{Glossary}


\begin{center}
\begin{longtable}{ll}

%Here is the caption, the stuff in [] is the table of contents entry
\caption{List of abbreviations} \label{gloss} \\

%This is the header for the first page of the table...
\hline \hline \\[-2ex]
\multicolumn{1}{l}{\textbf{Abbreviation}} &
\multicolumn{1}{l}{\textbf{Description}} \\[0.5ex] \hline
\\[-1.8ex]
\endfirsthead

%This is the header for the remaining page(s) of the table...
\multicolumn{2}{c}{{\tablename} \thetable{} -- Continued} \\[0.5ex]
\hline \hline \\[-2ex]
\multicolumn{1}{l}{\textbf{Abbreviation}} &
\multicolumn{1}{l}{\textbf{Description}} \\[0.5ex] \hline
\\[-1.8ex]
\endhead

%This is the footer for the last page of the table...
\\[-1.8ex] \hline \hline
\endlastfoot

% now the data
AF &  affinity purification\\
AP2 &  apetala 2\\
ARNTL &  aryl hydrocarbon receptor nuclear translocator-like\\
BMAL1 & brain and muscle ARNT-like 1\\
BMP & bone morphogenetic protein\\
BrdU & bromodeoxyuridine\\
C/EBP & CCAAT/enhancer binding protein\\
CLOCK & circadian locomoter output cycles protein kaput\\
ECM & extracellular matrix\\
EGF & epidermal growth factor\\
FGF & fibroblast growth factor\\
GRHL3 & grainyhead-like 3\\
HF & hair follicle\\
HT & high-throughput\\
HPLC & high-pressure liquid chromatogrphy\\
IEX-HPLC & ion exchange high-pressure liquid chromatography\\
IF & interfollicular\\
IFE & interfollicular epidermis\\
\end{longtable}
\end{center}
\cleardoublepage

%%%%% List of Figures
\listoffigures
\addcontentsline{toc}{chapter}{List of Figures}
\cleardoublepage

%%%%% List Of Tables
\listoftables
\addcontentsline{toc}{chapter}{List of Tables}
\cleardoublepage

% Define what levels to number in the TOC
\setcounter{secnumdepth}{3} % organisational level that receives a number
\setcounter{tocdepth}{2}    % print table of contents for level 3vb e

%%%%% Table of Contents UPF
\tableofcontents
\addcontentsline{toc}{chapter}{Contents}
\markboth{Contents}{\textbf{Contents}}
\cleardoublepage


%%%%% no indentation
\setlength{\parindent}{0pt}

\mainmatter
\pagenumbering{arabic}
\clearpage


\cleardoublepage

%%%%% Bibliography
\bibliographystyle{/Users/kianatoufighi/Dropbox/Thesis/ThesisLatex/BibStyles/jmb}
\bibliography{/Users/kianatoufighi/Dropbox/Thesis/ThesisLatex/BibLib/mylibrary}
\end{document} 

Best Answer

With your code the number of the last page of the \listoffigures and the last page of the \listoftables will be shown in the \tableofcontents.

Change the order of the commands to

\cleardoublepage
\addcontentsline{toc}{chapter}{List fo Tables}
\listoftables