3
$\begingroup$

In Mathematica 10.4 I'd like to center the column headings in my table while continuing to align the column entries on the decimal point. Here's an example:

data = {{3.`, 12.03504555`, 12.023009030063605`, 12.023376796911684`, 
         0.0010001225077536091`, 0.0009695645138888542`}, {11.`, 
         1.836680386`, 1.8363040407777864`, 1.8363031611946115`, 
         0.00020490512398463334`, 0.00020538402231751185`}}; 
TableForm[data, TableHeadings -> {None, {E - Subscript[E, F], "refVal", "myFastVal",
 "myAccurateVal", 1 - myFastVal/refVal, 1 - myAccurateVal/refVal}}, TableAlignments -> "."]

TableAlignments->"." causes the numeric rows to align on the decimal but the heading row remains left aligned, so the heading labels are offset relative to the data in their columns. Is there a way to do what I want?

$\endgroup$
1
  • $\begingroup$ The styling of your question can be improved. Please take the time to read the markdown help page. You'll better communicate your problem when you use the right formatting. $\endgroup$
    – halirutan
    Commented Feb 15, 2018 at 15:55

1 Answer 1

3
$\begingroup$

TableAlignments is not flexible enough to align individual rows, columns or items separately. That is, alignments can only be specified for each dimension (rows and/or columns), and row (column) headers inherit the alignment settings of the rows (columns). See also this closely related q/a.

Grid is more convenient to use to get what you need:

columnheaders = Item[#, Alignment -> Right] & /@ {E - Subscript[E, F], "refVal", 
    "myFastVal", "myAccurateVal", 1 - myFastVal/refVal, 1 - myAccurateVal/refVal};

Grid[Prepend[data, columnheaders], Dividers -> {None, 2 -> True}, Alignment -> "."] 

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks! That works. $\endgroup$
    – John V.
    Commented Feb 16, 2018 at 13:25
  • $\begingroup$ @JohnV., my pleasure. Thank you for the accept. Welcome to mma.se. $\endgroup$
    – kglr
    Commented Feb 16, 2018 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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