# Using a table to format a grid

Ok, I can't wrap my head around this because I don't know Mathematica well enough yet, so I'm asking for help, at least a direction to explore in. I have a Grid: positionsDisp = Grid [{ {1, 4, 7, 10, 13}, {2, 5, 8, 11, 14}, {3, 6, 9, 12, 15} }];

And I have a list of lists, each 5 numbers, one for each column of the positionsDisp grid, such as {1,4,7,10,13}, or in aggregate: {{1, 4, 7, 10, 13}, {1, 4, 7, 10, 14}, {1, 4, 7, 11, 13}, {1, 4, 7, 11, 14}, {1, 4, 7, 11, 15}, ...}

Finally, I have a grid of positionsDisp grids: Grid[Table[reelPositionsDisp, {9}, {11}], Frame -> All]

Now, here is the issue: I want to highlight the positions in the final grid according to the quintuples in my list of lists, so that for the first element of the list, the grid would be highlighted or framed at positions 1, 4, 7, 10, 13 in the first grid, positions 1,4,7,10,14, etc. The goal is for the final grid to show all paths across the columns traversing only adjacent positions (for example, 1,6,7,12,13 is not a valid path).

I've tried Map to map a function over the final grid, but that requires a table iterator, and I'm not sure what function I would use anyway. I've seen a lot of formatting examples, but they seem to be rather "hardcoded". I thought about addressing each column/row, but that would require table iteration again. What approach is best? Or even better, what is a workable solution? It's purely a cosmetic thing, but my audience is more visual than mathematical.

• I've read your question but am still quite puzzled about what it is you're trying to achieve. Based on my very loose understanding I'd suggest looking at MapIndexed with a levelspec of {2} but without further explanation I can't really say more. Nov 28, 2013 at 14:00

g = {{1, 4, 7, 10, 13}, {2, 5, 8, 11, 14}, {3, 6, 9, 12, 15}};
paths = {{1, 4, 7, 10, 13}, {1, 4, 7, 10, 14}, {1, 4, 7, 11, 13},
{1, 4, 7, 11, 14}, {1, 4, 7, 11, 15}};
Column[
Grid[g, Background -> {Automatic, Automatic,
Flatten@Table[{i, j} -> If[#[[j]] == g[[i, j]], Pink, White],
Evaluate[Sequence @@ ({{i, #[[1]]}, {j, #[[2]]}} &@Dimensions@g)]]},  Frame -> All] & /@ paths]

g = {{1, 4, 7, 10, 13}, {2, 5, 8, 11, 14}, {3, 6, 9, 12, 15}};
paths = {{1, 4, 7, 10, 13}, {1, 4, 7, 10, 14}, {1, 4, 7, 11, 13}, {1,
4, 7, 11, 14}, {1, 4, 7, 11, 15}};

myRules = Thread[# -> (newColor /@ #)] &  /@ paths;
Column[Grid /@ (g /.  myRules /. newColor[x_] :> Item[x, Background -> Pink ] )]

In the line myRules=..., instead of (newColor /@ #), one can use directly (Item[#, Background -> Pink]& /@ #). In this case, it works, but the OutputForm of myRules is not understandable because the Item[] are not displayed. To avoid confusing when looking at myRules, the InputForm should be used.