## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ how to nicely wrap and center text in table cell?

Information and discussion about graphics, figures & tables in LaTeX documents.
crobar
Posts: 12
Joined: Mon Nov 16, 2009 4:41 pm

### how to nicely wrap and center text in table cell?

Hello,

Can anyone tell me how to horizontally center the wrapped text in the second header cell of the table in the following example without screwing up the row height or otherwise making it look ugly? I just can't figure it out. In general, is it possible wrap text in one table cell, center it vertically and horizontally in the cell, and also have text in the other cells of the same row vertically centred as well?

\documentclass{article} \usepackage{booktabs} \begin{document} \begin{table}		\begin{tabular}{c c p{6cm}} \toprule 			\multicolumn{1}{c}{Name} 			& \multicolumn{1}{p{2.3cm}}{Variable Form In Code} 			& \multicolumn{1}{c}{Meaning} \\ 			\midrule			x	&	\verb|x|	&	Thickness of the back iron on part 1 \\		  x	&	\verb|x|	&	Thickness of the magnet on part 1 \\			\bottomrule		\end{tabular}\end{table}  \end{document}

Thanks!

Stefan Kottwitz
Posts: 9572
Joined: Mon Mar 10, 2008 9:44 pm
Hi crobar,

you could use m-columns with the array package and \centering in cells, like:
\documentclass{article} \usepackage{array}\usepackage{booktabs} \begin{document} \begin{table}       \begin{tabular}{c c p{6cm}} \toprule          \multicolumn{1}{m{2cm}}{\centering Name}          & \multicolumn{1}{m{2.3cm}}{\centering Variable Form In Code}          & \multicolumn{1}{m{6cm}}{\centering Meaning} \\          \midrule          x   &   \verb|x|   &   Thickness of the back iron on part 1 \\         x   &   \verb|x|   &   Thickness of the magnet on part 1 \\          \bottomrule       \end{tabular}\end{table} \end{document}

Stefan