I want to print regular and ragged tables with row- and column numbers.
Clear[bb];
tab = {{11, 12}, {21, 23}, {31, 32}};
raggedTab = {{11, 12}, {21, bb, 23}, {31, 32}}
{{11, 12}, {21, bb, 23}, {31, 32}}
If I print an ordinary matrix with TableForm and TableHeadings, dividers are correctly printed. If I use a ragged table instead, dividers are missing:
{Framed[TableForm[tab, TableHeadings -> Automatic]],
Framed[TableForm[raggedTab, TableHeadings -> Automatic]]}
Is this a bug or a feature?
For MatrixForm instead of TableForm I understand the behaviour. A ragged table is interpreted as a one-column list:
{Framed[MatrixForm[tab, TableHeadings -> Automatic]],
Framed[MatrixForm[raggedTab, TableHeadings -> Automatic]]}
With Grid, of course, I can control everything. But there are no automatic headings, hence I must provide them myself, which is a bit tedious:
{n, m} = Dimensions[tab];
Grid[Join[
{Prepend[Range[m], ""]},
Join[Transpose[{Range[n]}], tab, 2]]
, Frame -> True, Dividers -> {{2 -> True}, {2 -> True}}
]
{n, m} = {Length[raggedTab],
Max[Table[Length[raggedTab[[i]]], {i, n}]]};
Grid[Join[
{Prepend[Range[m], ""]},
Join[Transpose[{Range[n]}], raggedTab, 2]]
, Frame -> True, Dividers -> {{2 -> True}, {2 -> True}}
]