# Formating a Grid with Reals “.”-aligned

I have a table of real numbers and want to format a Grid such that the headlines are centered and the contents are aligned at the decimal point. MWE:

data = Table[RandomReal[{1, 100}], {i, 1, 5}, {j, 2}]


columns = {"one", "two"};


Rows:

rowsLabels = StringJoin["R", ToString[#]] & /@ Range[5]
rows = Flatten /@ ({rowsLabels, data}\[Transpose])


Table:

tab = Join[{Prepend[columns, "Text "]}, rows]


Then

Grid[tab,
Dividers -> {{2 -> True}, {2 -> True}},
Alignment -> {{Left, Center, Center}, {{Left, ".", "."}}, Baseline}]


delivers:

and

Grid[tab,
Dividers -> {{2 -> True}, {2 -> True}},
Alignment -> {{{Left, Center, Center}, {Left, ".", "."}}, Baseline}]


delivers:

So the second columns is fine, but the first not. Can anyone give me a hint on how I can achieve the desired result.

It looks like using a list specification doesn't work for this. Instead, you can use the 3 element list form of Alignment:

Grid[tab, Alignment->{{Left,".","."},Baseline, {{1,1},{1,3}}->Center}]


Alternatively, you could use Item to override the headers:

Grid[
MapAt[Item[#, Alignment->Center]&, tab, {1, All}],
Alignment->{{Left, ".", "."}, Baseline}
]


• Thank your for this solution, the second one is the one which is very clear to me (one rule - override the headers). – mgamer May 10 '18 at 19:05
• It seems to me that the documentation you point to for the three-argument form suggests the 3rd argument would be {{1, 1} -> Center, {1, 2} -> Center, {1, 3} -> Center}}. Should I be able to deduce from this that {{1, 1}, {1, 3}} -> Center} will work? If not, what is the actual documentation? – Alan May 10 '18 at 21:30
• @Alan The Alignment docs are a bit sparse on this topic. If you look at one of the other options, e.g., Frame, you will see an example of the syntax I used. – Carl Woll May 10 '18 at 21:54