[Tex/LaTex] n siunitx number formatting option equivalent to pgfplots’s “fixed relative”

siunitxtikz-pgf

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}.

Best Answer

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}
Related Question