3
$\begingroup$

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:

Grids

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?

$\endgroup$

1 Answer 1

2
$\begingroup$

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}

enter image description here

and with code: {4, "xxx", "", plot, SpanFromLeft}

enter image description here

$\endgroup$
2
  • 3
    $\begingroup$ I've still missed something here. Why should the grid cell with the plot in it get affected by this difference. Particularly as the grid cells below the plot SpanFromAbove? Maybe I've missed something simple (not the first time). $\endgroup$
    – Jagra
    Dec 3, 2012 at 22:09
  • 1
    $\begingroup$ @Jagra - There's nothing about it in the documentation. It's just the way it works, as far as I can see. Perhaps someone will add further detail. If you want full control I'd recommend using Graphics and Inset. $\endgroup$ Dec 3, 2012 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.