I'm using IEEEtran style for a two column document. I want my table cells to be aligned center both horizontally and vertically. First row has to be multiline with some columns having more lines than rest, but my code does not center align it horizontally.
\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{1}{|p{0.2\columnwidth}|}{\centering {\bfseries a few rows of text}} & \multicolumn{1}{p{0.2\columnwidth}|}{\centering {\bfseries a few rows of text}} & \multicolumn{1}{p{0.2\columnwidth}|}{\centering {\bfseries a few rows of text}} & \multicolumn{1}{p{0.2\columnwidth}|}{\centering {\bfseries a few more more rows of text}}\\
\hline
Three & Four&5&6\\
\hline
\end{tabular}
Which produces this:
that clearly first row is not vertically aligned in center.
Is there an easy fix for this?
Best Answer
There are a number of ways to achieve this. Either use
array
'sm{<len>}
column (instead ofp{<len>}
) which places the anchor at the vertical centre automatically. Or, usemakecell
to stack the content manually (which also provides a default vertical centre alignment: