31

I have an article with the following figure (there are 2 small charts near each other, horizontally):

\begin{figure}[h]
  \centering
  \includegraphics{left-graph}
  \includegraphics{right-graph}
  \caption{My caption}\label{mylabel}
\end{figure}

I reference the figure with:

Figure~\ref{fig:result} shows bla-bla-bla.

The rendered PDF shows ?? instead of the figure number. I tried with the reference occurring both before and after the figure (in the LaTeX source), but it didn't make a difference.

The relevant packages I'm using are below (those removed are for titling).

\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage[letterpaper]{geometry}
\geometry{top=1.0in, bottom=1.0in, left=1.5in, right=1.0in}
\usepackage{flafter} % make sure figures do not appear before their text
\usepackage{sidecap} % use side captions for floats
\usepackage{subfig} % subfloats

I'm not sure what's wrong here, advice is appreciated. I'm using MiKTeX 2.8.

Thank you!

lockstep
  • 250,273
  • 3
    Allowing only [h] is not much. I would add some options resulting in [htp] for instance. See http://texblog.net/help/latex/figure.html for reference. – Stefan Kottwitz Aug 17 '10 at 14:18

4 Answers4

35

Your labels don't match. Change the reference to \ref{mylabel} or the label to label{fig:result}

Lev Bishop
  • 45,462
12

I also had similar issue where pdflatex didn't update the Figure reference. I later found out that it is because of {\caption{.....}}\label{} incorrect usage. The \caption and \label commands have to be together like \caption{.....}\label{}. The caption command and its contents should not be enclosed with braces.

Stefan Pinnow
  • 29,535
raman
  • 193
  • 3
    Thank you for your contribution! I didn't think the order was important so my referencing wasn't working. Now, I've checked so that all of them are in the right order and it worked! – Gunelle Sep 23 '16 at 12:29
  • This answers so many questions. Great comment. – StiggyStardust Mar 01 '23 at 10:19
8

Besides the mistake noted by Lev Bishop (assuming that you just did some incomplete editing for this post, and in reality the labels match), it is possible that you did not run latex enough times. For the labels to work out you need to run it at least twice.

Aniko
  • 540
5

this is how I did at my work ..

\begin{figure}[b!]
\centering
\includegraphics[width=0.3\textwidth]{sampleFig.jpg}
\caption{sampleFig \cite{sample}}
\label{sampleFig}
\end{figure}

and in the paragraph I put like :

\figurename{\ref(sampleFig)}
Laurenz
  • 273
  • 6
    Welcome, do you know about \autoref{sampleFig} from package hyperref? It is much much better than your current way of doing stuff. – Johannes_B Jun 04 '16 at 14:53
  • When I click on the pdf it doesn't jump to the page with the figure. What should I do? – skan Nov 05 '17 at 20:33