2

I know that there is the following post

Reference to the Table of Contents page

but I could not find what I want.

What I want is to add in (almost) every page of my document (class book) a reference to the TOC page as below:

enter image description here

(I don't care for the "jump to Index" link)

All the pages before the TOC would not contain a link. The same holds true for the first page of each chapter and the first page of the table of contents.

As a minimal working code

\documentclass[12pt]{book}
 \usepackage[french]{babel}
 \usepackage[utf8]{inputenc}

 \usepackage[pdftex]{graphicx}

 \usepackage{lipsum}

 \usepackage[Lenny]{fncychap}

\usepackage{pdfpages}
\setlength{\oddsidemargin}{.5cm} \setlength{\evensidemargin}{.5cm}
\setlength{\textwidth}{15cm} \setlength{\textheight}{21.0cm}
\setlength{\topmargin}{0in}
\renewcommand\contentsname{Table des mati\`eres}

\parindent 0ex

%\usepackage{hyperref}

\usepackage[colorlinks=true,
    linkcolor=red,
    urlcolor=blue,
    pdftitle={Dossier de Candidature},
    pdfauthor={Dimitrios S. Anagnostou}]{hyperref}

\usepackage[affil-it]{authblk}

\parindent0pt  \parskip10pt

\begin{document}

\title{DOSSIER DE CANDIDATURE}
\author{Dimitrios Papas\thanks{vbkvbkvbdkvbd}}

\affil{
Université\ldots}

\date{\begin{center}
Docteur en Mécanique
\end{center}}

\maketitle \thispagestyle{empty}

\frontmatter  

\tableofcontents

\chapter*{Avant propos}
\addcontentsline{toc}{chapter}{Avant propos} 
\lipsum

\mainmatter  

\chapter{First}

\section{First section}
\lipsum

\chapter{Second}
\section{First section}
\lipsum

\end{document}
  • Apparently you have forgotten to supply the magnifying glass together with your screen shot? And the starter code as well ;-) – user31729 Mar 6 '17 at 18:37
  • You are right. I apologize. I will put a minimal example and a bigger picture. – Dimitris Mar 6 '17 at 18:37
3

The key is to place a \label at the start of the ToC. To achieve this, we force a new page (\clearpage) and place a hyperref marker \phantomsection. Now we can place a regular \label which we use as a hyperlink in the footer:

\documentclass{book}

\usepackage{fancyhdr,hyperref}
\usepackage{lipsum}

\fancypagestyle{mainmatter-pages}{%
  \fancyhf{}% Clear header/footer
  \renewcommand{\headrulewidth}{0pt}% Remove header rule
  \renewcommand{\footrulewidth}{0pt}% Remove footer rule
  \fancyfoot[L]{\hyperref[ToC-first-page]{Jump to Contents}}
  \fancyfoot[C]{\thepage}
}
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
  \cleardoublepage
  \phantomsection% Place hyperlink marker
  \label{ToC-first-page}% Set \label for hyperlink
  \oldtableofcontents
}
\let\oldmainmatter\mainmatter
\renewcommand{\mainmatter}{%
  \cleardoublepage
  \oldmainmatter
  \pagestyle{mainmatter-pages}%
}
\begin{document}

\frontmatter

\tableofcontents

\mainmatter

\chapter{First chapter}
\lipsum[1-50]
\chapter{Second chapter}
\lipsum[1-50]
\chapter{Third chapter}
\lipsum[1-50]
\chapter{Final chapter}
\lipsum[1-50]

\end{document}

The process is "automated" by replacing the \tableofcontents and \mainmatter macros to insert the appropriate links and settings (leaving the regular document code clean).

The footer can be modified to suit your needs.

  • Thank you very much. But when I run the minimal example with your workaround I get error messages. – Dimitris Mar 6 '17 at 19:34
  • @dimitris: Please see this paste which uses your minimal example with the additions I suggest. – Werner Mar 6 '17 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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