Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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{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
          %  \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\\
          \bottomrule
    \end{tabular}
\end{table}

alt text

share|improve this question
add comment

2 Answers 2

up vote 12 down vote accepted

Use the following as your column format:

S[table-format=3.2,table-number-alignment=right]
share|improve this answer
add comment

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
1  
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
add comment

Your Answer

 
discard

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.