0

I'm trying to reference two figures, but somehow the tagging mechanisms is not working properly. I have done this thousand of times, and it's driving me crazy. I have come to the following minimal example:

\documentclass[a4paper,12pt]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}

\section{Section name}

Reference to Fig. \ref{fig:1}.

Reference to Fig. \ref{fig:2}.


\begin{figure}
  \label{fig:1}
  \centering
  \rule{10cm}{5cm}
  \caption{xx}
\end{figure}

\begin{figure}
  \label{fig:2}
  \centering
  \rule{10cm}{5cm}
  \caption{xx}
\end{figure}


\end{document}

And the output I get looks like:

enter image description here

What am I doing wrong here???

Pythonist
  • 229
  • 3
    Because the \label command if before the \caption. You have to put the \label always after the \caption. – Phelype Oleinik Feb 14 '18 at 10:42
  • 3
    Additionally, it is not the figure env that provides the number (in contrast to for example a theorem env), it comes from \caption and have to go after caption in order to pick up the number – daleif Feb 14 '18 at 10:44
  • OK I see how it works, as well as the duplicated threat, which I didn't find when posting. Thanks for the fast and accurate hints. – Pythonist Feb 14 '18 at 11:48

0 Answers0