19

I would like to know how to include table of contents into a table of contents....

I have an example of how to spoof it into the toc - using \phantomsection - but it seems like when i have a long document the link goes a bit wrong - ie. it links to a couple of pages before.....

\phantomsection
\addcontentsline{toc}{chapter}{Contents}
\tableofcontents

Example:

\documentclass[12pt, a4paper, twoside]{book}
\usepackage[english]{babel}
\usepackage{amsfonts,dsfont}
\usepackage[final]{pdfpages}
\usepackage{hyperref} 

%----------------------------------------------------------------------------------
\begin{document}
\pagenumbering{roman} 
%----------------------------------------------------------------------------------

%----------------------------------------------------------------------------------
\thispagestyle{empty}
\begin{titlepage}
{\Large
\begin{center}
{\bf XXXXXXXXXXXXXXX}
\end{center}
}
\end{titlepage}
%----------------------------------------------------------------------------------

\phantomsection
\addcontentsline{toc}{chapter}{Contents}
\tableofcontents


\phantomsection
\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures

\phantomsection
\addcontentsline{toc}{chapter}{List of Tables}
\listoftables

%----------------------------------------------------------------------------------

\newpage
\setcounter{page}{1}
\pagenumbering{arabic}

\chapter{XXXXX}
\label{chXXXXX}

\section{Introduction}\label{chXXXXX_Intro}
BLAH BLAH BLAH. 

%----------------------------------------------------------------------------------

%--------------------
\setboolean{@twoside}{false}
\end{document}
JPH
  • 557
  • 1
  • 4
  • 13
  • 11
    Instead of using \phantomsection \addcontentsline{toc}{chapter}{Contents} you can load the tocbibind package. – Gonzalo Medina Mar 30 '13 at 21:15
  • 2
    Just out of interest: why does one want to do so? When I'm reading the TOC, I should actually be able to find the TOC without having to look into the TOC… as you see, this is a bit self-referencial. – Benedikt Bauer Mar 30 '13 at 21:29
  • 4
    Fair point. I guess the point is more - not so much to add it to the table of contents instead to the bookmarks in the e version - for easy navigation. It seemed a bit weird when i looked at the bookmarks that it noted the abstract, talks/papers, and then no bookmarks through to the first chapter - missing the TOC, lists of figures, tables etc. Adding it to the table of contents as well is nice - because it makes the bookmarks+TOC the same. (I should note I'm writing my thesis - it has a lot of crap required at the beginning). Anyway - I love self referential stuff - just like this comment. – JPH Mar 30 '13 at 21:42
  • 1
    Looks like your question was some kind of xy problem. The problem that you state in your comment may be solve in this question – Benedikt Bauer Mar 30 '13 at 21:52
  • 1
    Therefore I put a link to an explanation behind it. Here it is again: http://meta.tex.stackexchange.com/questions/2449/what-does-xy-problem-mean – Benedikt Bauer Mar 30 '13 at 22:50
  • 3
    An explicit page break (\newpage, \clearpage, or \cleardoublepage) before \phantomsection is missing to ensure that \phantomsection is at the top of the right page. – Heiko Oberdiek Mar 30 '13 at 22:54
  • @Benedikt Bauer, sorry - didn't see the first link. Perhaps it is strictly an xy problem - in that i wanted a bookmark, and was aiming to get it through the TOC. Although if I'm honest I'm pretty happy to have the solution to x and y - for the reason i mentioned above - so the bookmarks+TOC are the same. – JPH Mar 30 '13 at 23:14

2 Answers2

16

Ok.... Superfast answer\comment from Gonzalo Medina

Instead of using \phantomsection \addcontentsline{toc}{chapter}{Contents} you can load the tocbibind package. – Gonzalo Medina 3 mins ago


Example becomes:

\documentclass[12pt, a4paper, twoside]{book}
\usepackage[english]{babel}
\usepackage{amsfonts,dsfont}
\usepackage[final]{pdfpages}
\usepackage{hyperref}

\usepackage{tocbibind}


%----------------------------------------------------------------------------------
\begin{document}
\pagenumbering{roman}
%----------------------------------------------------------------------------------

%----------------------------------------------------------------------------------
\thispagestyle{empty}
\begin{titlepage}
{\Large
\begin{center}
{\bf XXXXXXXXXXXXXXX}
\end{center}
}
\end{titlepage}
%----------------------------------------------------------------------------------

\tableofcontents
\listoffigures
\listoftables

%----------------------------------------------------------------------------------

\newpage
\setcounter{page}{1}
\pagenumbering{arabic}

\chapter{XXXXX}
\label{chXXXXX}

\section{Introduction}\label{chXXXXX_Intro}
BLAH BLAH BLAH.

%----------------------------------------------------------------------------------

%--------------------
\setboolean{@twoside}{false}
\end{document} 
JPH
  • 557
  • 1
  • 4
  • 13
  • +1 for a solution that didn't as much as make me change my source file but to add an include. –  Apr 22 '18 at 03:44
1

If you are using the KOMA-script class, then the following is recommended over the tocbibind package:

\setuptoc{toc}{totoc}
Mario
  • 105