# Making a table using the grid function with some modifications

I am trying to make a table out of some formulas which I listed in the code section, however, I am having several issues:

*Alignment of rows (I think it has something to do with scientific notation since those values are the only ones not aligned, but I may be mistaken).

*Headers proper alignment, e.g. $$N_B$$ should span $$q_B$$ and $$\Omega_B$$ only

*Frames on all items (I know why the elements in the column of say, $$q_A$$ are not framed, it is because I declared the whole column as a "single object" so "Frame -> All" framed the whole column, but I don't know how to modify this).

q1 = Column[Table[i, {i, 0, 20}]];
q2 = Column[Reverse[Table[i, {i, 480, 500}]]];
\[CapitalOmega]1[q1_] := (q1 + 1 - 1)!/(q1! (1 - 1)!)
\[CapitalOmega]2[q2_] := (q2 + 100 - 1)!/(q2! (100 - 1)!)
\[CapitalOmega] = Column[Times[Table[\[CapitalOmega]1[q1], {q1, 0, 20}], Reverse[Table[N[\[CapitalOmega]2[q2]], {q2, 480, 500}]]]];
Ln\[CapitalOmega] = Column[Log[Times[Table[\[CapitalOmega]1[q1], {q1, 0, 20}], Reverse[Table[N[\[CapitalOmega]2[q2]], {q2, 480, 500}]]]]];
m1 = Column[Table[ScientificForm[\[CapitalOmega]1[q1]], {q1, 0, 20}]];
m2 = Column[Reverse[Table[ScientificForm[N[\[CapitalOmega]2[q2]]], {q2, 480, 500}]]];
Grid[{{"Two Einstein Solid", SpanFromLeft}, {"\!$$\*SubscriptBox[\(N$$, $$A$$]\)=1", SpanFromLeft, "\!$$\*SubscriptBox[\(N$$, $$B$$]\)=100", SpanFromLeft}, {"\!$$\*SubscriptBox[\(q$$, $$A$$]\)", "\!$$\*SubscriptBox[\(\[CapitalOmega]$$, $$A$$]\)", "\!$$\*SubscriptBox[\(q$$, $$B$$]\)", "\!$$\*SubscriptBox[\(\[CapitalOmega]$$, $$B$$]\)", "\[CapitalOmega]"}, {q1, m1, q2, m2, \[CapitalOmega]}}, Alignment -> {Center, Center}, ItemSize -> {{Scaled[0.05], Scaled[0.05], Scaled[0.05], Scaled[0.1], Scaled[0.1]}}, Spacings -> {2, 2}, Frame -> All]


*Please be as basic as possible and can someone explain each function clearly.

• Do you get what you need if you use Join[{{"Two Einstein Solid", SpanFromLeft}, {"\!$$\*SubscriptBox[\(N$$, $$A$$]\)=1", SpanFromLeft, "\!$$\*SubscriptBox[\(N$$, $$B$$]\)=100", SpanFromLeft, ""}, {"\!$$\*SubscriptBox[\(q$$, $$A$$]\)", "\!$$\*SubscriptBox[\(\[CapitalOmega]$$, $$A$$]\)", "\!$$\*SubscriptBox[\(q$$, $$B$$]\)", "\!$$\*SubscriptBox[\(\[CapitalOmega]$$, $$B$$]\)", "\[CapitalOmega]"}}, {q1, m1, q2, m2, \[CapitalOmega]} /. Column -> Identity // Transpose] as the first argument in Grid? – kglr May 18 '19 at 8:29
• @kglr Indeed! Can you please explain a bit why that must be the case with those functions? What are my mistakes? Also, the alignment of $N_B$ is not yet resolved. – mathemania May 18 '19 at 8:35
• mathemania, your code give as a table with 5 columns (your picture has 6). For 6 columns, change "" after the last SpanFromLeft to "", SpanFromLeft. – kglr May 18 '19 at 8:38
• @kglr That fixed the $N_B$ problem, but can you say something about why you chose to write $Join$ and $/. Column -> Identity // Transpose$ in order to fix my problem, what are their purposes in this context? – mathemania May 18 '19 at 8:44
• {q1, m1, q2, m2, \[CapitalOmega]} /. Column -> Identity removes the Column so that you end up with a matrix with 5 rows and 21 columns; Transpose converts that 5X21 matrix into a 21X5 matrix. Join just appends this matrix to your list of header rows. – kglr May 18 '19 at 8:59

You can add the options Alignment -> Center and ItemSize -> {All, 2} to Column when you define q1, m1, q2, m2 and Ω, e.g.

q1 = Column[Table[i, {i, 0, 20}], Alignment -> Center, ItemSize -> {All, 2}];


Then the rows in each Column object are aligned:

Grid[{{"Two Einstein Solid",
SpanFromLeft}, {"\!$$\*SubscriptBox[\(N$$, $$A$$]\)=1",
SpanFromLeft, "\!$$\*SubscriptBox[\(N$$, $$B$$]\)=100",
SpanFromLeft, ""}, {"\!$$\*SubscriptBox[\(q$$, $$A$$]\)",
"\!$$\*SubscriptBox[\(Ω$$, $$A$$]\)",
"\!$$\*SubscriptBox[\(q$$, $$B$$]\)",
"\!$$\*SubscriptBox[\(Ω$$, $$B$$]\)",
"Ω"}, {q1, m1, q2, m2, Ω}},
Alignment -> {Center, Center},
ItemSize -> {{Scaled[0.05], Scaled[0.05], Scaled[0.05], Scaled[0.15],
Scaled[0.15]}}, Spacings -> {2, 2}, Frame -> All]


where I added "" after the last SpanFromLeft so that $$N_B = 100$$ spans only two columns.

With this approach you can not add divider lines aligned across columns.

A better approach is to remove Column from {q1, m1, q2, m2, Ω} and Transpose the resulting 5X21 matrix into a 21X5 matrix and append it to the header rows

mat = Join[{{"Two Einstein Solid",
SpanFromLeft}, {"\!$$\*SubscriptBox[\(N$$, $$A$$]\)=1",
SpanFromLeft, "\!$$\*SubscriptBox[\(N$$, $$B$$]\)=100",
SpanFromLeft, ""}, {"\!$$\*SubscriptBox[\(q$$, $$A$$]\)",
"\!$$\*SubscriptBox[\(Ω$$, $$A$$]\)",
"\!$$\*SubscriptBox[\(q$$, $$B$$]\)",
"\!$$\*SubscriptBox[\(Ω$$, $$B$$]\)", "Ω"}},
Transpose[{q1, m1, q2, m2, Ω} /. Column -> Identity]];


and use mat as the first argument in Grid:

Grid[mat, Alignment -> {Center, Center},
ItemSize -> {{Scaled[0.05], Scaled[0.05], Scaled[0.05], Scaled[0.15],
Scaled[0.15]}}, Spacings -> {2, 2}, Frame -> All]