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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like the section headings in running text to link to their "line" in the Table of Contents so as to get "two-way" navigation, eg: a user looks in the Table of Contents for a section title, jumps there, reads a couple of lines, clicks on the section title again and gets taken to the section's entry in the Table of Contents once more.

Any ideas? :)

(Somewhat related to this question)

share|improve this question
up vote 12 down vote accepted

Here's another approach, using the titlesec package and the \hypertarget, \hyperlink mechanism from hyperref. A little example showing the necessary settings for \chapter, \section, \subsection and their starred versions:


  {\normalfont\huge\bfseries}{\chaptertitlename\ {\fontfamily{cmr}\selectfont\thechapter}}{20pt}{\hyperlink{chap-\thechapter}{\Huge#1}



\chapter{Numbered test chapter one}

\section{Test section one}

\subsection{test subsection one one}

\subsection{test subsection one two}

\chapter*{Unnumbered test chapter one}

\section*{Unnumbered test section}

\subsection*{Unnumbered test subsection}

share|improve this answer
Your solution indeed does work like a charm :) Still, I'm having problems trying to make it play nicely with the rest of my manuscript. I've chased the error down to the following line \renewcommand{\thechapter}{\texorpdfstring{\fontfamily{cmr}\selectfont\arabic{c‌​hapter}}{\arabic{chapter}}}, which basically gives me titling numbers in the sectionings (see tex.stackexchange.com/questions/31942/…). Should I mark your answer as accepted (it does work)? do you have any ideas how to make both things "compatible"? – mpr Oct 24 '11 at 12:26
@mpr: see my updated answer. I redefined the font family for the chapter counter inside \titleformat, so there's no need to use the problematic \renewcommand\thechapter{...}. – Gonzalo Medina Oct 24 '11 at 17:12
It works like a charm in the MWE, but in my manuscript I get a gazillion warnings along the lines of "destination with the same identifier (num2) has been already used, dupicate ignored"... I even included all of the packages / commands I use in my manuscript into the MWE, it seems to me that it's a matter of page numbering or something... I modified your commands slightly, for example: \hyperlink{subsec-\thechapter-\thesection-\thesubsection}{#1} and hypertarget{subsec-\thechapter-\thesection-\thesubsection}{} – mpr Oct 24 '11 at 18:11
@mpr: then you will have to provide a minimal version of your code. You can edit your original question to add this minimal version. – Gonzalo Medina Oct 24 '11 at 19:01
I'm very sorry for all the back-n-forth! I found that the problem are * chapters / sections / subsections / etc. The MWE you propose fails with a duplicate warning. – mpr Oct 24 '11 at 19:33

This solution sets up \hypertargets in the toc by renewing the \contentsline command. It links back to the toc by setting the section headings as \hyperlinks using the titlesec package. Note that each of the new \hypertarget start with the word 'toc'

You can easily copy this approach for chapters etc.

\usepackage{lipsum} % sample text
\usepackage[explicit]{titlesec} % to change headings

% renew \contentsline for toc to include hypertarget

% renew \section to link to the toc
{{\thesection} \hyperlink{tocsection.\thesection}{#1}}

% renew \subsection to link to the toc
{{\thesection} \hyperlink{tocsubsection.\thesubsection}{#1}}



\section{First section}
\subsection{my sub section}

\section{Second section}


\section{Third section}


Note that if you look at the .toc file for the above example you'll see the following entries

\contentsline {section}{\numberline {1}First section}{2}{section.1}
\contentsline {subsection}{\numberline {1.1}my sub section}{2}{subsection.1.1}
\contentsline {section}{\numberline {2}Second section}{2}{section.2}
\contentsline {section}{\numberline {3}Third section}{3}{section.3}

The \contentsline takes four arguments, the fourth of which will uniquely identify each entry. I used this unique entry combined with the string 'toc' as the \hypertarget{toc#4}{}; it would not work without the additional string 'toc' (or something similar), as it would result in a duplicated identifier which would be ignored.

share|improve this answer

Your Answer


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.