I defined my own environment for short pseudo-algorithms, and I would like to use the \labelformat command to change the output of \vref. Varioref's documentation says:

"The command takes two arguments: the first is the name of a counter and the second is its representation when referenced. This means that for a successful usage, one has to know the counter name being used for generating the label, though in practice this should not pose a problem. The current counter number is picked up as an argument."

This works for sections, but does not for my own environment.




% own environment for short algorithms

    \textbf{Algorithm \thealgctr: #1}\\%

Reference to section: \vref{ex1}, reference to algorithm: \vref{ex2}.
This is an example.



wrong output

1 Answer 1


The \labelformat command offers a way to change the counter behavior but for that to work the counter needs to exist. As you define the counter later that definition reinstalls the default behavior as neither check if there is already something defined.

So if you move the counter declaration before the \labelformat everything works out fine (well more or less you also need to add a \par into your environment definition as \medskip in LaTeX does not start vertical mode but uses \vspace) but then you get:

enter image description here

  • The solution was so simple that I'm a little embarrased I did not find it myself. I guess it got pretty late that night :) It works now, but I don't get you second part about \medskip - what do you mean, where do I need to add a \par? Commented Nov 9, 2014 at 14:37
  • 1
    @causaprima what do you think happens in "\par Test A \medskip Test B\par" ? where does the \medskip go and how does the result look like? Commented Nov 9, 2014 at 15:24
  • I guess you are referring to the first line in my enviroment definition, that should rather be \par\medskip\noindent%, right? Commented Nov 9, 2014 at 20:47
  • @causaprima yep Commented Nov 9, 2014 at 20:57

You must log in to answer this question.

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