5

I want to reference some parts of my document. At the moment I read that there are several options. When clicking on a cross-reference one should get to the right part of the document.

The first option is to use labels like explained on wikibooks. But I think that won't produce clickable links.

The second option is better in my opinion: the hyperref package, which I am already using. I found an explanation in the manual.

How can I link parts in the easiest way?

I don't want to put for every section a \label I think that could be done automatically. The entries in the table of contents are linked, thus I presume that some labels are already defined. Also the procedure should be resistant to renaming and moving the section through the document. It that possible or do I have to check my document twice after every change?

4
  • As for "automatically" labeling it, could you provide an example of how you would like to reference it then?
    – Psirus
    Commented Jan 10, 2012 at 10:28
  • Well yes no idea yet. I was expecting that not all parts will be possible. I think the automatic lables are chapter.0, chapter.1 etc. I found that out with Acrobat Pro.
    – rekire
    Commented Jan 10, 2012 at 10:37
  • 5
    If you were to reference it by chapter number, then it would not be resistant to moving around. Therefore, when you're writing a section on let's say Fermat's principle, name your label \label{fermat}, not \label{section3}, because you might move it around later. Naming it \label{sec:fermat} is just a "namespace-like" convention to differentiate between section-, figure-, table- and whatnot-references.
    – Psirus
    Commented Jan 10, 2012 at 10:42
  • related question about a command that automatically turns the section name into a label: tex.stackexchange.com/questions/26942/… (difference to this question: label name changes if section name changes)
    – doncherry
    Commented Jan 10, 2012 at 11:31

3 Answers 3

11

Using the labels together with hyperref will produce clickable links, at least it does for me. Here is a short example:

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\tableofcontents

\section{Fermat’s Principle}
    \label{sec:fermat}
    Fermat’s principle states that the path light takes from one point 
    to another is not necessarily the one with the smallest distance,
    but rather the path which can be traversed in the shortest time.
\section{Geometrical Optics}
    Geometrical optics is an approximation for light propagation in 
    cases where the wavelength is very small compared to the
    structures with which the light interacts. Snell’s Law, describing 
    refraction, can be derived from Fermat’s principle 
    (see section~\ref{sec:fermat}).    
\end{document}

enter image description here Naturally, this is resistant to moving and renaming the section, as long as you move the label along with the section and don't rename it.

2
  • I think it would be more obvious what you mean by resistant if you didn't use 'first' and 'second' as lables. Perhaps 'foo' and 'bar'?
    – Canageek
    Commented Jan 11, 2012 at 1:49
  • @Canageek I see what you mean, seemed a bit contradictory. I changed it to a more "real-world" example.
    – Psirus
    Commented Jan 11, 2012 at 7:14
4

You can use the commands \hyperlink{chapter.2}{LinkText} or \hyperlink{section.2.1}{LinkText} (as used for the table of contents of the pdf). With this commands you link absolute(!) to the chapter 2 or section 2.1. If you move your chapter the target for the link doesn't move. I think you should use the label-ref-mechanism for your needs.

0

The hyperref package provides the command \autoref, which is probably the cleanest way to do cross references with hyperref.

You still need to place labels as described in the answer of @Psirus, but instead of referencing them with their type,

section~\ref{sec:fermat}

you can simply do:

\autoref{sec:fermat}

Advantages:

  • Automatic detection of label type (section, subsection, figure, table, ...)
  • The whole label, including text for the type, is clickable

Customization

If you are still unhappy with the labels texts that are generated, you are free to change them like this:

\def\subsectionautorefname{FooSubSection}

If you want a completely different text just once, you can also use the \hyperref command:

\hyperref[sec:fermat]{Fermat's cool stuff}

Related

For completeness sake, there is also the cleverref package, which provides similar commands which seem to be slightly more configurable.

You must log in to answer this question.

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