# Centered captions containing \vref may not always appear as expected

I've noticed that when centered captions contains \vref to some reference, the captions may sometimes not become entirely centered. I see this especially in my document where there are two figures on the same page, the second referring to the first, and the caption of the second is no longer completely centered.

I've tried to create a minimal example but it's difficult to get this behavior. However, I've managed to come up with the following:

\documentclass[a4paper, 11pt]{article}

\usepackage{varioref}

\begin{document}
\begin{figure}[!h]
\centering
\framebox{1}
\caption{test}
\label{test}
\end{figure}

\begin{figure}[!h]
\centering
\framebox{2}
\caption{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla \vref{test}}
\end{figure}

\begin{figure}[!h]
\centering
\framebox{3}
\caption{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla \ref{test}}
\end{figure}
\end{document}


The behavior I'm looking for will be shown in the caption of the Figure 2. However, when built twice as it is, everything looks okay. But if one does the following

1. Build once
2. Add an additional "bla" to the caption of the second figure, and rebuild.
3. Remove the "bla" that you just added and then rebuild again.

Now the output will be the following:

Even though the captions of Figure 2 and 3 are textually exactly the same, the caption of Figure 2 is no longer centered as it should be. I fixed this problem in my own document by using \ref instead of \vref (the figures are on the same page anyway), but out of curiosity I would like to know what's going on.

-

When LaTeX typesets a caption, it does a check in order to see whether it fills at least one line; if it doesn't, then it centers the caption. One should go into the details of the implementation of \vref, but the most probable cause is that when doing the measurement, LaTeX "sees" a complete reference (to be resolved only later by the varioref macros) and so decides that the caption occupies more than a line of text.
@gablin I really wouldn't go studying the details of varioref. Sorry. :) – egreg Jan 7 '12 at 16:56