4

I would like to print numbers in a table in the form 12.3 (4.56) using siunitx. How can this be achieved?

I'm a bit worried that siunitx changes the numbers in various ways and I would like to understand why. Here is an example:

\documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{xcolor}

\begin{document}

\begin{tabular}{S[separate-uncertainty]
                S[separate-uncertainty, uncertainty-separator={\ }]
                S[uncertainty-separator={\ }]} % table-format=2.1(1.2) doesn't help here
  \toprule
  12.3 (456) & 12.3 +- 4.56 & 12.3 +- 4.56\\
  \bottomrule
\end{tabular}

\end{document}

My first trial was actually 12.3 (4.56) but that gives an error. It seems that there is no second dot allowed (I was hoping that this is possible with table-format, but it didn't work) unless one uses a syntax like 12.3 +- 4.56.

Note:

  • That both numbers (the 'main' number and the 'uncertainty') are perfectly formatted in my case. They shouldn't be changed/adjusted.

  • I am not looking for a solution with separate columns for the 'main' number and the 'uncertainty'.

  • I am specifically looking for a solution with siunitx in order to have the numbers nicely aligned (ideally according to both decimal dots) and to be able to colorize certain table entries.

  • Hmm, why the second point: I am not looking for a solution with separate columns for the 'main' number and the 'uncertainty' ? – Tom Bombadil May 17 '13 at 20:07
  • The table is autogenerated with a different program in a quite sophisticated way, including the corresponding header. Suddenly having roughly double the amount of columns is technically not possible, that's why I was hoping for a solution without a second column. I can hack it in the sense that I can determine the length of the numbers in the parentheses and fill the 'gaps' with spaces or \phantom commands. Not very elegant, though. Given that siunitx is so sophisticated, I was hoping this could be done with this package. I was quite a bit disappointed it makes so many assumptions... – Marius Hofert May 17 '13 at 20:15
  • If all the number tuples are of the form a (b) you could simply find and replace ( with & (. And for the header line you could find and replace & with } & \multicolumn{2}{c}{, in the end copying \multicolumn{2}{c}{ to the beginning and } just before the \\ . Finally, double the number of S columns. Or is there any reason this would not work? – Tom Bombadil May 17 '13 at 20:28
  • Of course I could do that :-) But this is part of a software and 99% of the users couldn't do that :-) They want to hit a button... – Marius Hofert May 17 '13 at 21:01
  • 1
    Ow, that's a low blow, Users! Don't get me started about them ;) – Tom Bombadil May 17 '13 at 22:44
3

Physicists would complain about 12.3 (4.56). 12.3 means that the last certain digit is the 3, e.g. you don't know what the exact following digits are. Lacking that knowledge, giving an error like 4.56 does not make any sense, as this would be more accurate than your actual result. So errors should have at best as many significant digits as the result. If your error computation gives 4.56 you'd need to round it at lest to 4.6. Often it is considered even better to have only one significant digit for the error (two is the first digit is a 1), so your result should probably be 12 (5) be Note that you don't use normal rounding rules, errors are always rounded up to avoid understating the value of the error, while results are rounded normally to the precision of the error. Also, the error is always given as digits from the end, I don't think that you usually use a decimal separator there. So you have three options:

  • use 12.3 (4.6) if you don't know a more precise value
  • use 12.30 (4.56) if you know the value to a higher precision than 12.3 lets on
  • use 12 (5) as the very large value of the uncertainty suggests

So I think 12.30(456) is fine, as well as 12.30 +- 4.56. Unfortunately, I didn't find a way to separate the uncertainties as you requested, although I personally don't think that this would be a good idea. However an unexpected behaviour occured: If you have numbers with and without decimal point in the same column, the alignment is off by about the width of the decimal separator.

Code

\documentclass{article}

\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{xcolor}

\begin{document}

\begin{tabular}{S[uncertainty-separator={\ }]
                S[separate-uncertainty, uncertainty-separator={\ }]
                S[separate-uncertainty]
                S} 
  \toprule
  12.30 (456) & 12.30 +- 4.56 & 12.3 +- 4.56 & 12.30 (456)\\
  12.3 (46) & 12.3 +- 4.6 & 12.3 +- 4.6 & 12.3 (46)\\
  12 (5) & 12 +- 5 & 12 +- 5 & 12 (5)\\
  \bottomrule
\end{tabular}

\end{document}

Output

enter image description here

  • Thanks, Tom. I accept this as an answer, but it was not quite what I was hoping for. The second number in my case is just another piece of information, it is not the uncertainty of the first number and therefore the number of digits can be larger than for the first number. I was hoping to use this "uncertainty" construction/approach of siunitx to get the numbers side-by-side. But I see it's not so simple. Nevertheless, your post was very informative, thanks again. – Marius Hofert May 17 '13 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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