views:

4043

answers:

2

Consider the following piece of LaTeX code:

\begin{tabular}{p{1in}p{1in}} 
A & B\\ 
C & D\\
\end{tabular}

How can I make the contents of each cell aligned in the center of the cell rather than the left? Note that I want to make sure that the widths of my columns are fixed, so I cannot use the "c" position attribute instead of "p{.1in}" to center my cell contents.

+1  A: 

You can use \centering with your parbox to do this.

More info here and here.

(Sorry for the Google cached link; the original one I had doesn't work anymore.)

Matt Ball
+5  A: 

\usepackage{array} in the preamble

then this:

\begin{tabular}{| >{\centering\arraybackslash}m{1in} | >{\centering\arraybackslash}m{1in} |}

note that the "m" for fixed with column is provided by the array package, and will give you vertical centering (if you don't want this just go back to "p"

Mica
Thanks! This was helpful.
kurious