How to center cell contents of a LaTeX table whose columns have fixed widths?

reprogrammer picture reprogrammer · Aug 31, 2009 · Viewed 157k times · Source

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.

Answer

Mica picture Mica · Aug 31, 2009

\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"