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:
What am I doing wrong here???

\labelcommand if before the\caption. You have to put the\labelalways after the\caption. – Phelype Oleinik Feb 14 '18 at 10:42figureenv that provides the number (in contrast to for example a theorem env), it comes from\captionand have to go after caption in order to pick up the number – daleif Feb 14 '18 at 10:44