# Vertically align first multiline row of table

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?

There are a number of ways to achieve this. Either use array's m{<len>} column (instead of p{<len>}) which places the anchor at the vertical centre automatically. Or, use makecell to stack the content manually (which also provides a default vertical centre alignment:

\documentclass{IEEEtran}

\usepackage{makecell,array}

\begin{document}

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

\bigskip

\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{1}{|m{0.2\columnwidth}|}{\centering\bfseries a few rows of text}
& \multicolumn{1}{m{0.2\columnwidth}|}{\centering\bfseries a few rows of text}
& \multicolumn{1}{m{0.2\columnwidth}|}{\centering\bfseries a few rows of text}
& \multicolumn{1}{m{0.2\columnwidth}|}{\centering\bfseries a few more more rows of text} \\
\hline
Three & Four& 5 & 6 \\
\hline
\end{tabular}

\bigskip

\begin{tabular}{|c|c|c|c|}
\hline
\multicolumn{1}{|p{0.2\columnwidth}|}{\bfseries \makecell{a few rows \\ of text}}
& \multicolumn{1}{p{0.2\columnwidth}|}{\bfseries \makecell{a few rows \\ of text}}
& \multicolumn{1}{p{0.2\columnwidth}|}{\bfseries \makecell{a few rows \\ of text}}
& \multicolumn{1}{p{0.2\columnwidth}|}{\bfseries \makecell{a few more \\ more rows \\ of text}} \\
\hline
Three & Four& 5 & 6 \\
\hline
\end{tabular}

\end{document}


I can not figured out why you put column headers in multicolum with p type of column and than horizontally center content again. Do you like to determine the table width? If no, than see if the following solution gives what you like to have:

\documentclass{IEEEtran}
\usepackage{makecell}

\usepackage{lipsum}% for dummy text

\begin{document}
\lipsum[2]
\begin{table}[htb]
\centering
\caption{my table}
\label{tab:very-important-table}
\setlength\extrarowheight{2pt}
\begin{tabular}{|c|c|c|c|}
\hline
&   \thead{a few rows\\ of text}
&   \thead{a few rows\\ of text}
&   \thead{a few more\\ more rows\\ of text} \\
\hline
Three   &   Four    &   5   &   6   \\
\hline
\end{tabular}
\end{table}
\lipsum
\end{document}


If yes, than the package tabularx can help:

\documentclass{IEEEtran}
\newcolumntype {C}{>{\centering\arraybackslash}X}% <-- defined new column type
\usepackage{lipsum}% for dummy text

\begin{document}
\lipsum[2]
\begin{table}[htb]
\setlength\extrarowheight{2pt}
\centering
\caption{my table}
\label{tab:very-important-table}
\begin{tabularx}{\columnwidth}{|C|C|C|C|}% determined table width
\hline
`