Message Boards Message Boards

0
|
2663 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

TableForm misses Dividers?

Posted 4 years ago

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]]}

enter image description here

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]]}

enter image description here

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}}
 ]

enter image description here

{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}}
 ]

enter image description here

POSTED BY: Werner Geiger
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract