10

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?

mcbetz
  • 4,857
  • 1
    The most F asked question of all. \label has to be after (or in) \caption – David Carlisle May 31 '13 at 13:27
  • 1
    @DavidCarlisle I could not find it here, that's why I added it. – mcbetz May 31 '13 at 13:28
  • searching for figure section \label on this site shows lots of duplicates (and lots more that have been closed already as duplicates) – David Carlisle May 31 '13 at 13:29
  • 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 May 31 '13 at 13:30
  • I think it would be better to edit or re-tag the duplicate rather than create a new question. – Paul Stanley May 31 '13 at 13:32
  • @PaulStanley I would be totally fine with that as well. But I really could not find anything on the problem, so I opened a new one. Sorry! – mcbetz May 31 '13 at 13:33
  • @Martin Betz I wasn't being critical: it certainly makes sense to make such a basic point easily "findable"; just trying to explain why I was going to vote to close. – Paul Stanley May 31 '13 at 13:37
  • 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 May 31 '13 at 13:40
  • 1

1 Answers1

16

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}
mcbetz
  • 4,857