4
$\begingroup$

Bug introduced in 6.0 and persisting through 11.0.1 or later

Grid ang ItemStyle are new in 6.0


I would expect the following to output the same grids

{Grid[{{1, 2}, {3, 4}}, ItemStyle -> {, , {{1, 1} -> Directive[30]}}, 
  Background -> {, , {{1, 1} -> Red}}, Frame -> All],
 Grid[{{1, 2}, {3, 4}}, 
  ItemStyle -> {, , {{1, 1} -> Directive[Background -> Red, 30]}}, 
  Frame -> All], 
 Grid[{{NumberForm@1, 2}, {3, 4}}, 
  ItemStyle -> {, , {{1, 1} -> Directive[Background -> Red, 30]}}, 
  Frame -> All]}

instead of

enter image description here

Update:

The following should all produce identical grids and in fact they (almost) do - provided you mix and match between different Mathematica versions:

 {Grid[{{1, 2}, {3, 4}},ItemStyle -> {None, None,{{1, 1} -> Directive[30]}},Background -> {, , {{1, 1} -> Red}}, Frame -> All], 
  Grid[{{1, 2}, {3, 4}},ItemStyle -> {{} , {},{{1, 1} -> Directive[Background -> Red, 30]}}, Frame -> All], 
  Grid[{{NumberForm@1, 2}, {3, 4}},ItemStyle -> {Automatic,Automatic, {{1, 1} -> Directive[Background -> Red, 30]}}, Frame -> All],
  Grid[{{Item[1, BaseStyle -> {Background -> Red, FontSize -> 30}],2}, {3, 4}},Frame -> All],
  Grid[{{Item[Style[1, 30], Background -> Red], 2}, {3, 4}},Frame -> All]}

V6:

enter image description here

V7

enter image description here

V8

enter image description here

V9

enter image description here

The "almost" is that the second Grid - perhaps the cleanest implementation - is yet to fire but perhaps in V10 ...? (As a side note, n.b. the alternative padding (None,Automatic,{},,}) to reach the cell specification in the ItemStyle option - maybe one day argument positions might more seamlessly combine with their structure? )

Upshot: There seems to be a bug in combining values for the Background option with other styling within a single Directive but this can be easily overcome by using both specifications as per the first Grid above.

$\endgroup$
7
  • 1
    $\begingroup$ fyi, your code gives syntax error on V9.01 on windows. An improperly formatted directive with head Symbol was encountered $\endgroup$
    – Nasser
    Commented Jan 29, 2014 at 15:38
  • $\begingroup$ no syntax error on V9.0 on OS X. Does Grid[{{1, 2}, {3, 4}}, ItemStyle -> {None, None, {{1, 1} -> Directive[30]}}, Background -> {None,None, {{1, 1} -> Red}}, Frame -> All] go through? $\endgroup$ Commented Jan 29, 2014 at 15:43
  • $\begingroup$ @Nasser Not here ! $\endgroup$ Commented Jan 29, 2014 at 15:46
  • 1
    $\begingroup$ Screen shot. Need to do it with a fresh Mathematica session (restart M itself) !Mathematica graphics Next time, evaluated, the error goes away. Only first time it shows up. $\endgroup$
    – Nasser
    Commented Jan 29, 2014 at 15:50
  • $\begingroup$ Grid[{{1, 2}, {3, 4}}, ItemStyle -> {None, None, {{1, 1} -> Directive[30]}}, Background -> {None,None, {{1, 1} -> Red}}, Frame -> All] is OK. No error. $\endgroup$
    – Nasser
    Commented Jan 29, 2014 at 15:58

1 Answer 1

3
$\begingroup$

The documentation for ItemStyle says

Item style specifications can include all options to Item, as well as options to Style. Directive[opt1, opt2, ...] can be used to specify multiple options.

Therefore, as I see it

Grid[{{1, 2}, {3, 4}}, 
 ItemStyle -> {{}, {}, {{1, 1} -> Directive[30, Background -> Red]}}, 
 Frame -> All]

grid1

should be equivalent to

Grid[{{Item[Style[1, 30], Background -> Red], 2}, {3, 4}}, Frame -> All]

grid2

but it clearly isn't, so this looks like a bug to me.

Update

I reported this to Wolfram Research tech support and receives the following reply:

Thank you for bringing this issue about ItemStyle to our attention.

I simplified the code to

Grid[{{1,2},{3,4}},ItemStyle->Background->Red]

and found similar results. I have sent a note about this to the appropriate members of our development team.

$\endgroup$
2
  • $\begingroup$ When you confirm a bug it is appropriate to add the bugs tag to the question. (Already done now.) $\endgroup$
    – Mr.Wizard
    Commented Feb 1, 2014 at 8:40
  • 2
    $\begingroup$ Bug still present in V10 $\endgroup$ Commented Jul 16, 2014 at 4:07

Your Answer

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

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