Message Boards Message Boards

0
|
2597 Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

How to style a Grid with ItemStyle?

Posted 2 years ago

I have one question: "How to combine style definitions within ItemStyle?" and one explanation: "How to define cell regions within ItemStyle".

See the following notebook:

Unfortunately this embedded notebook does not show colors. No idea why. That is why I attach the same notebook to this post.

Attachments:
POSTED BY: Werner Geiger
4 Replies

As far as i know, this is how it works:

  • first come column specs which can be a list of a spec per column, then come rows, then come specific rules for elements
  • Column styles go before row styles, so a row style will not override a column style.
  • specific style rules override column and row specs. Also the last rule spec overrides previous ones.

    Grid[tbl, ItemStyle -> {
    {Directive[{Darker@Yellow}], Green, Directive[{Bold, Red}]},(*list of rules for each columns*)
    Directive[{"Text", Gray}],(*one general spec for all rows*)
    {{4, 4} -> Directive[Blue], {{2, 3}, {2, 4}} -> Directive[{"Text", Purple}], {4, 4} -> Directive[ Bold]}}
    (*specific style rules for elements*)
    ]
    
POSTED BY: Martijn Froeling
Posted 2 years ago

Great explanation, Martijn, great example! Thanks so much.

Hence my little problem (each item as "Text" and column 2 as Red) is solved by:

Grid[tbl, ItemStyle -> {{2 -> Red}, "Text"}]

enter image description here I was not aware of that strong sequence columns, rows, items. In the former example the "Text"-style is specified as the style for each rows. This is rather arbitrary. But I found no way to specify an overall ItemStyle.

To bring it together with some region specifications one would write:

Grid[tbl, 
 ItemStyle -> {{2 -> Red}, 
   "Text", {{{2, 3}, {2, 4}} -> Green, {-1, -1} -> Magenta}}]

enter image description here See attached new notebook version "220519a Styling a Grid with ItemStyle.nb".

Attachments:
POSTED BY: Werner Geiger
Posted 2 years ago

One can use the option BaseStyle for whatever should apply to all items

 Grid[tbl,
    ItemStyle -> {2 -> Red, Automatic, {{{2, 3}, {2, 4}} -> Green, {-1, -1} -> Magenta}},
    BaseStyle -> "Text"
 ]
POSTED BY: Hans Milton
Posted 2 years ago

Yes, of course. I forgot about that.

Thanks

POSTED BY: Werner Geiger
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract