Is it possible to vertically center multiple columns in a table?

41,806

Solution 1

You'll need \usepackage{array} to do this.

From what I can gather, you're looking at the m{} alignment, which wraps a paragraph at the specified point value, and vertically aligns the text to the middle of the field. For example, something like this:

\begin{tabular}{|m{2cm}|m{1ex}|m{1ex}|m{1ex}} \hline
           & x1 & x2 & x3 \\\hline
Long Label & 1  & 0  & 1  \\\hline
Long Label & 0  & 1  & 1  \\\hline
\end{tabular}

Solution 2

Try this:

\begin{tabular}{|m{3.5em}|b{1em}|b{1em}|b{1em}|}
\hline
%% row 1

&x1
&x2
&x3
\\\hline
%% row 2
Long Label
&1
&0
&1
\\\hline
%% row 3
Long Label
&1
&0
&1
\\\hline
\end{tabular}

For more info on table formatting see http://en.wikibooks.org/wiki/LaTeX/Tables

EDIT: changed c to b{}

Share:
41,806

Related videos on Youtube

iceburn
Author by

iceburn

Updated on January 15, 2020

Comments

  • iceburn
    iceburn over 4 years

    I've found an example here but that only centers one column and I can't really adapt it to my needs. What I'd like is something like this:

    alt text

  • iceburn
    iceburn over 13 years
    that's not really centering the text vertically
  • Robert
    Robert over 13 years
    I don't know what that even means - it is centre aligned... if you are referring to wrapping, then you need to set the column size by using m{} instead of c
  • iceburn
    iceburn over 13 years
    you're using the |c| to center the text horizontally, not vertically. look at the image i posted. i want to align the text in multiple columns so that it is centered according to the first one, which takes multiple rows. if you know how to use the m{} command, could you post an example?
  • Robert
    Robert over 13 years
    visit the wikibook I listed, you will get all you need from there
  • iceburn
    iceburn over 13 years
    i compiled it and it doesn't work as intended. the text in the x1/x2/x3 columns aren't centered vertically
  • Crippledsmurf
    Crippledsmurf over 13 years
    This might be a better question for tex.stackexchange.com
  • iceburn
    iceburn over 13 years
    it isn't there. in the example given in the "Spanning in both directions simultaneously" section it only has the same thing as in the question i linked in the op. seems this just isn't possible with latex since i can't find examples with it anywhere
  • iceburn
    iceburn over 13 years
    well, using b{} instead of m{} did align it vertically but now it isn't horizontally aligned... argh!
  • Robert
    Robert over 13 years
    then you need booktabs package, here's the documentation: tug.ctan.org/macros/latex/contrib/booktabs/booktabs.pdf
  • iceburn
    iceburn over 13 years
    none of the examples in the documentation do what i need, and pretty much all of google's results point to it with at most examples taken from the documentation

Related