# Pretty printing of factorization output

I want to create a table of factorization of certain numbers $f(n)$ with traditional pretty printing output (more or less same as what is used to display in textbooks). For example consider

FactorInteger[Table[n!, {n, 0, 5}]]


standard output is

{{{1, 1}}, {{1, 1}}, {{2, 1}}, {{2, 1}, {3, 1}}, {{2, 3}, {3, 1}}, {{2, 3}, {3, 1}, {5, 1}}}


and the so-called traditional output is some kind of matrix-looking format, with first column the base and the second column the exponent.

How do I create a suitable display output as in

$$\begin{array}{cc} \text{N} & \text{factorization of N!} \\ \hline 0 & 1 \\ \hline 1 & 1 \\ \hline 2 & 2 \\ \hline 3 & 2, 3 \\ \hline 4 & 2^3, 3 \\ \hline 5 & 2^3, 3,5 \\ \hline \end{array}$$

The lines and heading etc. are not the important aspects, the easily readable output is.

## 3 Answers

data = FactorInteger[Table[n!, {n, 0, 5}]];

leftCol = Prepend[Range[0, Length[data] - 1], "N"];

rigthCol = Prepend[
Row[HoldForm[#]^#2 & @@@ {##}, ","] & @@@ data,
"factorization of N!"
];

Grid[
Transpose[{leftCol, rigthCol}],
Alignment -> {{Right, Center}},
Dividers -> {False, {False, {True}}},
BaseStyle -> 25
] // TraditionalForm A bit differently:

list = FactorInteger[Table[n!, {n, 0, 5}]];
r    = Range[0, 5];
fac  = Map[Apply[HoldForm[#1^#2] &, #, {1}] &, list]


{{1^1},{1^1},{2^1},{2^1,3^1},{2^3,3^1},{2^3,3^1,5^1}}

Transpose@{r, Row /@ fac} //
TableForm[#, TableDepth -> 2, TableAlignments -> Center,
TableHeadings -> {None, {"N", "factorization of N!"}}] & // Framed Should be done with Grid, as "while TableForm allows you to create tables, it does not support the extensive styling options that are available to Grid" [ref], but that has been already shown by Kuba.

fun[x_] :=
Row@Riffle[
MapThread[If[#2 == 1, #1, HoldForm[#1^#2]] &,
Transpose[FactorInteger[x]]], "\[CenterDot]"]
Grid[Prepend[{#, fun[#!]} & /@ Range[0, 10], {"N",
"Factorization N!"}], Frame -> All, BaseStyle -> 20] 