-1

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]

enter image description here

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}]

enter image description here

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

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

bbgodfrey
  • 61,439
  • 17
  • 89
  • 156
johnny09
  • 395
  • 2
  • 13

1 Answers1

4

Disclaimer:
Taken from documentation

Code:

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

Output:

output

Reference:
Grid

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

e.doroskevic
  • 5,959
  • 1
  • 13
  • 32
  • Thanks for your answer. But how can I present the required output as a matrix with parentheses? – johnny09 Nov 26 '15 at 17:15
  • 1
    @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
  • 2
    @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
  • 1
    maybe {Grid[Table[x, {4}, {7}], Background -> {{Pink}, None}]} // MatrixForm // Rasterize? – kglr Nov 26 '15 at 21:31