I need to set up a rather complicated Grid[]
and I've run into a curious problem. I've reduced it to a simple example. See the following 2 sets of code and their output:
plot = Plot[Sin[x], {x, 0, 6 Pi}, ImageSize -> 175];
Grid[
{
{1, 2, 3, 4, 5},
{2, "x", "x", "A long title... ", 70000},
{3, "xx", "xx", "", ""},
{4, "xxx", SpanFromLeft, plot, SpanFromLeft},
{5, "xxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{6, "xxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{7, "xxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{8, "xxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{9, "xxxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{10, "xxxxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth}
} ,
Alignment -> {Left, Top}
]
"-----------------------------"
Grid[
{
{1, 2, 3, 4, 5},
{2, "x", "x", "A long title... ", 70000},
{3, "xx", "xx", "", ""},
{4, "xxx", "", plot, SpanFromLeft},
{5, "xxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{6, "xxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{7, "xxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{8, "xxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{9, "xxxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth},
{10, "xxxxxxxxx", SpanFromLeft, SpanFromAbove, SpanFromBoth}
} ,
Alignment -> {Left, Top}
]
Output:
Both grids have 10 rows x 5 columns. They have identical code excepting for the position at row 4 column 3:
- 1st grid has SpanFromLeft at that position.
- 2nd grid has "" at the same position.
Immediately to the left of row 4 column 3 I have the plot.
Can anyone explain why I get such different alignment in the two grids?
Answer
Add a Frame -> All
option to both plots and you'll see why excluding SpanFromLeft
has such an effect. The SpanFromLeft
is causing the cell height to adapt to the plot on its right.
With code: {4, "xxx", SpanFromLeft, plot, SpanFromLeft}
and with code: {4, "xxx", "", plot, SpanFromLeft}
Comments
Post a Comment