Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 366
reprogrammer Avatar asked Aug 31 '09 14:08

reprogrammer


People also ask

How do I center a cell content in LaTeX?

If you want to horizontally center all contents inside of a p type column, it is easier to use >{\centering\arraybackslash}p{5cm} instead of adding \centering to every single cell.

How do you center an element in a table LaTeX?

When you're using \begin{center} and end{center} the whole environment will be centered. The c in the tabular environment specify that the content inside a cell should be centered.

How do you set a fixed column width?

Select your table. On the Layout tab, in the Cell Size group, click AutoFit. Click Fixed Column Width.


1 Answers

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

like image 195
Mica Avatar answered Sep 19 '22 18:09

Mica