4
$\begingroup$

Is there away to get TableHeadings align to the Right instead of the default to the Left? For example, for

TableForm[{{1}, {3}}, TableHeadings->{{"t111111", "t2"}, {"Values"}}]

is there a way to have t111111 and t2 align to the right?

$\endgroup$
3
$\begingroup$

Sure hope there is an easier way than the following

tf = TableForm[{{1}, {3}}, TableHeadings -> {{"t111111", "t2"}, {"Values"}}]

enter image description here

RawBoxes[ToBoxes@tf /. HoldPattern[ColumnAlignments -> _]:>(ColumnAlignments -> {Right, Left})]

enter image description here

tf = TableForm[{{1, 2, 3}, {3, 4, 5}},TableHeadings->{{"t111111","t2"},{"Val1", "Val2", "Val3"}}];

RawBoxes[ToBoxes@tf /. HoldPattern[ColumnAlignments -> _]:>(ColumnAlignments -> {Right, Center})]

enter image description here

$\endgroup$
1
$\begingroup$
leftpad[list_] :=
 With[{blanks = StringJoin /@ Map[Table[" ", {#}] &, Max[#] - # &[StringLength /@ list]]},
  Map[StringJoin[blanks[[#]], list[[#]]] &, Range @ Length @ list]]

keys = {"a", "abcd" , "abc", "ab"};
vals = Range @ 4;

TableForm[List /@ vals, TableHeadings -> {leftpad @ keys, {"Values"}}]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ I don't know if you realize this, but you can edit your deleted answers and undelete them instead of posting new ones. $\endgroup$ – RunnyKine Sep 20 '14 at 9:45
  • $\begingroup$ @RunnyKine Thanks. I will do that in the future :) $\endgroup$ – eldo Sep 20 '14 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.