# Spanning horizontally and vertically in Grid

I'm trying to make a Grid that has one cell that spans horizontally and one that spans vertically, like so (generated manually with Graphics):

But when I try to do this with Grid, the right-most vertical cell doesn't span both rows:

Grid[{
{ Style["1", FontSize->30], SpanFromLeft, Style["4\n4", FontSize->30] },
{ Style["2", FontSize->30], Style["3", FontSize->30], SpanFromAbove }
}, Frame->All, Spacings->{3,3} ]


Since I have the frame active, I know the right-most cell does in fact span both rows, as we see if we remove SpanFromAbove:

Grid[{
{ Style["1", FontSize->30], SpanFromLeft, Style["4\n4", FontSize->30] },
{ Style["2", FontSize->30], Style["3", FontSize->30] }
}, Frame->All, Spacings->{3,3} ]


Is it not possible to combine vertical and horizontal spans in a grid? Is there a better function, like some combination of Column and Row? Thx

• I'm not sure what do you mean, is the height of the first item the problem? Because except that size issue everything seems ok, with Alignment -> {Center, Center} you can see that the item with 4s is streched. Or did I miss the point? Grid[{{Style["1", FontSize -> 30], SpanFromLeft, Style["4\n4", FontSize -> 30]}, {Style["2", FontSize -> 30], Style["3", FontSize -> 30], SpanFromAbove}}, Frame -> All, Spacings -> {3, 3}, Alignment -> {Center, Center}] – Kuba Jul 23 '18 at 15:54
• Even with the alignment, the content of the right-most box never stretches to the second row. Here's the same thing with four "4"s: Grid[{{Style["1", FontSize -> 30], SpanFromLeft, Style["4\n4\n4\n4\n", FontSize -> 30]}, {Style["2", FontSize -> 30], Style["3", FontSize -> 30], SpanFromAbove}}, Frame -> All, Spacings -> {3, 3}, Alignment -> {Center, Center}] – Chris Wilson Jul 23 '18 at 15:57
• FWIW, this works fine if you replace Grid with GraphicsGrid. Seems like a bug to me. – Chris Wilson Jul 23 '18 at 16:28
• This is what I see - link. But I wouldn't be surprised by another bug of Grid, just want to make sure it is clear. – Kuba Jul 23 '18 at 16:41
• It is a bug, but this description doesn't quite characterize it correctly. The problem isn't that a vertical spanning member can't properly span. Changing Alignment shows this. @ChrisWilson misses seeing this in part because of an extra newline at the end...try wrapping Framed around the Style or using Bottom alignment. What it cannot do is to calculate the required height of the first row correctly. It apportions to the first row enough pixels to hold everything, although it could have subtracted the number of vertical pixels in the second row. – John Fultz Jul 25 '18 at 1:38

I encountered a similar problem, and I found this idea that uses Grid inside Grid.

Grid[{
{Grid[{
{Style["1", FontSize -> 30], SpanFromLeft},
{Style["2", FontSize -> 30], Style["3", FontSize -> 30]}
}, Frame -> All, Spacings -> {3, 3}],
Grid[{
{Style["4", FontSize -> 30]},
{Style["4", FontSize -> 30]}
}, Frame -> True, Spacings -> {3, 2.99}]}
}, Spacings -> -0.1]


I played with the Spacings a bit, to make the graph aligned, and here is the result.

• Brilliant! (Though I wish it wasn't necessary...) – Chris Wilson Jul 25 '18 at 23:04