Wrong number when reference inside algorithm
1,072
If you use a label and a ref, you need to compile your document twice. Otherwise an error may occur.
\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}[tb]
\caption{Algorithm}
\label{alg}
\begin{algorithmic}[1]
\STATE blalblabla \label{cond1}
\STATE blablabla \label{cond2}
\STATE return to step \ref{cond2}.
\end{algorithmic}
\end{algorithm}
\end{document}
Which gives when compilied twice:
Related videos on Youtube
Author by
user96784
Updated on January 27, 2020Comments
-
user96784 almost 4 years
\usepackage{algorithm} \usepackage{algorithmic} \begin{algorithm}[tb] \caption{Algorithm} \label{alg} \begin{algorithmic}[1] \STATE blalblabla \label{cond1} \STATE blablabla \label{cond2} \STATE return to step \ref{cond2}. \end{algorithmic} \end{algorithm}
As you see it gives "return to step 1" (instead of 2)
-
Mensch almost 8 yearsPlease make your code snippet compilable! Welcome to TeX.SE!
-
-
user96784 almost 8 yearsIn a new latex file it works for me, but not in the original one. Any idea why ??
-
Romain Picot almost 8 years@user96784 You may have used the same label twice for example. You can try to remove the aux too
-
user96784 almost 8 yearsNo, also tried to remove aux, still the same problem.
-
Romain Picot almost 8 years@user96784 well, without a proper MWE it will be hard to answer the question then