0
$\begingroup$

I have a function that creates a grid with numbers in particular spots. I can't figure out a way to change the background of cells with numbers in them. For example

grid = Grid[table, Frame -> All, Spacings -> {2, 2}, indices]

where indices is a list {{},{},{}} with the indices of the cells that should have a different color.

Anyone have ideas on how to do this if it's possible?

$\endgroup$
2
  • $\begingroup$ Look up Item in the documentation. You need to wrap Item around the content of the cells that should change color, and then change the color as in the documentation. Example data for table with the corresponding indices would make it easier to answer the question. $\endgroup$
    – C. E.
    Commented Feb 4, 2017 at 22:06
  • 1
    $\begingroup$ Duplicate of this? $\endgroup$
    – PlaysDice
    Commented Feb 4, 2017 at 23:33

1 Answer 1

1
$\begingroup$

Based on the Documentation for Grid you can define the background for grid entries located at indices with the format {row,column} (where row=1 is the upper row of the grid !)

grid = Grid[table, 
  Background -> {Automatic, Automatic, 
    Table[i -> Green, {i,indices}]}, Dividers -> {All, All}]

Here we use Green, can be any color

testdata = {{"a", "B", "c"}, {"c", 1, "d"}, {"f", "g", "h"}}
indices = {{1, 1}, {2, 2}};
grid = Grid[testdata, 
  Background -> {Automatic, Automatic, 
    Table[i -> Green, {i, indices}]}, Dividers -> {All, All}]

Output

$\endgroup$

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