# Multi-line Multi-row cells

I am trying to create a 4x2 table with two multi-row cells, which join cells (1,2) and (2,2) and (1,3) and (2,3) respectively.

The 1st multi-row cell should contain 2 lines and the second 3 lines:

+---+---+---+---+
| A | B | D | G |
+---+   | E +---+
| H | C | F | I |
+---+---+---+---+


Here is my first attempt:

\begin{tabular}{||c|c|c|c||}\hline\hline
A & \multirow{2}{*}{B \\ C} & \multirow{2}{*}{D \\ E \\ F} & G \\ \cline{1-1}\cline{4-4}
H &   &    & I \\ \hline\hline
\end{tabular}


The error (on the multirow line) I get is

! LaTeX Error: Something's wrong--perhaps a missing \item.


and the newlines (\\) inside multirows are ignored.

I also tried putting tabular inside multirow (as per How to add a forced line break inside a table cell):

\begin{tabular}{||c|c|c|c||}\hline\hline
A & \multirow{2}{*}{\begin{tabular}{c} B \\ C \end{tabular}} &
\multirow{2}{*}{\begin{tabular}{c} D \\ E \\ F \end{tabular}} & G
\\ \cline{1-1}\cline{4-4}
H &   &    & I \\ \hline\hline
\end{tabular}


and there were no errors, but F was placed below the last two horizontal lines (i.e., the two rows in the table cannot accommodate the 3 rows in the 2nd multirow cell):

+---+---+---+---+
| A | B | D | G |
+---+   |   +---+
| H | C | E | I |
+---+---+---+---+
F


The 3rd attempt was to pass an actual width in cm instead of {*} to multirow. This works in my case (because the chunks into which I break the multi-row cells have the same width), but the 3rd line (F) is still below the table - i.e., the table height is not increased to accommodate the multi-row cells.

So, my questions are:

• how can I tell multirow where to break lines?
• how do I tell tabular to make space for the multi-row cells?
• Your initial sentence, regarding how the table shoul be formated is awfully hard to read/understand. Maybe it would be good to either provide a real image or at least some kind of ascii sketch. – inVader Dec 4 '15 at 18:39
• But as far as I understand you want to have two separate rows ind the first and last column, and one row (spanning two lines), another one (spanning three lines) in the second and third coulmn? – inVader Dec 4 '15 at 18:41
• @inVader: yes, and I added the ascii art; it is better now? – sds Dec 4 '15 at 19:10

I propose this solution. I loaded hhline for better intersecting double lines, and stackengine. The spacing required by multirow cells can be obtained with the cellspace package, which defines a minimal vertical padding for cells of columns with a qualifier prefixed by the letter S.

In case you really need line breaks in a \multirow the makecell package defines a\multirowcell command that allows for line breaks:

\documentclass{article}
\usepackage{array}

\usepackage{multirow}
\usepackage{cellspace}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\usepackage{hhline}
\usepackage{stackengine}
\setstackEOL{\\}

\begin{document}

\begin{tabular}{||Sc|c|c|c||}
\hhline{|t:====:t|}
A &
B & \multirow{2}{*} {\setstackgap{L}{2.05ex}\Centerstack{D\\E\\F}}
& G \\ %
\hhline{||-|~|~|-||}
H & C & & I \\
\hhline{|b:====:b|}
\end{tabular}

\end{document}


• To get baselines to align better, you might try \setstackgap{S}{3pt}\renewcommand\arraystretch{1.6} – Steven B. Segletes Dec 4 '15 at 21:33
• Yes, but I don't like to use \arraystretch: as a result, the contents of a cell is no more vertically centred.I think it's better to play with \cellspacetop/bottomlimit. – Bernard Dec 4 '15 at 21:42
• @Steven B. Segletes: by the way, I first tried \Centerstack, instead of these nested \stackunder, but all $3$ letters were superimposed. Did I miss something? – Bernard Dec 4 '15 at 21:45
• The default longstack gap is \baselineskip, which tabular sets to zero . The fix, which I will implement if/when the package is revised, is to \setstackgap{L}{\normalbaselineskip} instead of \setstackgap{L}{\baselineskip}. Of course, the fix can be manually performed by the user, as well. – Steven B. Segletes Dec 4 '15 at 21:59
• Fine! Is the default row spacing in array or matrix the same as\normalbaselineskip? – Bernard Dec 4 '15 at 22:04