Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I thought that someone must have asked this, but my searches didn't find it.

I am looking to refer back to the table of contents from places in my document. How can I do this?

share|improve this question

5 Answers 5

up vote 5 down vote accepted

A further improved version that will put two links in every page and links point to the TOC.

\documentclass{article}
\usepackage{blindtext}
\usepackage{eso-pic}
\usepackage{hyperref}
\usepackage{ifthen}
\newboolean{linktoc}
\setboolean{linktoc}{true}  %%% uncomment to show answers properly
%\setboolean{linktoc}{false}  %%% comment to show answers properly

\newcommand\AtPageUpperRight[1]{\AtPageUpperLeft{%
 \put(\LenToUnit{\paperwidth},\LenToUnit{-0.3\paperheight}){#1}%
 }}%
\newcommand\AtPageLowerRight[1]{\AtPageLowerLeft{%
 \put(\LenToUnit{\paperwidth},\LenToUnit{0.3\paperheight}){#1}%
 }}%

\ifthenelse{\boolean{linktoc}}%
{%
\AddToShipoutPictureBG{%
   \AtPageUpperRight{\put(-70,0){\hyperref[toc]{Go to TOC}}}
   \AtPageLowerRight{\put(-70,0){\hyperref[toc]{Go to TOC}}}
    }%
}%
{}%


\begin{document}
  \tableofcontents\label{toc}
  \Blinddocument
\end{document}

enter image description here

If you don't want to display the links (you will in the final document), you can disable them by switching the boolean:

%\setboolean{linktoc}{true}  %%% comment to hide links 
\setboolean{linktoc}{false}  %%% uncomment to hide links

You get

enter image description here

share|improve this answer

Since you are using hyperref you can simply add a \label to the \tableofcontents command and then refer to it with \hyperref.

MWE:

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\tableofcontents\label{toc}

\clearpage

\section{A section}

Here is a link to the \hyperref[toc]{Table of Contents}.

\end{document} 

enter image description here

share|improve this answer
    
I upvoted but realize now after having read Heiko's answer that \pageref does not work correctly if the table of contents extend on more than one page... –  jfbu Mar 7 at 16:22
    
@jfbu In fact I didn't use \pageref. \hyperref works correctly in any case. –  karlkoeller Mar 7 at 16:38
    
I did notice you did not use \pageref! I was dissuaded from posting an answer when I saw yours, as I thought it nailed it, but then realized about the \pageref issue. The OP was not specific and \pageref is mentioned in the other answers. –  jfbu Mar 7 at 16:44

Assuming you want a page reference, and you are using a standard class, I would do the following:

\documentclass{article}
\let\oldcontentsname\contentsname
\renewcommand{\contentsname}{\oldcontentsname\label{contents}}
\begin{document}

\tableofcontents

\clearpage

\section{Section 1}

Here is some text for section 1. It refers back to the table of contents 
on page \pageref{contents}.

\clearpage

\section{Section 2}

And here is some more text, also referring to the table of contents on
\pageref{contents}.

\end{document}

If \tableofcontents doesn't start a new page, you could just issue the \label immediately before it, but doing it this way makes sure the label ends up in the right place if a new page is started with the title.

share|improve this answer

The normal reference system of LaTeX can be used including packages such as hyperref/nameref, titleref, ...

The tricky part is put \label at the right place. hyperref likes it right after the title, then the anchor of the \label remains the title. Also putting \label at the end of the \tableofcontents has the risk for a wrong page reference, if the table of contents is more than one page long.

The following example uses an indirect, defensive approach. \label is put right at the beginning of the .toc file via \addtocontents. In the first run, the \label goes into the .toc file, then in the next run it is propagated to the .aux file and in the third LaTeX run the reference is available. Therefore three LaTeX runs are needed:

\documentclass{article}

\AtBeginDocument{%
  \addtocontents{toc}{\protect\label{toc}}%
}

\begin{document}
\tableofcontents
\section{Hello World}
See table of contents on page \pageref{toc}.
\end{document}

The .toc file:

\label {toc}
\contentsline {section}{\numberline {1}Hello World}{1}

Result:

Result

Extension, if the table of contents is reused several times

The counter toclabel is defined and used to generate several label names, e.g. toc1, toc2, toc3:

\documentclass{article}

\newcounter{toclabel}
\AtBeginDocument{%
  \addtocontents{toc}{\protect\stepcounter{toclabel}}%
  \addtocontents{toc}{\protect\label{toc\protect\thetoclabel}}%
}

\begin{document}
\section*{First table of contents}
\input{\jobname.toc}
\newpage
\section*{Second table of contents}
\input{\jobname.toc}
\newpage
\tableofcontents
\section{Hello World}
First table of contents on page \pageref{toc1}\\
Second table of contents on page \pageref{toc2}\\
Third table of contents on page \pageref{toc3}
\end{document}

Result with several tables of contents

share|improve this answer
    
Can you please explain what \protect does? in \protect\label{toc} –  Kartik Mar 6 at 14:54
    
    
This will fail if one can typeset multiple times a table of contents from the .toc file, which admittedly is not the case with the standard classes (and excluding toc-devoted packages). –  jfbu Mar 7 at 16:39
    
@jfbu: This is not much of a problem, see the updated answer. –  Heiko Oberdiek Mar 7 at 16:52
    
you fixed it fast ;-)... –  jfbu Mar 7 at 16:54

With etoc this works out of the box, with or without hyperref:

toc ref

\documentclass{article}
\usepackage{hyperref}
\usepackage{etoc}

\begin{document}
\tableofcontents\label{toc}

\clearpage
\newcount\cnta
\loop
\advance\cnta 1
\ifnum\cnta<100
\section{A section}

Here is a link to the \hyperref[toc]{Table of Contents} on page \pageref{toc}.
\repeat
\end{document} 

Note that without etoc the page reference will be wrong (with or without hyperref, the page will be 4 and not the correct 1). Here is what happens then:

toc ref is wrong

share|improve this answer
    
And I've upvoted you because your answer seems to solve all issues. :-) –  karlkoeller Mar 7 at 16:43
    
let's hope it does not create others ... :). [release 1.07k just to be issued fixes compatibility with tocloft] –  jfbu Mar 7 at 16:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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