7

I'm using siunitx to report a value plus an 'uncertainty' (as defined in the siunitx package). I'm running into problems with my desired formatting, and I think the issue is because I'd like the resulting uncertainty to have a different number of decimal places than the value that the uncertainty pertains to. E.g. 98.5 (one decimal place) +/- 0.98 (two decimal places). Note that in this example the values have a unit (%) meaning that solutions using \SI are preferred over num.

Anyone know how to produce something equal to the first attempt below but with the first number (98.5) reported to one decimal place instead of 2?

The context is that I am citing values from a scientific journal article, so regardless of whether a differing number of decimal places is 'correct' I want to accurately reflect the values reported. The 'uncertainty' in this context represents standard deviation about a mean.

Below is an MWE:

\documentclass{article}
\usepackage{textcomp}
\usepackage{siunitx}

\sisetup{range-units=single,
        separate-uncertainty = true,
        multi-part-units = single}

\begin{document}

\noindent\SI{98.5 \pm 0.98}{\percent} : Spacing correct, precision wrong (desired 98.5, not 98.50)

\noindent\SIrange[range-phrase=\ \textpm\ ]{98.50}{0.98}{\percent} : Workaround. Note different (wrong) spacing around plus/minus sign

\noindent\ \SIrange[range-phrase=\ \textpm\ ]{98.5}{0.98}{\percent} : Workaround with desired numbers. Incorrect spacing maintained

\noindent\SI{98.5 (98)}{\percent} : Precision correct, uncertainty value wrong.

%\noindent\SI{98.5 (9.8)}{\percent} : Expected to fix uncertainty value of above, returns error instead

\end{document}

output of MWE

  • 2
    As as side note, please keep in mind that values and uncertainties should really be expressed with the same number of significant digits. (See eg. NIST recommendations, or §7.2.6 of this BIPM guide). – Arcturus B Nov 23 '17 at 23:34
9

There are limits to what one can convince the parsing system to do: where that happens, you'll need to do things manually. Depending on how you want your markup to look, you might go with

\documentclass{article}
\usepackage{siunitx}

\begin{document}
\SI[parse-numbers = false]{98.5 \pm 0.98}{\percent}
\end{document}

or

\documentclass{article}
\usepackage{siunitx}

\begin{document}
$98.5 \pm \SI{0.98}{\percent}$
\end{document}
  • Shucks. Well, thanks for your help just the same! – JMikes Nov 23 '17 at 20:47
1

While the answers proposed by Joseph Wright are viable options, I prefer the workaround I proposed in my original question using \SIrange because it preserves the functionality of keeping whether units are repeated or not (range-units) as a variable (i.e. A +/- B% vs A% +/- B%).

Thank you to Joseph Wright for confirming that there wasn't a more elegant solution to this problem.

Preferred answer is below, followed by an MWE illustrating the impact of range-units on the proposed solutions.

Preferred Answer: \SIrange[range-phrase=\ \textpm\ ]{98.50}{0.98}{\percent}

MWE

\documentclass{article}
\usepackage{textcomp}
\usepackage{siunitx}

\sisetup{separate-uncertainty = true}
\begin{document}

\sisetup{range-units=single}
Single Units in Setup: \\
\SIrange[range-phrase=\ \textpm\ ]{98.5}{0.98}{\percent} \\
\SI[parse-numbers = false]{98.5 \pm 0.98}{\percent} \\
$98.5 \pm \SI{0.98}{\percent}$ \\

\sisetup{range-units=repeat}
Repeat Units in Setup: \\
\SIrange[range-phrase=\ \textpm\ ]{98.5}{0.98}{\percent}  - Functionality Maintained\\
\SI[parse-numbers = false]{98.5 \pm 0.98}{\percent} - Functionality NOT Maintained\\
$98.5 \pm \SI{0.98}{\percent}$ - Functionality NOT Maintained\\

\end{document}

Output of MWE showing effect of range-units on alternative solutions

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.