[Tex/LaTex] Multirow cell content overflows

longtablemultirowtables

My multirow cell content overflows table height if it is higher than the combined height of spanned rows. Is this normal behaviour?

\documentclass{article}
\usepackage{multirow,longtable}
\begin{document}
\begin{longtable}{|p{20mm}|p{20mm}|}
\hline
A &  B 
\\\hline 
\multirow{2}{20mm}{\parbox{18mm}{AB\linebreak BC \linebreak CD \linebreak EF}}
& X, then Y
\\\cline{2-2} 
 & Y, then Z
\\\hline
\end{longtable}
\end{document}

Height overflow with in a multirow cell

If it is, how do I obtain HTML-table-like behaviour to fit the contents inside? There's actually a lot of paragraph text in all cells except the headers.

Best Answer

Here are a couple of other possibilites, where you don't need to measure. As the left entry is actually 4 "physical" rows tall, although logically it is 2 rows, I specify \multirow{4} for it. Multirow doesn't know about the actual height of rows (that information is not given by TeX), so it counts in terms of the default row height.

The new documentation of the multirow package has a section about this problem with a couple of solutions.

\documentclass{article}
\usepackage{multirow,longtable}
\begin{document}
\begin{longtable}{|p{20mm}|p{20mm}|}
\hline
A &  B
\\\hline
\multirow{4}{=}{AB\newline BC \newline CD \newline EF}
    &   X, then Y   \\
    &  \\ \cline{2-2}
    &  Y, then Z \\
    &  \\
\hline
\end{longtable}

\begin{longtable}{|p{20mm}|p{20mm}|}
\hline
A &  B
\\\hline
\multirow{4}{=}{AB\newline BC \newline CD \newline EF}
    &   X, then Y   \\ \cline{2-2}
    &  Y, then Z \\
    &  \\
    &  \\
\hline
\end{longtable}

\begin{longtable}{|p{20mm}|p{20mm}|}
\hline
A &  B
\\\hline
\multirow{4}{=}{AB\newline BC \newline CD \newline EF}
    &   \multirow{2}{=}{X, then Y}   \\
    &  \\ \cline{2-2}
    &  \multirow{2}{=}{Y, then Z} \\
    &  \\
\hline
\end{longtable}

\end{document}

enter image description here

Related Question