# How can I vertically center multiple cells in the same line of a table?

For example:

I've only found answers that involve centering only one column, such as this one.

-

why don't you use \centering for the horizontal centering?

\documentclass{article}
\usepackage{array}
\begin{document}

\begin{tabular}{|>{\centering}m{3em}|c|c|c|}
\hline
&x1&x2&x3\\\hline
Long Label&1 &0 &1\\\hline
Long Label&0 &1 &1\\\hline
\end{tabular}
\end{document}

-
Yeah, your solution is much better than mine. Not sure why I didn't think of doing it that way.... –  Lev Bishop Sep 8 '10 at 14:23
Be careful, this solution cannot center image vertically. :-) –  xport Jan 3 '11 at 1:45

It's pretty ugly and I really wouldn't recommend to make this type of table (see the discussion of how to design publication-quality tables in the documentation of booktabs), but if you're sure you want to reproduce exactly your image:

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{|m{3em}|c|c|c|}
\hline
&x1&x2&x3\\\hline
Long Label&1 &0 &1\\\hline
Long Label&0 &1 &1\\\hline
\end{tabular}
\end{document}


Edit: Your question title talks about vertical centering, but since you say you aren't happy with the above centering, perhaps you actually wanted horizontal centering also? You can get it like this:

\documentclass{article}
\usepackage{array}
\newsavebox{\tempbox}
\makeatletter
\newcolumntype{M}[1]{>{\begin{lrbox}{\tempbox}}%
c<{\end{lrbox}\parbox{#1}{%
\everypar{\vrule\@height\ht\@arstrutbox\@width\z@\everypar{}}%
\centering\unhcopy\tempbox\@finalstrut\@arstrutbox}}}
\makeatother
\begin{document}
\begin{tabular}{|M{3em}|c|c|c|}
\hline
&x1&x2&x3\\\hline
Long Label&1 &0 &1\\\hline
Long Label&0 &1 &1\\\hline
\end{tabular}
\end{document}


If that is still not what you wanted, please edit your question to be more clear about what exactly you are trying to reproduce from your figure.

-
The text in the first column isn't centered, so this is still not exactly what I had in mind. Though I've asked elsewhere and that was also the best answer I got. I'm starting to think LaTeX just can't do it, but thanks anyway. –  www Sep 8 '10 at 3:00
Yeah that is it. I'm surprised it's possible and even more that it took all these lines of code to do it. Man, this is really discouraging, if I have to know that much just to get tables to do that. But thanks again! –  www Sep 8 '10 at 6:17