2

I want to create a tabular with fixed column width and centered text. I write it like that:

\begin{table}[ht]
\begin{center}
\begin{tabular}{p{4cm}p{4cm}p{4cm}}
\hline
\multicolumn{3}{c}{\textbf{High resolution model}} \\
\hline
\centering $\alpha_{H,1}$ & \centering $\alpha_{H,2}$ & \centering $\alpha_{H,3}$  \\
 bla & bla & bla \\
\end{tabular}
\end{center}
\end{table}

I use the centering command because when using "p{4cm}p{4cm}p{4cm}" to fix the size of the columns, by default the text is aligned on the left. But when I want to compile I get the following error : "! Extra alignment tab has been changed to \cr." that I do not understand and that I am not able to solve.

Any help would be appreciated :)

2
  • 1
    If you want to horizontally center the contents of all rows in a p type columns, use >{\centering\arraybackslash}p{4cm} if you only want to center the contents of one cell, use \multicolumn{1}{c}{.....} or \makecell from the makecell package.
    – leandriis
    Sep 3, 2019 at 8:16
  • Thnak you leandriis for your suggestion, it works fine !
    – Seb
    Sep 3, 2019 at 8:37

1 Answer 1

3

I would like to suggest that you (a) load the array package and (b) use this package's \newcolumntype directive to create a centered version of the basic p column type:

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

Then, replace

\begin{tabular}{p{4cm}p{4cm}p{4cm}}

with

\begin{tabular}{C{4cm}C{4cm}C{4cm}}

and you're all set.


A full MWE (minimum working example):

\documentclass{article}
\usepackage{array} % for "\newcolumtype" macro
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{table}[ht]
\centering
\begin{tabular}{*{3}{C{4cm}}}
\hline
\multicolumn{3}{c}{\textbf{High resolution model}} \\
\hline
$\alpha_{H,1}$ & $\alpha_{H,2}$ & $\alpha_{H,3}$  \\
bla & bla & bla \\
\hline
\end{tabular}
\end{table}
\end{document} 
1
  • 1
    Thank you Mico for your answer ! It works perfectly fine ! I choose this answer over the one proposed by leandriis because I find it more convenient.
    – Seb
    Sep 3, 2019 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.