3

Hey fellow LaTeX users.

Is there any way to make the page numbers in a document hyperrefback to the header of the TOC?

It would be very useful in my document so I quickly could jump back and forth to the ToC.

Khaurum
  • 245
  • 1
    Where on the ToC page would you want to jump to? The header, the first "real" line, the sectional entry closest to the referring page, or something else? – Mico Nov 07 '13 at 08:11
  • edited my post to answer your question. – Khaurum Nov 07 '13 at 08:13

1 Answers1

5

You could add a \label just before \tableofcontents which could be indexed and linked to by hyperref. Here’s a minimal example:

\documentclass{report}

\usepackage{hyperref}

% Set up the header and footer
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[CO]{\thepage}
\renewcommand{\headrulewidth}{0pt}

% Put the link in the header
\fancyhead[RO]{This is a link to the~\hyperref[toc-contents]{\textbf{Table of Contents}}}

% This fills the document with dummy text
\usepackage{blindtext}

\begin{document}

\label{toc-contents}
\tableofcontents

\blinddocument

\end{document}

and the top of a page looks something like:

enter image description here

Clicking the bold text would take you to the table of contents.

Of course, you could use something other than fancyhdr to set up the link in the header if you have a different package that you prefer or are already using.


ETA: I should really have read the question more carefully. If you want the page numbers to link to the table of contents, then you replace the header/footer code above by

% Set up the header and footer
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}

% Put the link in the footer
\fancyfoot[CO]{\hyperref[toc-contents]{\thepage}}
alexwlchan
  • 5,417
  • How do you make the page number appear to the right of the header instead of in the middle of the footer? – Khaurum Nov 07 '13 at 09:44
  • @Khaurum: Use \fancyhead[RO]{\hyperref[toc-contents]{\thepage}} instead of the fancyfoot[…]{…}. – alexwlchan Nov 07 '13 at 09:49
  • @alexwlchan I have my TOC within a couple of \newpage, the links back to TOC actually link back to the first page instead of TOC. What do I need to change? – Erik Vesterlund Sep 05 '17 at 17:46
  • The solution proposed is not correct. It only works here because it puts the TOC as the first page of the document. See https://tex.stackexchange.com/a/600955/161015 as alternative. – Simon Dispa Jun 12 '21 at 13:57