# Represent list of lists as formatted grid

I have tried to figure out how to make these changes, but it mostly just ends up with me making it ten times worse.

Insert[
Multicolumn[
Flatten[
Table[
{p, TraditionalForm@FullSimplify[ ((p - 2) n^2 - (p - 4) n)/2]},
{p, 3, 32, 1}
]
],
{12, 5}
],
Alignment -> Center,
2
]


Needs to become {p, ((p - 2) n^2 - (p - 4) n)/2 // Distribute} /. p -> Range[3, 32] // Transpose; ## Explanation

Since most arithmetic operations are performed element-wise over lists (e.g. {a, b} + 1 -> {a + 1, b + 1}), we can strip the Table and just replace p with the list of given values. Then we can use Distribute to bring in the 1/2 term. And finally, since the list now has the structure

{
{3,           4,   5,            ...},
{n^2/2 + n/2, n^2, 3n^2/2 + n/2, ...}
}


and we want to pair up the elements in each column, we can use a good ol' fashion Transpose.

Then for the formatting into a grid, we need to Partition the list of lists into a 5x7x2 array, and then use TableForm with the TableAlignments option, and finally, to make it all pretty, we wrap the whole thing in a TraditionalForm.

Welcome to MSE. Here is one way

table = Table[{p, TraditionalForm@Expand[((p - 2) n^2 - (p - 4) n)/2]}, {p, 3, 32}];
table // Map[Column[#, Center] &] // Partition[#, 5] & // Grid 