# Create bold headings and rows in TableForm if x is prime

In the following table

table = Table[x*n, {x, 0, 20},
{n, 0, 5}];
{{"x=0", "1", "2", "3", "4",
"5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15",
"16", "17", "18", "19", "20"},
{"n=0", "1", "2", "3", "4",
"5"}}]


I want to create two versions:

1. With the headings in bold for each row where x is prime,
2. With the whole row in bold (including its heading) for each row where x is prime.

How do I accomplish these?

I want a computed result rather than simply formatting rows or headers manually, since I may want to change the size of the table later. I'm after a global solution...

• As a starting point: Table[Style[x*n, If[PrimeQ[x], Bold, ## &[]]], {x, 0, 20}, {n, 0, 5}] Mar 27, 2019 at 16:48

First version:

xlabels = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"};
table = Table[x*n, {x, 0, 20}, {n, 0, 5}];
TableForm[table,
TableHeadings -> {Style[#, {Bold,Plain}[[PrimeQ[ToExpression[#]] /. {True -> 1, False -> 2}]]] & /@ xlabels, {"n=0", "1", "2", "3", "4", "5"}}]


Second version:

table2 = Table[Style[x*n, {Bold, Plain}[[PrimeQ[ToExpression[x]] /. {True -> 1, False -> 2}]]], {x, 0, 20}, {n, 0, 5}];
TableForm[table2,
TableHeadings -> {Style[#, {Bold, Plain}[[PrimeQ[ToExpression[#]] /. {True -> 1, False -> 2}]]] & /@ xlabels, {"n=0", "1", "2", "3", "4", "5"}}]