9

How can I format a table column with siunitxwithout adding additional zeroes after the decimal separator?

I'd like to see 5,2 in the output instead of 5,200 (however: 0,246 shall still be displayed as 0,246 and e. g. 0,200 shall still be displayed as 0,200 if it is given like that in the source code), but I can not find the correction options (siunitxis too flexible - at least much more flexible then my brain ;-)).

The package options in the preamble have to stay as they are, as this otherwise would affect other tables.

\documentclass{scrbook}

\usepackage[round-mode=places, round-integer-to-decimal, round-precision=2,
    table-format = 1.2, 
    table-number-alignment=center,
    round-integer-to-decimal,
    output-decimal-marker={,}
    ]{siunitx} 

\usepackage[version=3]{mhchem}
\usepackage[tight]{units}
\usepackage{booktabs}


\begin{document}

\begin{tabular}{lllS[table-format=1.3, round-precision=3, table-comparator=true, round-integer-to-decimal=false]}
\toprule
Eigenschaft & Einheit & Spezifikation & {Wert}\\
\midrule
{\ce{Y2O3}} & {(\unit{\%})} & {4,95--5,35} & 5,2 \\
{\ce{Al2O3}} & {(\unit{\%})} & {0,15--0,35} & 0,246 \\
{\ce{SiO2}} & {(\unit{\%})} & {$<0,02$} & <0,002 \\
{\ce{Fe2O2}} & {(\unit{\%})} & {$<0,01$} & <0,002 \\
{\ce{Na2O}} & {(\unit{\%})} & {$<0,04$} & 0,007 \\
GV    & {(\unit{\%})} & {$<1,2$} & 0,42 \\
Spez. Obfl. & {(\unitfrac{m$^2$}{g})} & {5--9} & 6,9 \\
Partikelgröße & {(\unit{\AA})} & {k. A.} & 390 \
\bottomrule
\end{tabular}%
\end{document}
11
  • Does changing round-precision=3 to =1 have the desired effect?
    – Seamus
    Jul 16, 2011 at 11:16
  • @Seamus: no, round-precision=1 rounds all values to 1 decimal, but I just don't want that decimals are added: 5,2 shall stay 5,2 but 0,246 shall also still be displayed as 0,246! So I "just" want all numbers be aligned with the ",". (I've edited the question to hopefully make it more clear) Jul 16, 2011 at 11:25
  • 1
    @Martin: You do know that you are abusing the rounding system, I hope. In general, I would not expect rounding to be on for an entire document as it implies that you are not thinking about where to round. The rounding system is intended for cases where auto-generated data tables need unrealistic precision removing. Leaving rounding on 'all of the time' makes it quite likely data is being rounded when you have not first checked that this is scientifically correct.
    – Joseph Wright
    Jul 16, 2011 at 14:10
  • 3
    (My point being that while siunitx provides various tools, it is intended to support good science.)
    – Joseph Wright
    Jul 16, 2011 at 14:12
  • 3
    I've posted some thoughts as texdev.net/2011/07/17/which-siunitx-options-to-set-globally
    – Joseph Wright
    Jul 17, 2011 at 15:07

4 Answers 4

10

I think what you need is the round-mode=off switch. [Addendum, Nov. 2021: see the remark at the bottom of this answer for an explanation on how to get his answer to work if you're working with version 3.x of the siunitx package.] Here's your MWE, slightly reworked:

\documentclass{scrbook}

\usepackage[round-mode=places, round-integer-to-decimal, round-precision=2,
    table-format = 1.2, 
    table-number-alignment=center,
    round-integer-to-decimal,
    output-decimal-marker={,}
    ]{siunitx} 
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\sisetup{table-format=1.3, round-precision=3, table-comparator=true, round-integer-to-decimal=false}
\begin{tabular}{S[round-mode=places]S[round-mode=off]}
\toprule
{``Places''} & {``Off''}\\
\midrule
  5,2   &   5,2   \\
  0,246 &   0,246 \\
 <0,002 &  <0,002 \\
 <0,002 &  <0,002 \\
  0,007 &   0,007 \\
  0,42  &   0,42  \\
  6,9   &   6,9   \\
390     & 390     \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

Addendum, Nov. 2021: In version 3 of the siunitx package, the valid choices for the round-mode option are none, places, figures, and uncertainty. Obseve that off is no longer a valid choice. Thus, in order to get the code shown above to run under v3 of siunitx, one needs to replace round-mode=off with round-mode=none.

0
2

The solution is:

round-mode=off (to overwrite round-mode=places in the preamble)

\begin{tabular}{llcS[table-format=1.3, round-precision=3, table-comparator=true, round-integer-to-decimal=false, round-mode=off]}
2

The option is round-pad=false. According to the new doc of siunitx:

The option round-integer-to-decimal = false has been removed, and whilst there is not a direct replacement, users are likely to find that round-pad = false offers the desired outcome.

1

The option I think you are looking for is add-decimal-zero=false.

Section 5.5 of the siunitx manual (Post-processing numbers) contains all the relevant information on the options for how to represent numbers.

Having actually tried this, it appears not to work. It's certainly what the option should do. But it doesn't appear to work...

4
  • thanks for your effort: I've finally found it (and Mico Loretan posted it): round-mode=off helps. :-) Jul 16, 2011 at 11:54
  • @Martin also, I recomment replacing the units package and its commands with siunitx's replacements. And your package options include the round-integer-to-decimal option twice.
    – Seamus
    Jul 16, 2011 at 11:57
  • thanks for your recommendations! I started with unitsand discovered siunitx later when things got more complicated... I plan to replace units, but as I have extensively used it in the whole document, this will be quite time consuming as I fear side effects.. Jul 16, 2011 at 11:59
  • add-decimal-zero is not the right option. As far as I can tell, it's solely about the implicit zero in 123. (notice the decimal point). Nov 8, 2019 at 12:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .