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

I was trying to align the subcaption letter of a subfigure that contains a math environment using temporal boxes, to align it vertically to the biggest one. However, when I do it the subcaption letter moves to the side.

error image

What I'm doing wrong? I want to have the third expression align to the middle (vertically) and the three caption letter to appear align horizontally.


1 & 2 & 3\\
1 & 2 & 3\\
1 & 2 & 3
1 & 2 & 3\\
1 & 2 & 3\\
1 & 2 & 3
\vbox to \ht\tmpbox{%
\caption{My caption.}

share|improve this question
up vote 2 down vote accepted

There are two flaws in your approach:

  1. When you typeset a paragraph in a \vbox, it gets the same width as the current line width

  2. You're not taking into account the depth of \tmpbox

    $\vcenter to \dimexpr\ht\tmpbox+\dp\tmpbox\relax{

When doing experiments with boxes, it helps putting them in a \fbox command, so that we can figure out what TeX is really thinking they are.

Matrices are, by default, centered with respect to the line (more precisely, with respect to the axis of formulas, which runs slightly above the baseline); thus the box containing the first matrix will have some part of it (slightly more than half the total vertical size) above the baseline, which contributes to the height, and some part below the baseline (depth).

Thus, if we want that the last subfigure take exactly the same vertical space as the matrix, we need to make it as large as the sum of height and depth. But we need also to center it with respect to the axis of formulas, which is a job for \vcenter that can be issued only in math mode:

$\vcenter to\dimexpr\ht\tmpbox+\dp\tmpbox\relax{...}$

does what we need.

Now let's look at what happens inside the \vcenter. If we say


then TeX will start a paragraph as soon as it scans the $ and this paragraph will be assigned the current line width, no matter if it is less than one line long. Thus we need to avoid TeX starting a paragraph: it must remain in the mode when it simply stacks boxes one above the other, also known as vertical mode. Therefore we say


that will do the job. The horizontal size of the \vcenter box will always be the maximum of the horizontal boxes it contains, in this case precisely the size of the formula.

Look at the package adjustbox to get similar results in a "more LaTeX" way.

Alternatively, and probably this is the simplest way, load the varwidth package and write

share|improve this answer
Thanks that worked. Can you elaborate a little bit more in the explanation about the computation of the \tmpbox dimensions. Also, why do you need the extra \hbox. And also, you have double math mode, why? – adn Jan 4 '12 at 12:28

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.