41

I cannot find out how to break the line inside the multirow in tabular. In my table, a cell should be two rows wide and should have a linebreak to keep the text overlapping the other cells'.

Any suggestions?

Sample of code:

\begin{center}
    \begin{tabular}{|p{1cm}|p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
    \hline
    \multirow{2}{*}{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}
endive1783
  • 827
  • 1
  • 8
  • 18
kokosing
  • 5,251
  • 5
  • 37
  • 50

5 Answers5

42

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}

parbox in latex document

Tombart
  • 30,520
  • 16
  • 123
  • 136
16

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: Broken text in the right width but sadly going out of the table

However if typically your table has more text on the other cells than just "sth1" it will look great: enter image description here

loved.by.Jesus
  • 2,266
  • 28
  • 34
  • 1
    How do i prevent the overflow in the multirow column? – Midiparse Dec 19 '15 at 11:02
  • @Midiparse I am sorry I am not able to give you an answer. One possibility might be to put your text in a box and use this box in the multirow environment [just guessing (!)] – loved.by.Jesus Dec 27 '15 at 12:10
16

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}
Valentin Lorentz
  • 9,556
  • 6
  • 47
  • 69
Steve Tjoa
  • 59,122
  • 18
  • 90
  • 101
  • I cannot just use "l" parameter in tabular command, because the cell was to width, but the "\begin{minipage}{2cm}Long text to break\end{minipage}" helped me out, thank you. – kokosing Oct 21 '10 at 21:18
7

For me it worked to use the build-in command of "multirow" - the {*} is "{width}"

OddballDK
  • 71
  • 1
  • 1
1

Also, using parbox and \\:

\documentclass{article}
\usepackage{multirow}

\begin{document}

\begin{center}
    \begin{tabular}{|p{1cm}|p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
        \hline
        \multirow{2}{*}{\parbox{1cm}{Long\\ text\\ to\\ break}} % NOT 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}

Be anyway careful not to exceed the margins of your cells.

MattAllegro
  • 6,455
  • 5
  • 45
  • 52