2

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.

5
  • Could you show the expected HTML behaviour via an image (using some more meaningful content)?
    – Werner
    Commented Dec 13, 2016 at 5:32
  • yes, this is expected behavior. the number rows in multirow cel had to be equal or less than number lines in other columns. you can solve your problem on the way that cells in second row make higher.
    – Zarko
    Commented Dec 13, 2016 at 5:52
  • @Werner The text "AB BC CD EF" should fit into a single cell stretching the height of the table and automatically distributing the extra height between the cells in the second column Commented Dec 13, 2016 at 5:55
  • @Zarko so there's no way to automate it? There's a lot of paragraph text, so measuring the height to be added by trial and error is a real pain Commented Dec 13, 2016 at 5:57
  • I'm afraid, that you need reconsider the table construction. Anyway, using multirow you need always to count number of lines, there for some additional effort to add missing space in other columns should not be a big deal :). I believe, that this will make you a lot of pain ...
    – Zarko
    Commented Dec 13, 2016 at 6:06

3 Answers 3

1

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

7
  • I still need to count lines if not measure them. Oh well. Guess that's not an area where one would expect LaTeX to shine. Commented Dec 18, 2016 at 15:51
  • So can you give some specification what is going into the columns A and B? Is A some text that has to be wrapped? Or is it a number of lines. And similarly, column B: Is it always a number of lines of the form "X, then Y" separated by horizontal lines? Commented Dec 18, 2016 at 16:03
  • And the next question. If the left column is too tall, which of the three above do you prefer? Commented Dec 18, 2016 at 16:06
  • Both columns contain paragraph text. Column A is a description of something called "educational outcome", and column B is how that thing is to be be manifested (or tested). Don't tell me it's silly, I know. I need to produce a LOT of that. The first version looks best, I think, but actually any of the three will do. Commented Dec 18, 2016 at 17:16
  • 1
    If they contain paragraph text, why don't you use p{} columns? And how do the horizontal lines in column B come along? That looks more like an inner tabular to me than paragraph text. Commented Dec 18, 2016 at 17:36
2

Assumed, that you have recent version of package multirow and considering my comment above,:

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

gives:

enter image description here

2

A simple solution with makecell: it allows to have line breaks in cells, and defines a \Gape command to change height and depth of cells:

\documentclass{article}
\usepackage{multirow,longtable, makecell}

\begin{document}

\renewcommand\cellalign{lc}
\begin{longtable}{|p{20mm}|m{20mm}|}
  \hline
  A & B                     \\
  \hline
  \multirowcell{2}[0.9ex]{AB\\ BC \\ CD \\ EF}
    & \Gape[2ex]{X, then Y} \\
  \cline{2-2}
    & \Gape[2ex]{Y, then Z} \\
  \hline
\end{longtable}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .