Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a simple table as follows:

    \caption{The factors the camera solver depends on to evaluate the rules.}

How is it possible to vertically-center the text of the cells?

share|improve this question
This earlier question might be of help to you. –  morbusg Dec 16 '10 at 12:34
Looking closer at your example, I realize you obviously have the array package loaded. p{...} aligns the content toward the top, m{...} aligns the content toward the center, while b{...} aligns it toward the bottom. –  Jimi Oke Dec 17 '10 at 23:19
@Jimi: the example works even without array. The p specifier is standard. –  Stefan Kottwitz Dec 18 '10 at 15:35
@Stefan: Oh, I didn't know that. Thanks! –  Jimi Oke Dec 18 '10 at 16:18
Question, actually. How in the world would a person who knows nothing about code go about this? I'm drowning in information, here. –  Amy Jan 12 at 23:33
show 1 more comment

3 Answers

up vote 17 down vote accepted

enter image description here






        |A{#1}{1.5}% for figure
        |>{\centering$\displaystyle}A{#2}{1}<{$}% for inline equation
        |>{\correction{-1}\strut\[}A{#3}{1}<{\]\strut}% for displayed equation
        |>{\centering}A{#4}{1.5}% for text

    It is practically a big lie that \LaTeX\ 
    makes you focus on the content without
    bothering about the layout.}

    \int_a^b f(x)\, \textrm{d}x=\frac{b-a}{b+a}&



\x & \x & \multicolumn{2}{A{0.55}{1.5}|}{\x} \tabularnewline\hline
\multicolumn{2}{|A{0.45}{1.5}|}{\x} & \x & \x\tabularnewline\hline 
\x & \multicolumn{2}{A{0.5}{1}|}{\x} & \x\tabularnewline\hline 
share|improve this answer
Your solution is working absolutely fine, but isn't there a simpler solution? Aligning contents vertically feels time like simpler than the proposed solution. –  Promather Dec 16 '10 at 19:42
Thanks, but what about the other solution below? –  Promather Dec 26 '10 at 20:48
@xport: Your edits have nothing to do with Rafid's question. For his question, the widths of the columns just don't matter. I think it's not good to include stuff that's really unrelated. –  Hendrik Vogt Dec 28 '10 at 22:25
add comment

One easy way to this would be to use the array package, specifying your column width with m{...}. For example:

\begin{tabular}{ m{4cm} m{1cm} }
   ... & ... \\

will give you a four centimeter-long column and a one centimeter-long column. In each cell, the contents will be vertically aligned to the center. Note, however, that the cell contents will be horizontally aligned left. If you also want to align all the cell contents toward the center in a horizontal sense, then you could do something like this:

\begin{tabular}{ >{\centering\arraybackslash} m{4cm} >{\centering\arraybackslash} m{4cm} }
   ... & ... \\

The point of \arraybackslash is to return \\ to its original meaning because the \centering command alters this and could possibly give you a noalign error during compilation.

If you have several columns and do not want your source to look cluttered, you could define new columns before your tabular environment, for example:

\newcolumntype{C}{ >{\centering\arraybackslash} m{4cm} }
\newcolumntype{D}{ >{\centering\arraybackslash} m{1cm} }
\begin{tabular}{ C D }
   ... & ... \\

There is a lot of useful information on tables in the wiki LaTeX guide, if you want to explore this further.

share|improve this answer
Are you sure that an image inclusion will be EXATCLY vertically centered using your method above? –  xport Dec 19 '10 at 22:42
@xport: It might be relative to the first and last baselines of the cells, not the exact totalheight. –  Martin Scharrer Jul 10 '11 at 15:53
When using this method, people should be cautious NOT to mix other column types such as p. The height of a row AND vertical-alignment follows that of the cell with the maximum height in that row. It is fine if an m column cell has the maximum height, but otherwise the vertical-align would not work. –  Achimnol Dec 27 '12 at 15:22
add comment

There is a command \vcenter which vertically centers its content in horizontal mode. It can only be used in mathmode.

Here is an example with Plain XeTeX (compile with xetex yourfilename.tex)

{ \offinterlineskip
    &Lorem ipsum dolor sit amet&\XeTeXpicfile "test-pattern.jpg" &
      \TeX&$E=mc^2$&$\displaystyle{a^2-b^2\over c^2}$\cr\trule
    &Etiam quam lacus&\vrule width 4em height 5ex depth 2ex&\eTeX &
      $E\ne mc^2$&{\it \&} cetera\cr\trule}

enter image description here

share|improve this answer
add comment

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.