Message Boards Message Boards

0
|
4465 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Grid with horizontal and vertical backgrounds of different colors

Posted 4 years ago

Hello

I want to define a grid such as the first row has a horizontal background of a color different from the next rows that have vertical backgrounds of alternate colors..

Extrapolating from Mathematica help I nearly managed to get what I want, except the first row that I would like to have a yellow horizontal background. Here is my code:

data = {{"first", 1, a, aa}, {"second", 11, b, bb}, {"third", 111, c, 
   cc}}:           (* the number of data rows may vary *)
Grid[Prepend[data, {"My Data", SpanFromLeft}], 
 Background -> {{{LightBlue, LightRed}}, {1, 1} -> Yellow}, 
 Frame -> All]

What is the correct way to get that first row in a different color from the other two alternating ones?

Thanks

POSTED BY: Jan Potocki
3 Replies
Posted 4 years ago

An alternative

Grid[
    Prepend[data, {"My Data", SpanFromLeft}],
    Background -> {{{LightBlue, LightRed}}, 1 -> Yellow},
    Frame -> All
 ]
POSTED BY: Hans Milton
Posted 4 years ago

Hi Jan,

Grid[Prepend[data, {Item["My Data", Background -> Yellow], SpanFromLeft}], 
 Background -> {{{LightBlue, LightRed}}}, Frame -> All]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 4 years ago

Thanks Rohit. This weekend, I was going to have to figure out how to do this. You just saved me a few minutes to a few hours.

POSTED BY: Mike Besso
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