12

I want to refer to a figure within a section (say 1.2), using \ref{fig:xyz}

Section:

\section{XYZ}

Figure:

\begin{figure}
    \includegraphics[width=1\linewidth]{xyz.jpg}
    \label{fig:xyz}
    \caption[XYZ]
\end{figure}

When I add \ref{label:001} to my document, it does not link to the figure, but to the section (1.2).

What can I get it right?

9
  • 1
    The most F asked question of all. \label has to be after (or in) \caption Commented May 31, 2013 at 13:27
  • 1
    @DavidCarlisle I could not find it here, that's why I added it.
    – mcbetz
    Commented May 31, 2013 at 13:28
  • 1
    @DavidCarlisle Yes, that is a possible duplicate. However, I could not find it using the keywords that were relevant for me, ref, label and section. Maybe my question is a good addition, maybe not.
    – mcbetz
    Commented May 31, 2013 at 13:30
  • 1
    @PaulStanley Totally understand that! Let's see what the others think. I was just thinking about how I could do it differently next time. Probably have to extend my search and specificly look for possible duplicates...
    – mcbetz
    Commented May 31, 2013 at 13:40
  • 1
    Another really helpful duplicate is: Understanding how references and labels work
    – Alan Munn
    Commented May 31, 2013 at 16:06

1 Answer 1

18

You have to put \label after \caption - and everything will work.

Thus, your figure will now be:
\begin{figure}
    \includegraphics[width=1\linewidth]{xyz.jpg}
    \caption[XYZ]
    \label{fig:xyz}
\end{figure}

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