# Numbers in tables: align by decimal point *and* flush right?

While the solutions to both questions worked, there is a final change I hope it is possible. Currently, while the numbers are aligned by decimal points, they are centered within the column. Below is the code and its output.

Is there a way to make the numbers in the rightmost column be flushed right as well, while maintaining the alignment by decimal point? It is alright if a little bit of help is needed, such as declaring in advance how many digits are in each part (integer and fractional). Thus it is known which decimal position will be the rightmost one and the alignment can be determined.

\begin{table}[htp]
\centering
\begin{tabular}{@{}l r r>{\bfseries}S[table-format=3.2]@{}}
\toprule
\textbf{Product Group} & \textbf{Production Size} & \textbf{Number of Failures} & \textbf{Failure Rates} \\
& & & \textbf{(per 1,000 items)} \\
\midrule
foo1 & 11,111 & 1,111 & 11.11\\
foo2 & 22,222 & 2,222 & 222\\
foo3 & 33,333 & 3,333 & 3.33\\
foo4 & 44,444 & 4,444 & 44.4\\
foo5 & 55,555 & 5,555 & 5.5\\
\bottomrule
\end{tabular}
\end{table}


Use the following as your column format:

S[table-format=3.2,table-number-alignment=right]


I don't think that's actually going to look as good as you think, but....

Probably the most straightforward way is to fill out the numbers all to the same number of decimal points, and then right-align them. You obviously don't want to print out all of that, so use \phantom on the parts you don't want to print:

foo2 & 22,222 & 2,222 & 222\phantom{.00}\\
foo3 & 33,333 & 3,333 & 3.33\\
foo4 & 44,444 & 4,444 & 44.4\phantom{0}\\

• Andre-r's solution is more straightforward, but this answers also gets a vote because I learnt about \phantom. Commented Sep 6, 2010 at 14:42
• Yup, I agree that his is the better answer -- no point in doing something by hand when there's a way to do it automatically. Thanks for the upvote, though! Commented Sep 7, 2010 at 22:04
• The phantom trick becomes a little easier to use if you define an unused character to stand for the desired phantom. Here I define the underscore to stand for a phantom zero: \catcode`_=\active\def_{\phantom0}. It's a good idea to keep this articular definition local to the table, i.e. place it after \begin{table} to avoid that the underscore is redefined globally. Commented Jan 22, 2011 at 19:32