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.

I need to typeset a table with units, so I'd like to use siunitx for that. However, I don't want scientific notation, but a given number of figures. pgfplots has the fixed relative option for that purpose:

\documentclass{article}
\usepackage{pgfplots,siunitx}
\def\numA{1.23456789e3}
\def\numB{1.23456789e-3}
\begin{document}
\noindent
  pgf standard format:\\
  \pgfmathprintnumber{\numA}\\
  \pgfmathprintnumber{\numB}\\
  \pgfkeys{/pgf/number format/.cd,fixed relative,precision=3}
  desired format:\\
  \pgfmathprintnumber{\numA}\\
  \pgfmathprintnumber{\numB}
\end{document}

This is the output of the above code:

enter image description here

I'd like to get the same output with siunitx, if possible. I've tried explicitly disabling scientific-notation, but as it seems that key is only useful for enabling scientific notation when siunitx would otherwise not use it:

\num{\numA}\\
\num{\numB}\\
\sisetup{round-mode=figures,round-precision=3,scientific-notation=false}
\num{\numA}\\
\num{\numB}\\

Output:

enter image description here

One possibility would be to redefine \SI{}{} and \num{} to use \pgfmathprintnumber{} and disabling siunitx's number parsing, but I'd like to know what else I could do.

My current workaround is:

\let\oldnum\num
\renewcommand{\num}[1]{\oldnum[parse-numbers=false]{\pgfmathprintnumber{#1}}}
\let\oldSI\SI
\renewcommand{\SI}[3][]{\oldSI[#1,parse-numbers=false]{\pgfmathprintnumber{#2}}{#3}}

but this doesn't let me pass options to \pgfmathprintnumber. Passing options to \SI works well, as in \SI[per-mode=fraction]{1e-3}{\meter\per\second}.

share|improve this question
1  
Do you mean rounding to a number of significant figures? –  Joseph Wright Mar 30 '12 at 10:03
1  
Yes, rounding is a part of the problem. My numbers come from an external file with 19 figures each and I want to round them to a fixed number of significant figures, but without scientific notation. –  Christoph Mar 30 '12 at 10:08
2  
At present, I suspect the answer in 'no',but work on v2.5 is due to take place over the next week. So I will look into this. –  Joseph Wright Mar 30 '12 at 17:44
    
@Joseph: Thank you! I've added my current workaround, not sure if that is helpful to others but it works for me despite all its limitations. –  Christoph Mar 30 '12 at 18:05
add comment

1 Answer

up vote 6 down vote accepted

This is possible in version 2.5, which deals correctly with fixed exponent of zero

\documentclass{article}
\usepackage{pgfplots,siunitx}
\def\numA{1.23456789e3}
\def\numB{1.23456789e-3}
\begin{document}
\noindent
  pgf standard format:\\
  \pgfmathprintnumber{\numA}\\
  \num{\numA}\\
  \pgfmathprintnumber{\numB}\\
  \num{\numB}\\
  \pgfkeys{/pgf/number format/.cd,fixed relative,precision=3}
  \sisetup{scientific-notation = fixed, fixed-exponent = 0, round-mode = figures,
    round-precision = 3}
  desired format:\\
  \pgfmathprintnumber{\numA}\\
  \num{\numA}\\
  \pgfmathprintnumber{\numB}\\
  \num{\numB}\\
\end{document}
share|improve this answer
    
CTAN update over the weekend! –  Joseph Wright Apr 14 '12 at 21:35
1  
bazinga! Thank you! That makes life much easier. –  Christoph Apr 19 '12 at 7:22
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.