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 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.

share|improve this question
1  
fyi, your code gives syntax error on V9.01 on windows. An improperly formatted directive with head Symbol was encountered –  Nasser Jan 29 at 15:38
    
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? –  Ronald Monson Jan 29 at 15:43
    
@Nasser Not here ! –  belisarius Jan 29 at 15:46
1  
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. –  Nasser Jan 29 at 15:50
    
Grid[{{1, 2}, {3, 4}}, ItemStyle -> {None, None, {{1, 1} -> Directive[30]}}, Background -> {None,None, {{1, 1} -> Red}}, Frame -> All] is OK. No error. –  Nasser Jan 29 at 15:58

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
When you confirm a bug it is appropriate to add the bugs tag to the question. (Already done now.) –  Mr.Wizard Feb 1 at 8:40
1  
Bug still present in V10 –  Mike Honeychurch Jul 16 at 4:07

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.