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{}
Related videos on Youtube
Author by
iceburn
Updated on January 15, 2020Comments
-
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:
-
iceburn over 13 yearsthat's not really centering the text vertically
-
Robert over 13 yearsI 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 over 13 yearsyou'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 over 13 yearsvisit the wikibook I listed, you will get all you need from there
-
iceburn over 13 yearsi compiled it and it doesn't work as intended. the text in the x1/x2/x3 columns aren't centered vertically
-
Crippledsmurf over 13 yearsThis might be a better question for tex.stackexchange.com
-
iceburn over 13 yearsit 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 over 13 yearswell, using b{} instead of m{} did align it vertically but now it isn't horizontally aligned... argh!
-
Robert over 13 yearsthen you need booktabs package, here's the documentation: tug.ctan.org/macros/latex/contrib/booktabs/booktabs.pdf
-
iceburn over 13 yearsnone 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