4

I have a document with multiple sections and a clickable TOC. I belive the TOC to be created by the following command in a package that I use.

\tableofcontents

As I wanted the TOC to be clickable I added

\usepackage{hyperref}

Now, in section 2.3 I want to write

As we saw in section 2.2 ..

where 2.2 is clickable.

In order to refer to section 2.2 should I make a new label or I can use some inner working that made the clickable TOC?

6
  • 1
    Please add a minimal working example: normally using hyperref should add a link.
    – Joseph Wright
    Commented Aug 25, 2013 at 18:02
  • I edited the question to provide more info. The point is that I'd like to use the labels used by hyperref for the clickable TOC, but they were added automatically.
    – Niccolò
    Commented Aug 25, 2013 at 18:22
  • 2
    That's not a minimal working example (MWE): we need a 'full' document starting \documentclass and ending \end{document}.
    – Joseph Wright
    Commented Aug 25, 2013 at 18:24
  • Assuming you have a label \label{sec:2.2} associated with the appropriate section, and use \ref{sec:2.2} it should work with the hyperref package
    – Holene
    Commented Aug 25, 2013 at 19:03
  • @Holene Take care that using a label named sec:2.2 might not be the best choice since if you add a chapter before it won't make any sense to have this label, but I would use the same idea of label and ref (or label and cref from cleveref package) commands to achieve the request.
    – Ludovic C.
    Commented Aug 25, 2013 at 20:26

2 Answers 2

4

You should use label{...}.

Best practice is to prefix the key with something like sec: or section. and not use the section number as key, but an abbreviated version of the headline or content description.

I guess there is some internal referencing system (1) you could hijack, but I wouldn't recommend it. The internal referencing most probably uses the section numbers as keys.(2) So if you add a section in front or shuffle the sections around otherwise you would have to change the references in order to get them right again. Something which you tried to avoid in the first place.


(1) Recently deleted sections still listed in the TOC are clickable, but the link is dead.
So the target has to be present as anchor to be discovered by the client, and was not saved as coordinates.

(2) Two sections with the same headlines impose no problems.

1
  • My question was actually about how to avoid adding label to each section as TOC already pointed to something. Anyway your note (1) and @LaRiFaRi's answer convinced me that it is probably impossible or not a good practice.
    – Niccolò
    Commented Aug 25, 2013 at 21:18
2

If you are just having problems in referencing, see my minimal example! If you do it like this and don't succeed, show us, how you are doing it, in your OP.

% arara: pdflatex
% arara: pdflatex

\documentclass{article}
\usepackage{blindtext}
\usepackage{hyperref}

\begin{document}
\tableofcontents
\section{Section}
\blindtext
\section{Section}
\blindtext
\subsection{subsection}
\blindtext
\subsection{subsection} \label{sec:Section}
\blindtext
\subsection{subsection}
As we saw in \ref{sec:Section}...
\blindtext
\end{document}
1
  • Your MWE is close enough to mine indeed and what you write works fine for me, thanks! However what I was trying to ask was: (since I have a TOC with working links to sections) can I avoid to add labels and use some kind of command like \refSection{labelUsedByTOC} ? That is to avoid adding label to every sections. If Tobias Simon is correct (the labelUsedByTOC is just the section number), his answer combined with your made me understand why what I wanted to do was either impossible or a bad practice.
    – Niccolò
    Commented Aug 25, 2013 at 21:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .