Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
2  
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). –  Jagra Dec 3 '12 at 22:09
1  
@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. –  Chris Degnen Dec 3 '12 at 22:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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