## Vertical alignment of subfigures in LaTeX

(Update: Several people are finding this page through a search engine, which is little surprise since I had a great deal of trouble finding the answer to this problem. However, I've bookended the $\LaTeX$ stuff with some banal life events, so you'll have to scroll down a bit to find the answers to your $\LaTeX$ woes.)

So, the landlord came in today to fix some things.

I tried to give him as much space as possible, since I find it hard to hide how frustrated he can make me. The last time I saw him, he complained about everything: from the hinge on the screen door that had rotten out, to "clothes on the floor" of our bedrooms.

My room had one (1) shirt on the floor. That is a miracle. Though I guess people complained about free manna from heaven as well.

But the other day while I was gone, he came with his wife and they talked to Lisa. I don't know what she said to them, but when he came back today, he didn't have anything negative to say. He fixed the screen door and trimmed the yard while the plumbers were busy working on our leaking taps.

Lisa has a degree in International Relations.

Now, it was probably best that I said little to him, since I didn't want to change his mood. Instead I sat in my room trying to get my figures to look right in $\LaTeX$. They were all printing on separate lines, but I found the subfigure package which allows the creation of, well, subfigures, which can all go on one line or be formatted into whatever kind of tables you would like.

The only problem with this is I was generating the figures with the xymatrix command in the xy-pic package. The captions on the subfigures refused to align vertically, even though all the documentation I could find insisted that this should be the default behavior. I even tried the subfig package, which is supposed to be more advanced in some ways, but got the same behavior. I still don't understand exactly what is going on, but from this newspost, I gather that xypic doesn't set some kind of baseline in a reasonable place, and so you have to fudge it by wrapping the xymatrix in code like this:

\raisebox{\depth}[\totalheight][0pt]{ ... }

Which is frankly quite mysterious to me. But I created a macro to handle it, and indeed, the figures then aligned vertically as I expected them to.

\newcommand{\raisexy}[1]{\raisebox{\depth}[\totalheight][0pt]{\xymatrix{#1}}} 

The only problem then was that many of my diagrams are low-width posets, so their captions
were
being
typeset
like
this,
which is quite annoying. But since all my captions are rather short, using the \widthof command from the calc package I was able to whip something up to ensure that those figures are better spaced:

\newcommand{\widesubfigure}[2][\@empty]{\hfill \subfigure[#1]{ \makebox[\widthof{(m)~#1}]{#2}} \hfillmbox{} }

This sets the width of the figure to be at least the width of the caption, and automatically adds some whitespace to the sides to ensure even horizontal spacing on the page.

So, now all my figures are arranged nicely, and I just have to fix their content.

The landlord and plumbers are coming back tomorrow to fix the leaking tub. Calvin estimates that the tub leaks 144 liters (36 gallons) of water everyday, costing roughly \$5.00 per month.

Really, though, it isn't right to waste water, no matter how cheap it is.

### 3 Responses to “Vertical alignment of subfigures in LaTeX”

1. Calvin Says:

HEY KEVN HAVE U THOUGHT ABOUT USING MS-WORKS? ITS GRATE!

Also 5 bux a mo. isn't nuffin' to sneeze at! Consider that is probably like one bath every two days, minus heat, well, one half bathtub of cold water per day! Think about how luxurious that would be! ACHOO!

2. Benjamin Keil Says:

This entry saved me a lot of stress. It's the fourth google hit for "xymatrix baseline", but it's the first hit that looks like it's written in Human. As I happen to be a Human speaker, I clicked on it first, and it solved all my problems. Also, I needed to center my matrices vertically to wrap them in ()s, so the following worked well for me:

\left(\raisebox{.5\depth}{\xymatrix{blah blah}}\right)

Thanks for posting this,
Ben.

3. Kevin Says:

Ben,
Thanks for your feedback; that's why I posted it!