# How to show the whole table

I have this code

mat = ( {
{7, 6},
{2, 4}
} );
Print[" Min ",
Grid[{Min /@ mat},
Background -> {Automatic,
Automatic, {{1, 1} -> Red, {1, 2} -> Red}}, ItemSize -> {2, 1},
Frame -> All]]


However it displays only two cells that are the minimum of each row. How can I make the other numbers appear in the table, but only the minimum to be in red.

Like this?

Row@{
"Min ",
Grid[
mat,
Background -> {
Automatic,
Automatic,
Table[
{n, First@Ordering[mat[[n]]]} -> Red,
{n, Length@mat}
]
},
Frame -> All,
ItemSize -> {2, 1}
]
}


We build the list of rules for the red cells by going over each row using Table. The index of the minimal element of each row can be found using Ordering

Here the same thing for the maximum in each column:

Row@{
"Max ",
Grid[
mat,
Background -> {
Automatic,
Automatic,
Table[
{Last@Ordering[mat[[All, n]]], n} -> Green,
{n, Length@mat[[1]]}
]
},
Frame -> All,
ItemSize -> {2, 1}
]
}


A few things changed:

• We iterate over the columns of the matrix now.
• Therefore, Table goes over the length in the second dimension.
• We need to look at the elements per column, so mat[[All,n]] instead of mat[[n]].
• The indices of the position specifications were also flipped
• Since we're looking for the maximum, we take the Last element of the list returned by Ordering.
• Thank you, by finding the maximum in each pillar what should I replace?I think row with column,but I am not sure for the others. Commented Jan 3, 2019 at 18:34
• @M.Alexis I've added a second example Commented Jan 3, 2019 at 18:54

This is one way:

{{7, 6}, {2, 4}} //
ReplaceAll[v_?VectorQ :> (v /. Min[v] -> Item[Min[v], Background -> Red])] //
Legended[Grid[#, Dividers -> All], SwatchLegend[{Red}, {"minimum"}]] &