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'd like to link the Table of Contents in the footer of each page.

I can achieve this thanks to this hint like so:

# In the hyperref section of the document preamble
\cfoot{\hyperlink{page.1}{TOC}}

But if I change my document so that it has a title page, and the TOC moves to page two, I'll need to change this. Is there a better way to link to the TOC? Adding a \label{} and then using a ref{} does not seem to work.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

You could use \hypertarget to create an anchor on the toc page, for example at the beginning of the TOC page or turning the TOC heading into an anchor. Here's an example how you could do it:

\documentclass{report}
\usepackage{fancyhdr}
\usepackage{hyperref}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}% removes header line
\fancypagestyle{plain}{% for chapter starting pages
  \fancyhf{}% clears header fields
  \cfoot{\hyperlink{contents}{TOC}}}
\cfoot{\hyperlink{contents}{TOC}}% links the TOC at the center of the page footer
\begin{document}
Title page
\cleardoublepage
\hypertarget{contents}{}
\tableofcontents
\chapter{One}
\chapter{Two}
\end{document}
share|improve this answer
2  
Can you say why I get the "TOC" link only in the foot of the first page? –  Hendrik Vogt Feb 19 '11 at 12:59
1  
@Hendrik: that's a good observation! It's because only the first page has fancy page style, the other pages automatically got plain as they are chapter starting pages. It can be fixed using \fancypagestyle{plain}{...}. I'll add it to my example. –  Stefan Kottwitz Feb 19 '11 at 13:17

There are several ways to do this. One would be to write the page number of the TOC directly into the .aux file as shown below. I'm sure there is a nicer, more higher-interface solution for that, but just right now (1am) I can't get it. The code below assumes that you want to link to the first ToC page and not to the title of it.

\documentclass{book}

\usepackage{hyperref}
\usepackage{fancyhdr}
\pagestyle{fancy}
\def\tocpage{1}% Default value will be set to correct one at \begin{document}
\cfoot{\hyperlink{page.\tocpage}{TOC}}

\begin{document}

Titlepage

\cleardoublepage % Important to get the page number right
\makeatletter
% Write directly to the `.aux` file:
\write\@auxout{\gdef\noexpand\tocpage{\number\value{page}}}%
\makeatother
\tableofcontents

\chapter{test}
\chapter{test}
\chapter{test}
\chapter{test}

\end{document}
share|improve this answer

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.
http://tex.stackexchange.com/questions/11475/add-a-link-to-the-toc
tex.stackexchange.com
crawl=CC-MAIN-2015-27
75009
application/http; msgtype=response
sha1:L7LXRBPW3VZO6VRXLEEG5GM2PZX563JP
<urn:uuid:dbbb019c-eff2-489c-a375-af4b833848d5>
2015-07-04T22:34:39Z
104.16.12.13
sha1:NS66XVOQBQZIJFGJN4LN4N76GNZ4IHU6
<urn:uuid:a6ddde4a-f216-4592-b7a0-587d1b4f29ab>
http://tex.stackexchange.com/questions/11475/add-a-link-to-the-toc
length
response
<urn:uuid:b98264dc-fb81-4a70-8727-06b3e2a81137>
robots: classic
hostname: ip-10-179-60-89.ec2.internal
software: Nutch 1.6 (CC)/CC WarcExport 1.0
isPartOf: CC-MAIN-2015-27
operator: CommonCrawl Admin
description: Wide crawl of the web for June 2015
publisher: CommonCrawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf