[Tex/LaTex] How to centre merged columns with tabulary

horizontal alignmentmulticolumntabulary

I'm trying to centre the content of the cells but I can't do it in merged cells. It's working properly in normal cells, but isn't working in merged cells.

Does anyone knows how to fix it?

Here is my code

\documentclass{article}

\usepackage{tabulary,booktabs}

\begin{document}

\begin{center}
\begin{tabulary}{\linewidth}{C|C|C|C|C|C|C|}

\toprule

\multicolumn{7}{>{\centering\arraybackslash}m{13cm}}{Lorem ipsum dolor sit amet} \\

\midrule
\midrule

\multicolumn{7}{>{\centering\arraybackslash}m{13cm}}{Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes} \\

\midrule

\multicolumn{7}{>{\centering\arraybackslash}m{13cm}}{Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus.} \\

\midrule

Vivamus Integer tincidunt  & elementum & semper & nisi & Aenean & vulputate & eleifend \\

\midrule

Donec & vitae & sapien & libero Integer tincidunt & venenatis & faucibus & libero \\

\bottomrule

\end{tabulary}
\end{center}

\end{document}

Best Answer

I am not sure I have fully understood your problem but here is a way to make a table with the first row wrapping in a multicolumn. Obviously you will have to adapt the length in the m{} column descriptor to your need.

\documentclass{article}

\usepackage{tabulary,booktabs}

\begin{document}

\begin{tabulary}{\linewidth}{CCCC}
\toprule
\multicolumn{4}{>{\centering\arraybackslash}m{2.65cm}}{Table This is a very long title for my table} \\
\midrule
\midrule
0 & 14 & 18 & 32 \\
\midrule
1 & 47 & 67 & 114 \\
\midrule
5 & 81 & 61 & 142 \\
\bottomrule
\end{tabulary}

\end{document}

This yields this output:

Output1

Note

If you want to automate a little bit the process you can use the tabularx environment instead and define a general length for your table in your preamble.

\documentclass{article}

\usepackage{tabularx,booktabs}

\newlength{\tablelength}
\newlength{\titlelength}
\setlength{\tablelength}{6cm}
\setlength{\titlelength}{\tablelength}
\addtolength{\titlelength}{-1.5em}

\begin{document}

\begin{tabularx}{\tablelength}{>{\centering\arraybackslash}X>{\centering\arraybackslash}X>{\centering\arraybackslash}X>{\centering\arraybackslash}X}
\toprule
\multicolumn{4}{>{\centering\arraybackslash}m{\titlelength}}{Table This is a very long title for my table} \\
\midrule
\midrule
0 & 14 & 18 & 32 \\
\midrule
1 & 47 & 67 & 114 \\
\midrule
5 & 81 & 61 & 142 \\
\bottomrule
\end{tabularx}

\end{document}

It yields this output

Output 2

Related Question