# Having trouble cross-referencing figures

I'm having a bit of trouble trying to reference figures in my latex document. Here is my latex code:

\documentclass[12pt]{article}
\begin{document}

\begin{figure}
Here is a figure
\label{fig:test1}
\caption{Here is a caption}
\end{figure}
Here is some text. See figure~\ref{fig:test1}.

\end{document}


I compile it twice with pdflatex test.tex but in the resulting pdf I get a blank space where there should be a number for the figure reference. For example, instead of "See figure 1." I get "See figure ."

How do I fix this problem?

-
+1 because you provided a real minimal example. –  lockstep Sep 8 '11 at 20:22

You need to place your \label after \caption in order for the referencing to work:

\documentclass[12pt]{article}
\begin{document}

\begin{figure}
Here is a figure
\caption{Here is a caption}
\label{fig:test1}
\end{figure}
Here is some text. See figure~\ref{fig:test1}.

\end{document}

-
Lol thanks, can't believe I didn't try that before :P –  Eddy Sep 8 '11 at 18:21