[Tex/LaTex] Multicolumn centering and text wrap

horizontal alignmentmulticolumn

I'm trying to make a table with some multicolumns that have wrapped text, but I also want them to be center justified. I have managed to get the text to wrap using advice from other questions, but it wont center and I don't know why.

\documentclass{article}

\usepackage{array}
\newcolumntype{D}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}
\begin{table}[htbp]\centering
\begin{tabular}{l c c c c}
& \multicolumn{2}{D{2cm}}{\textbf{Some Big Words}} & \multicolumn{2}{D{2cm}}{\textbf{More Big Words}} \\
rowname & BlahBlah & BlahBlah & BlahBlah & BlahBlah \\
\end{tabular}
\end{table}
\end{document}

Image

Notice how the multicolumns are not located in the center of the two columns they are supposed to span, but are off to the left. How do I center the multicolumns?

Best Answer

Your titles are centred in the specifed width of 2cm, it's possible to make a vertical stack with a tight box that is centred in a c multicolumn by using a nested tabular

enter image description here

\documentclass{article}

\newcommand\hd[2]{\multicolumn{2}{c}{\bfseries\begin{tabular}{@{}c@{}}#2\end{tabular}}}

\usepackage{array}


\begin{document}
\begin{table}[htbp]\centering
\begin{tabular}{l c c c c}
& \hd{2}{Some Big\\Words} & \hd{2}{More Big\\Words} \\
rowname & BlahBlah & BlahBlah & BlahBlah & BlahBlah \\
\end{tabular}
\end{table}
\end{document}
Related Question