# Is it possible to colour only one column of a matrix? [closed]

I was wondering if it's possible to colour a column or a row in a matrix.

For example is it possible to add colour for one of the rows/columns of the following matrixform code?

MatrixForm[{{n, -1 + n, -2 + n, ⋯, 1}, {2 n, 2 n - 1,
2 n - 2, ⋯, n + 1}, {3 n, 3 n - 1, 3 n - 2, ⋯,
2 n + 1},  {⋮, ⋮, ⋮, ⋱, ⋮}, {n^2, -1 + n^2, -2 + n^2,⋯, HoldForm[(n - 1) n + 1]}}]


I would appreciate any help or suggestion.

EDIT: For example what if we want to colour only one column in the following matrix?

Rasterize@
Style[MatrixForm[{{n, -1 + n, -2 + n, ⋯, 1}, {2 n, 2 n - 1,
2 n - 2, ⋯, n + 1}, {3 n, 3 n - 1, 3 n - 2, ⋯,
2 n + 1},  {⋮, ⋮, ⋮, ⋱, ⋮}, {n^2, -1 + n^2, -2 + n^2,⋯, HoldForm[(n - 1) n + 1]}},
TableAlignments -> {Center, Center}] // TraditionalForm,
Background -> LightBlue, FontFamily -> Times, 30]


EDIT: Thanks to @Kuba, @E.Doroskevic and @Mr. Wizard I managed to get the following matrix:

Grid[Table[{{1, 2, 3, ⋯, 10}, {2, 3, 4, ⋯, 11}, {3, 4, 5, ⋯, 12},
{⋮, ⋮, ⋮, ⋱, ⋮}, {10, 11, 12, ⋯, 20}}], Background ->{{LightBlue},None},
ItemStyle -> {{Red, Blue, Green, Black}}, ItemSize -> {5, 5}]


Also how can I present the above as a matrix with parentheses or square brackets?

I have tried \\MatrixForm but it didn't work.

• You can use MapIndexed[] to apply Style[] to any particular row, column, or entry. – J. M.'s ennui Nov 26 '15 at 14:41
• @J.M. Could you kindly show me a simple example? Thank you. – johnny09 Nov 26 '15 at 14:54
• Why not experiment? I already pointed out the functions you'll need to use; look up how they're used in the docs, and try things out. If you get stuck, edit your question to include what you tried with these, and we'll take it from there. – J. M.'s ennui Nov 26 '15 at 15:10
• Grid has Background option which quite wide documentation. Take a look there. – Kuba Nov 26 '15 at 15:31
• – Yves Klett Nov 26 '15 at 16:31

Disclaimer:
Taken from documentation

Code:

Grid[Table[x, {4}, {7}], Background -> {{Pink}, None}]


Output:

Reference:
Grid

P.S
Most specifically look at the documentation provided for the associated option Background

• Thanks for your answer. But how can I present the required output as a matrix with parentheses? – johnny09 Nov 26 '15 at 17:15
• @johnny09 wrap the code above with { }? Is that what you mean? – e.doroskevic Nov 26 '15 at 17:17
• Not exactly. What I want is to create a matrix. So I need parentheses or square brackets to the left and right of the entries. – johnny09 Nov 26 '15 at 17:23
• @johnny09 I would advise you to refer to the reference left above in my answer. However, based on my comprehension of what you are aiming to achieve, following (simplified) sample should suffice as a demonstration: {Grid[{{x, x, x}, {x, x, x}}, Background -> {{Pink}, None}]} – e.doroskevic Nov 26 '15 at 17:31
• maybe {Grid[Table[x, {4}, {7}], Background -> {{Pink}, None}]} // MatrixForm // Rasterize? – kglr Nov 26 '15 at 21:31