[Tex/LaTex] Add list of figures, tables, etc on different position in table of contents

positioningtable of contents

I have a LaTeX document with some chapter and a list of figures and tables.
Something like this:

\tableofcontents
\addcontentsline{toc}{chapter}{\listfigurename}
\listoffigures
\addcontentsline{toc}{chapter}{\listtablename}
\listoftables
\chapter{Chapter 1}
\chapter{Chapter 2}
\chapter{Chapter 3}

So the result in the table of contents would be:

List of tables ………………. i
List of figures …………….. ii
Chapter 1 ……………….. 1
Chapter 2 ……………….. 2
Chapter 3 ……………….. 3

But i want to have in the document the lists at the beginning and in the table of contents i want them at the end, like this:

Chapter 1 …………………. 1
Chapter 2 …………………. 2
Chapter 3 …………………. 3
List of tables ……………. i
List of figures ………….. ii

I tried this:

\tableofcontents
\listoftables
\listoffigures
\chapter{section 1}
\chapter{section 2}
\chapter{section 3}
\addcontentsline{toc}{chapter}{\listfigurename}
\addcontentsline{toc}{chapter}{\listtablename}

But then the page number is wrong:

Chapter 1 ……………….. 1
Chapter 2 ……………….. 2
Chapter 3 ……………….. 3
List of tables …………… 4
List of figures …………. 5

Does anyone know a solution, how to change the position of the lists in the toc with the correct page number?

Best Answer

refcount allows you to extract page references in an expandable way. The following method uses the \label-\ref system to set a \label on the first page of the LoF/LoT and then add the entries to the ToC where they are needed, expanding the page number using \getpagerefnumber:

enter image description here

\documentclass{book}

\usepackage{refcount}

\begin{document}

\frontmatter
\tableofcontents

\clearpage
\label{listoffigures}
\listoffigures

\clearpage
\label{listoftables}
\listoftables

\mainmatter
\chapter{First chapter}
\chapter{Second chapter}
\chapter{Third chapter}

% Insert delayed LoF/LoT
\addtocontents{toc}{\protect\contentsline{chapter}{\listfigurename}{\getpagerefnumber{listoffigures}}}
\addtocontents{toc}{\protect\contentsline{chapter}{\listtablename}{\getpagerefnumber{listoftables}}}
\end{document}