First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Presumably this takes place in a browser?

Maybe in Jupyter or in SageCell?

The following works in these contexts.

Making it work in the Sage REPL or in SageTeX would require some changes.

Not sure that fully answers your question, but hopefully it is a step.

A = [[10] * 10, [100] + [0] * 9, [100/9] * 9 + [0]]
A.extend([[20] * 5 + [0] * 5, [51200/1023/2^n for n in range(10)]])
f = lambda x: x if x in ZZ else round(x, 4)
D = [[f(a) for a in r] for r in A]
latex_req = r"$\require{color}$"
latex_def = r"$\definecolor{energy}{RGB}{200, 8, 21}$"
box = lambda t: r"$\color{energy}{\colorbox{yellow}" + fr"{{{t}}}" + "}$"
hr = [r"$\color{red}" + f"{{{n}}}$" for n in (1 .. 10)]
cc = ["Équirépartition", "Tout pour un", "Un déshérité"]
cc += ["Injustice pour 1/2 population", "Injustice croissante"]
hc = [latex_req + latex_def] + [box(c) for c in cc]
t = table(D, header_row=hr, header_column=hc)
t

Illustration

click to hide/show revision 2
No.2 Revision

Presumably this takes place in a browser?

Maybe in Jupyter or in SageCell?

The following works in these contexts.

Making it work in the Sage REPL or in SageTeX would require some changes.

Not sure that fully answers your question, but hopefully it is a step.

A = [[10] * 10, [100] + [0] * 9, [100/9] * 9 + [0]]
A.extend([[20] * 5 + [0] * 5, [51200/1023/2^n for n in range(10)]])
f = lambda x: x if x in ZZ else round(x, 4)
D = [[f(a) for a in r] for r in A]
latex_req = r"$\require{color}$"
latex_def = r"$\definecolor{energy}{RGB}{200, 8, 21}$"
box = lambda t: r"$\color{energy}{\colorbox{yellow}" + fr"{{{t}}}" + "}$"
hr = [r"$\color{red}" + f"{{{n}}}$" for n in (1 .. 10)]
cc = ["Équirépartition", "Tout pour un", "Un déshérité"]
cc += ["Injustice pour 1/2 population", "Injustice croissante"]
hc = [latex_req + latex_def] + [box(c) for c in cc]
t = table(D, header_row=hr, header_column=hc)
t

Illustration

Inspired by the answer to this previous question: