TeX - LaTeX Asked on July 30, 2021
I would like to implement the following recommendation for rounding values in tables:
The siunitx
package provides options for rounding to a fixed number of significant digits but here we need to do this in dependence on the uncertainty. How can this be achieved?
Based on my very limited knowledge of TeX (and searching the Internet) I came up with the following solution which I will provide here as a start for others to improve on this:
documentclass{minimal}
usepackage{siunitx}
usepackage{stringstrings}
newcommand*{numRF}[2]{num[round-mode=figures,round-precision=#2]{#1}}
begin{document}
newcommand{matchroundtabular}[2]{% only works for integer values
{%
aftergroupround
stringlength[q]{#1}
newcountnumlen
numlen=theresult
stringlength[q]{#2}
newcounterrorlen
errorlen=theresult
newcountround
round=numlen
advanceround by -errorlen
advanceround by 1
expandafter
}
theround
{numRF{#1}{round}} & {numRF{#2}{2}}%
}
% Problem 1: alignment off
sisetup{round-mode = figures,round-precision = 2, table-number-alignment = right}%
begin{tabular}{
l
S[table-format=6.0]@{$,pm,$}S[table-format=3.0]@{~}
S[table-format=6.0]@{$,pm,$}S[table-format=3.0]@{~}
}
2 tight $tau$s & matchroundtabular{72293}{269} & 80839 & 51
2 medium $tau$s & matchroundtabular{212383}{461} & 231155 & 125
end{tabular}
% Problem 2: not working here
begin{tabular}{c@{$,pm,$}c}
Aaaaa & Bbbbb
matchroundtabular{343454}{455}
end{tabular}
end{document}
Output:
So this works but has two problems:
S
column definition. (See second table. My code is bad.)It currently also only works for integers. (Doing the same for floats is certainly much more complicated -- and I don't need it right now.)
Answered by fuenfundachtzig on July 30, 2021
With version 3 of siunitx
you can use round-mode = uncertainty
, for example
documentclass{article}
usepackage{booktabs}
usepackage{siunitx}
begin{document}
sisetup{uncertainty-mode = separate, round-mode = uncertainty}
begin{tabular}{
l
S[table-format=3.2(2)]
S[table-format=3.3(2)]
}
toprule
2 tight $tau$s & 72.293(269) & 80.839(51)
2 medium $tau$s & 212.383(461) & 231.155(125)
bottomrule
end{tabular}
end{document}
or
documentclass{article}
usepackage{booktabs}
usepackage{siunitx}
begin{document}
sisetup{uncertainty-mode = separate, round-mode = uncertainty}
begin{tabular}{
l
S[table-format=6(2)]
S[table-format=6(2)]
}
toprule
2 tight $tau$s & 72293(269) & 80839(51)
2 medium $tau$s & 212383(461) & 231155(125)
bottomrule
end{tabular}
end{document}
Answered by Joseph Wright on July 30, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP