6
$\begingroup$

Bug introduced in 9 or earlier and persisting through 11.3


I would like to understand why the following code produces such a different result (Mathematica 9, Win7). Is this a bug? Is there a way to avoid this line height problem?

Grid[
 {{"a", "b", "c", "d"},
  {"L1\nL2\nL3", "e", SpanFromLeft, "f"},
  {SpanFromAbove, "g", SpanFromLeft, "h"},
  {SpanFromAbove, "i", SpanFromLeft, "j"},
  {SpanFromAbove, "k", SpanFromLeft, "l"}}, Dividers -> All]

enter image description here

Grid[
 {{"a", "b", "c", "d"},
  {"L1\nL2\nL3", "e", "m", "f"},
  {SpanFromAbove, "g", SpanFromLeft, "h"},
  {SpanFromAbove, "i", SpanFromLeft, "j"},
  {SpanFromAbove, "k", SpanFromLeft, "l"}}, Dividers -> All]

enter image description here

UPDATE:

Maybe I oversimplified my need making the question difficult to understand. Here is a more practical example of the problem:

Grid[
 {{"", SpanFromLeft, "simple\nmodel", "improved\nmodel"},
  {"Test\nSim\nParams", "param1 =", 1, SpanFromLeft},
  {SpanFromAbove, "param2 =", 2, 3},
  {SpanFromAbove, "param3 =", 4, 5},
  {SpanFromAbove, "param4 =", 6, 7}}, Dividers -> All]

enter image description here

$\endgroup$
8
  • $\begingroup$ Is there any particular reason you didn't put "m" in the first one and what is the expected result? $\endgroup$
    – s.s.o
    Aug 25, 2014 at 13:32
  • $\begingroup$ The first one more closely matches the real (much bigger) table that I am working on. $\endgroup$ Aug 25, 2014 at 13:38
  • $\begingroup$ @GustavoDelfino It's not clear what you need: are you saying you have data like the first table but want it to look like the second table? $\endgroup$
    – mfvonh
    Aug 25, 2014 at 13:40
  • $\begingroup$ I need the same row height for all rows in the first table. For some reason, when I merge two columns this becomes difficult. $\endgroup$ Aug 25, 2014 at 13:52
  • 1
    $\begingroup$ This is a very good question, and I tried for several hours to find an answer. SpanFromLeft in the second row should not trigger SpanFromAbove, there is no apologize for such nasty behaviour. In my opinion it's a bug. $\endgroup$
    – hieron
    Aug 25, 2014 at 20:35

1 Answer 1

5
$\begingroup$

I think the problem is that SpanFromLeft match the dimensions of the first cell in the row (which is "Test\nSim\nParams"). the first cell is bigger than the others in the same levels.

you may try some thing like this:

Grid[{
  {"", SpanFromLeft, "simple\nmodel", "improved\nmodel"},
  {"Test   ", "param1 =", 1, SpanFromLeft},
  {"Sim\nParams", "param2 =", 2, 3},
  {SpanFromAbove, "param3 =", 4, 5},
  {SpanFromAbove, "param4 =", 6, 7}
  },
 Frame -> {All, 
   1 -> True, {{{3, 4}, {2, 4}} -> True, {{4, 4}, {2, 4}} -> True}}]

enter image description here

$\endgroup$
4
  • $\begingroup$ Your answer is the closest to the updated question. Why don't you show the output ??? $\endgroup$
    – eldo
    Aug 25, 2014 at 22:51
  • $\begingroup$ @eld, I was so busy. thanks. $\endgroup$ Aug 25, 2014 at 23:28
  • $\begingroup$ (+1) Your assumption that SpanFromLeft match the dimensions of the first cell in the row contradicts the following: Grid[{{"","",SpanFromLeft,"simple\nmodel","improved\nmodel"},{"","Test\nSim\nParams","param1 =",1,SpanFromLeft},{"",SpanFromAbove,"param2 =",2,3},{"",SpanFromAbove,"param3 =",4,5},{"",SpanFromAbove,"param4 =",6,7}},Dividers->All]. Now the first cell in the row contains only "" but the heigh of the row is still the same. $\endgroup$ Aug 26, 2014 at 6:52
  • $\begingroup$ Maybe SpanFromLeft matches the dimensions of the largest cell in the row. $\endgroup$ Aug 26, 2014 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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