Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
+1 because you provided a real minimal example. –  lockstep Sep 8 '11 at 20:22
add comment

1 Answer

up vote 7 down vote accepted

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}
share|improve this answer
    
Lol thanks, can't believe I didn't try that before :P –  Eddy Sep 8 '11 at 18:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.