How to add a line break in LaTeX multicolumn heading?

178 Views Asked by At

I have the following table in latex which is centered:

\multicolumn{1}{|c|}{\large \cellcolor{bleudefrance}\color{white}\textbf{very long sentence}}

How can I make the column heading "very long sentence" have a line break in between so that the column heading runs on two lines e.g.

Very long
Sentence

will be the column heading?

1

There are 1 best solutions below

0
MattAllegro On

Using the package array, you can set the column type to allow automatic line breaks without splitting the word, as in the following minimal working example:

\documentclass{article}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
\begin{table}
%\centering%\caption{cap}%\label{lab}
\begin{tabular}{l}
\hline
\multicolumn{1}{|C{\textwidth}|}{\large\textbf{%
very long sentence very long sentence very long sentence very long sentence very long sentence very long long sentence%
}}\\
\hline
\end{tabular}
\end{table}
\end{document}

screenshot of output