TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is a followup question to siunitx: aligning numbers by decimal points in tables doesn't work for bolded or italicized numbers and Aligning numbers by decimal points in table columns.

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.

Thanks in advance.

    \begin{tabular}{@{}l r r>{\bfseries}S[table-format=3.2]@{}}
          \textbf{Product Group} & \textbf{Production Size} & \textbf{Number of Failures} & \textbf{Failure Rates} \\
          & & & \textbf{(per 1,000 items)} \\
          %  \addlinespace
          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\\

alt text

share|improve this question
up vote 13 down vote accepted

Use the following as your column format:

share|improve this answer

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}\\
share|improve this answer
Andre-r's solution is more straightforward, but this answers also gets a vote because I learnt about \phantom. – wishihadabettername Sep 6 '10 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! – Brooks Moses Sep 7 '10 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. – Christian Lindig Jan 22 '11 at 19:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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