1

When using See for example figure \ref{fig:example}., it outputs something like See for example figure 2.4.1. when the ref is in section 2.4.1. Why does it not link to the figure? The figure is defined like this:

\begin{figure}[H]
    \label{fig:example}
    \caption{Example figure.}
    \includegraphics[width=\textwidth]{img/example.png}
\end{figure}

The figure itself does get a proper label, e.g. Figure 3: Example figure. but the reference references and links to the chapter it's in, which is completely useless. If I intentionally break the label, for example by using \label{example} without fig:, it puts ?? instead of the section, so it apparently can resolve it.

Luc
  • 214
  • 1
    \label should be placed after \caption, not before, otherwise you pickup the wrong \@currentlabel content (which is defined by the last \refstepcounter usage –  Mar 01 '17 at 15:43

1 Answers1

1

Move the \label command after the \caption command, or even better, inside it.

\caption{Example figure.\label{fig:example}}

or

\caption{Example figure.}\label{fig:example}
gernot
  • 49,614
  • Thanks! I saw the other question, of which this question is marked as a duplicate, but it has a lot more code and for some reason (maybe because I'm not native English?) I mixed up caption and section and thought it was a different issue. This took me way too long but your answer helped me fix it in 5 seconds. Thanks for the concise answer :) – Luc Mar 01 '17 at 19:08