I am trying to reference an algorithm in my thesis, made using the algorithmicx and algorithm packages, but it fails, ending up with the dreaded ?? and the following error:
LaTeX Warning: Reference `alg:somealg' on page 10 undefined on input line 442.
A shortened down version can be seen here:
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\begin{document}
Blahblah, see Alg.~\ref{alg:somealg}.
\begin{algorithm}
\label{alg:somealg}
\caption{This is some algorithm}
\begin{algorithmic}[1]
\State $2 + 2 = 4$
\end{algorithmic}
\end{algorithm}
\end{document}
What am I doing wrong?
\labelafter (or within) the\caption. – Torbjørn T. Jul 27 '15 at 09:19