0

this is my first time asking questions on this forum, long time reader however, so please bear with me.

I currently have a document, in book class, for which I have been making use of the hypref package in order to link the table of contents (toc) entries to the corresponding section, I have got it set-up such that I can click the title of the various sections and they take me back to the toc page.

I also have entries for a list of figures (lof), list of tables (lot) and bibliography (bib), and in the toc the links to the corresponding pages work fine to take me to the relevant page, however, I would like to be able to make the titles of the lof,lot and bib be a link to take back to the toc.

I can't find a way to access the title of any of them, I have also tried creating a chapter and placing the \listoffigures in there, and then inserting the chapter and linking the chapter title to the toc, which kind of works, but there are two entries for lof in the toc, and the lof automatically jumps to a new page, so I end up with a chapter with a linked title to the toc, followed by a new page and then the contents as generated by the lof.

I have been trying to find a similar issue online for some time, and have yet turned up nothing useful, and so I made this account to hopefully solve this. If anyone knows of a similar question already having been asked, or knows a way to make this work, I would appreciate any help in this matter.

TLDR: Trying to link lof,lot and bib titles back to the toc

Here is a MWE

\documentclass[11pt,twoside,openany]{book}

\usepackage[nottoc,numbib]{tocbibind} 
\usepackage{hyperref}

\begin{document}

\addtocontents{toc}{\protect\hypertarget{TOC}{}}
{\hypersetup{linkcolor=black} \tableofcontents}

\listoffigures

\chapter[Introduction]{\hyperlink{TOC}{Introduction}}
text here

\end{document}

I found this discussion where they go about a different means of toc linking and back, which I might end up using, however, the lof still doesnt link back to toc, here's a modified MWE

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}
\usepackage{blindtext}
\usepackage{hyperref}
\usepackage[nottoc,numbib]{tocbibind} 

\makeatletter
\patchcmd{\addcontentsline}{{#2}{#3}{\thepage }}%
       {{#2}{#3}{\protect\Hy@raisedlink{\protect\hypertarget{back\@currentHref}{}}{\thepage}} }%
       {\typeout{** patch \string\addcontentsline\space success}}%
       {\typeout{** patch \string\addcontentsline\space failure}}% 
       \AtBeginDocument{\renewcommand{\Sectionformat}[2]%
       {\ifnum #2>\c@secnumdepth {#1}\else\hyperlink{back\@currentHref}{#1}\fi}}
    \patchcmd{\@makechapterhead}{\bfseries #1\par}{\bfseries\hyperlink{back\@currentHref}{#1}\par}%
       {\typeout{** patch \string\@makechapterhead\space success}}%
       {\typeout{** patch \string\@makechapterhead\space failure}}
\makeatother


%\hypersetup{colorlinks=true,linkcolor=black}

\begin{document}
\tableofcontents
\listoffigures
\Blinddocument
\end{document}
2
  • As a long time reader you have probably noticed that questions usually require an example document in order to be answerable. Could you provide such a document, with the correct documentclass, a table of contents, and the LOF etc, with the current code that you use for backreferencing in place? That would provide a starting point for an answer and save people that want to try finding an answer the time of trying to recreate your setup.
    – Marijn
    Feb 5 at 11:53
  • I was aware a MWE is typically used, however, I thought that the question was fairly general, but I have added an example on how I implemented the linking between toc and chapters and back to toc, for which the lof only links from toc but not back to toc
    – TaukDe
    Feb 5 at 12:30
1

This should be for you. Note that I've simplified the code a bit. This way you don't have to enter \hyperlink for each chapter:

\documentclass[11pt,twoside,openany]{book}
\usepackage[nottoc,numbib]{tocbibind} 
\usepackage{etoolbox}

\makeatletter
\patchcmd{\@makechapterhead}{#1}{\hyperlink{TOC}{#1}}{}{}
\patchcmd{\toc@chapter}{\chapter*{#1}}{\chapter*{\hyperlink{TOC}{#1}}}{}{}
\makeatother

\usepackage{hyperref}

\begin{document}
\tableofcontents
 \listoffigures
  \listoftables
  \chapter{Introduction} 
\end{document}
1
  • Thanks a lot Ivan, that worked perfectly as intended.
    – TaukDe
    Feb 7 at 6:26

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.