7

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?

9

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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