GeneralCentered contents in LaTeX tables

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Bluemilk
Posts: 5
Joined: Sun Jun 08, 2008 3:12 pm

Centered contents in LaTeX tables

Post by Bluemilk »

Hi all,

The headers in my LaTeX tables have quite a bit of text. So I had to use the p command to specify the width of the column. Problem is, in the actual table, the contents of the cell are not centered, that is, I want my \checkmark command to be in the center of that cell. How do I solve this problem?

Code: Select all

\begin{table}
\begin{center}
\begin{tabular}{lp{2cm}p{2cm}p{2cm}p{2cm}p{2cm}p{2cm}}
\toprule
\multirow{3}{*}{\textbf{Weather}} & \multicolumn{3}{c}{Rain in Spain} & \multicolumn{3}{c}{Rain In Italy} \\ \cmidrule(r){2-4} \cmidrule{5-7} &  Information here & Information here & Information here & Information here & Information here & Information here \\ \midrule
HAHA & & \checkmark & & & & \\
\bottomrule
\end{tabular}
\end{center}
 \caption[MAC finalisation classification scheme]{MAC finalisation classification scheme}
\label{MACclasstable}
 \end{table}
Added in some arbitrary data in my code. My actual contents are not so nonsensical. :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Centered contents in LaTeX tables

Post by Stefan Kottwitz »

Hi Bluemilk,

welcome to the LaTeX Community Forum!

You could use >{\centering\arraybackslash} right before the p column:

Code: Select all

\begin{tabular}{lp{2cm}>{\centering\arraybackslash}p{2cm}p{2cm}p{2cm}p{2cm}p{2cm}}
You can find more information in the array documentation.

Stefan
LaTeX.org admin
Bluemilk
Posts: 5
Joined: Sun Jun 08, 2008 3:12 pm

Re: Centered contents in LaTeX tables

Post by Bluemilk »

thanks! that worked like a charm! :)
Post Reply