How to center vertically in a LaTeX table?
April 18, 2007 11:06 AM   Subscribe

How do I center text (or, really, images) up-and-down within a tabular cell in LaTeX?

I have a table, created in LaTeX, using the tabular environment. I would like the contents of the cells to be centered within each cell vertically, as well as horizontally. (That is, if the cell is a box, I want there to be white space above and below the text, if there is some other cell with more text.)

(For the purposes of full disclosure, I use the tabular environment within a figure environment to easily make multi-part figures; the issue is I have a big image and a small image side-by-side, and I'd like the small image to appear centered vertically with the big image, aligned with the baseline of the big image! If you can tell me how I really should be doing this, that would be an acceptable answer too.)
posted by leahwrenn to Computers & Internet (5 answers total)
 
\usepackage{array}
\begin{tabular}{|m{1in}|m{1in}|}
cell 1
&
cell 2
\end{tabular}

will give you a two-column table, each column 1 inch wide, with vertical bars before and after each, and with content centered in each. The 'm' is the magic flag for vertical centering.

I'll have to think more about your big-image/little-image problem.
posted by gleuschk at 11:25 AM on April 18, 2007


Hacky solution to the big-image/little-image problem: nest tables. Put the two images in a table, each at the bottom of its cell, then wrap that in a second one-cell table with its content vertically aligned.
posted by gleuschk at 11:28 AM on April 18, 2007


Response by poster: I'll poke at the array package. The m{--} is close in that it makes the images behave the way I want (basically), but then the columns are no longer centered vertically (that is, where the columns are in relation to each other), although it's doing the up-and-down in the cell great!

So my picture looks like

[ image ] [ image ]
(a) (b)

but I want
[ image ] [ image ]
(a) (b)

(maybe this will work---it's hosed in preview)
(Probably I should just be using the subfigure package, but I haven't figured out how it works.)
posted by leahwrenn at 11:38 AM on April 18, 2007


Gleuschk has it on both counts. You could also pad the small image with a transparent graphic along its top.
posted by Blazecock Pileon at 11:40 AM on April 18, 2007


Response by poster: Hooray! Array, plus looking at this .pdf for making square cells, led to

\newcolumntype{S}{>{\centering\arraybackslash} m{.4\linewidth} }
\begin{tabular}{S S}%{c c}
\includegraphics[]{BeamEx} & \includegraphics[]{BeamRefKaleid}\\
(a) & (b)
\end{tabular}

which is also hacky but worked!
posted by leahwrenn at 11:49 AM on April 18, 2007


« Older center-mounted child carriers for bicycles   |   Mac DVD player that can increase playback speed... Newer »
This thread is closed to new comments.