6

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:

enter image description here

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.

0

1 Answer 1

5

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.

3
  • 1
    Just as a side note: When the document is built twice as it is, the reference is first resolved to "??" and then to "Figure 1", both of which are small enough to make the entire caption fit on one line and thus be centered. However, when I do the modification in Step 2, the reference resolves to "Figure 1 on page 1", which causes the caption line to break. And only then does the caption gets messed up after, in the third build, being resolved to "Figure 1".
    – gablin
    Jan 7, 2012 at 16:51
  • 1
    @gablin I really wouldn't go studying the details of varioref. Sorry. :)
    – egreg
    Jan 7, 2012 at 16:56
  • Well, it was worth a try. =)
    – gablin
    Jan 7, 2012 at 22:16

You must log in to answer this question.

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