I am renaming the "line" label for lines in the algorithmic environment, since I am using the default label for lstlisting environment. As soon as I add define \crefname for it, the counter does not increase.

It's a simple problem, so an example will illustrate it best.



            \State First line
            \State Second line
Refer here to \cref{line:1} and to \cref{line:2}. 
These two work just fine: \cref{line:4} and \cref{line:3}.
            \State Another first line
            \State Another second line

Compiled example

I tried with \newcounter{opC} and \crefalias{opC}{line} to no avail.

Incidentally, \ref returns numbers as it should, as shown for the second algorithm. Also, the hyperref links point to the right location (though hard to check in this MWE), so only the actual label is wrong.


1 Answer 1


After studying the cleveref package documentation further, I stumbled across a warning in section 14.1 Non-bugs. Even though I did not use \label in an optional argument to another command (as the third bullet suggests), it seems that it should be enclosed with curly braces in order to work properly.

Correcting \label[opC]{line:1} into {\label[opC]{line:1}} in the example above fixes the problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .