wernergg
(Werner Geiger)
May 19, 2022, 11:17am
1
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.
220519 Styling a Grid with ItemStyle.nb (28.6 KB)
mfroeling
(Martijn Froeling)
May 19, 2022, 12:33pm
2
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*)
]
wernergg
(Werner Geiger)
May 20, 2022, 8:56am
3
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"}]
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}}]
See attached new notebook version “220519a Styling a Grid with ItemStyle.nb”.
220519a Styling a Grid with ItemStyle.nb (41.3 KB)
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"
]
wernergg
(Werner Geiger)
May 20, 2022, 4:11pm
5
Yes, of course. I forgot about that.
Thanks