0
$\begingroup$

In the following table

table = Table[x*n, {x, 0, 20}, {n, 0, 5}]; TableForm[table, TableHeadings -> {{"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...

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

1 Answer 1

2
$\begingroup$

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

enter image description here

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

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.