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.

Possible Duplicate:
Why does an environment's label have to appear after the caption?

I am using tikz with its externalize library. I create figures with the following coding style:

\begin{figure}
\centering
\begin{tikzpicture}
  code code code..
\end{tikzpicture}
\label{fig:label}
\caption{Blah blah blah text.}
\end{figure}

when I use \ref{fig:label} it does not display the correct number. Another notable and bizarre behavior is that the number is in the format, e.g 5.2.1 and not 5.2; has anyone encountered this?

Also by trying to create a MWE I could not make the thing to even appear. I am not trying to do complex stuff, just to say "in the figure x.x ...". Anyway, here is the not working MWE:

\documentclass[a4paper,10pt]{report}
\usepackage{tikz} %pgf-tikz pakcage
\usepackage{pgfplots}
\usepackage{hyperref}

\hypersetup{
    colorlinks=true,linkcolor=blue,linktocpage,bookmarksopen=true
}

\begin{document}

\begin{figure}
\begin{tikzpicture}

\draw[fill = blue,fill opacity = 0.3](0,2) rectangle (1.5,3.5);
\draw[fill = yellow,fill opacity = 0.3](0.5,2.5) rectangle (1,3);

\draw[->] (0.75,0.75) -- (0.75,2.75);
\end{tikzpicture}
\label{fig:stuff}
\end{figure}

Hello \ref{fig:stuff} world
\end{document}
share|improve this question

marked as duplicate by lockstep, Torbjørn T., Gonzalo Medina, cmhughes, Stephan Lehmke Aug 31 '12 at 21:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Put \label after \caption. –  lockstep Aug 31 '12 at 21:20
    
That's it. I switched positions and it worked like a charm. Thanks a lot. –  msmechanized Aug 31 '12 at 21:36

1 Answer 1

up vote 3 down vote accepted

you should put figure label after caption

share|improve this answer

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