7

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

Community
  • 1
  • 1
iceburn
  • 987
  • 3
  • 13
  • 16

2 Answers2

4

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}
Mies
  • 281
  • 1
  • 2
  • i can't get it to compile like that. i've tried searching for that array package before too because i read about it after searching on google, but i couldn't find its documentation – iceburn Sep 07 '10 at 23:00
  • I'm a dolt. It's \usepackage{array}, not \include{array}. – Mies Sep 07 '10 at 23:07
  • I see what you mean. I'm going to tinker around with it for a bit until LaTeX agrees with what I'm saying. – Mies Sep 07 '10 at 23:09
  • I forgot to add an extra alignment. So the top line should have 1 m{2cm} and 3 m{1ex}. I left out one of the m{1ex} – Mies Sep 07 '10 at 23:13
  • 4
    i compiled it and it doesn't work as intended. the text in the x1/x2/x3 columns aren't centered vertically – iceburn Sep 07 '10 at 23:13
  • THANK YOU! This is by far the simplest solution I've seen, and the only one's that's worked for me. – etotheipi Feb 09 '21 at 18:24
3

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{}

Robert
  • 8,406
  • 9
  • 38
  • 57
  • that's not really centering the text vertically – iceburn Sep 07 '10 at 22:58
  • 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 – Robert Sep 07 '10 at 23:02
  • 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? – iceburn Sep 07 '10 at 23:05
  • visit the wikibook I listed, you will get all you need from there – Robert Sep 07 '10 at 23:08
  • 4
    This might be a better question for tex.stackexchange.com – Crippledsmurf Sep 07 '10 at 23:22
  • 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 Sep 07 '10 at 23:23
  • 1
    well, using b{} instead of m{} did align it vertically but now it isn't horizontally aligned... argh! – iceburn Sep 07 '10 at 23:32
  • then you need booktabs package, here's the documentation: http://tug.ctan.org/macros/latex/contrib/booktabs/booktabs.pdf – Robert Sep 07 '10 at 23:36
  • 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 – iceburn Sep 07 '10 at 23:41