How to center cell contents of a LaTeX table whose columns have fixed widths?
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.
Solution 1:
\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"
Solution 2:
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.)