Latex: how to break the line in multirow inside the tabular
p
column and \parbox
also works:
\usepackage{multirow}
\begin{document}
\begin{center}
\begin{tabular}{|p{1.5cm}|l|l|l|l|l|}
\hline
\multirow{2}{*}{\parbox{1.5cm}{Long text to break}}
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3} \\
\cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\
\hline
\hline
\end{tabular}
\end{center}
\end{document}
You could try to minipage
it:
\begin{center}
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\multirow{2}{*}{\begin{minipage}{0.5in}Long text to break\end{minipage}}
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3} \\
\cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\
\hline
\hline
\end{tabular}
\end{center}
However, in your particular case, my suggestion would simply be to loosen the restrictions of the other columns, because there is too much space wasted there. With each p{}
, that forces the other columns to be a certain width, so there is not enough room for the first column.
The following code looked presentable to me when I compiled it:
\begin{center}
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\multirow{2}{*}{Long text to break}
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3} \\
\cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\
\hline
\hline
\end{tabular}
\end{center}
for me the shortest and most practical answer:
use \linewidth
as the length for the {width}
parameter.
\usepackage{multirow}
\begin{document}
\begin{center}
\begin{tabular}{|p{1cm}|p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\hline
\multirow{2}{\linewidth}{Long text to break} % HERE IS A PROBLEM
& Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3}
\\ \cline{2-6}
& sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\ \hline
\hline
\end{tabular}
\end{center}
\end{document}
That's it!
The only possible problem is that in the improbable case that the text in the other cells is really short it may look like that:
However if typically your table has more text on the other cells than just "sth1" it will look great:
For me it worked to use the build-in command of "multirow" - the {*} is "{width}"