TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

consider the following example:






\REQUIRE $x$ and $y$
\ENSURE $|x + y|$
\STATE $z = x + y$
\RETURN $-z$\label{l1}

cref\{l1\}: \cref{l1}, ref\{l1\}: \ref{l1}

\REQUIRE $x$ and $y$
\ENSURE $|x - y|$
\STATE $z = x - y$
\RETURN $-z$\label{l2}

cref\{l2\}: \cref{l2}, ref\{l2\}: \ref{l2}


This will output (apart from the pseudocode):

cref{l1}: line 3, ref{l1} 3

cref{l2}: line 9, ref{l2} 3

As you will notice, \cref{l2} returns an incorrect line number. Any suggestions on how to fix this?

share|improve this question
up vote 5 down vote accepted

cleveref only claims to support a limited number of packages and algorithmic is not on that list. However, adding \setcounter{ALC@unique}{0} after the beginning of your algorithmic enviroments fixes the problem, i.e., writing

\REQUIRE $x$ and $y$


I suggest you wrap this up in a new environment, so that you do not have to write it each time.

share|improve this answer
Actually, cleveref 0.18.5 claims to support the algorithms package, which ships the algorithmic package. But you are correct - it is currently not supported, but will be fixed with 0.18.6 (in development). For now only algorithmicx is supported. – Karalga Aug 6 '12 at 13:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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