34

I like the default behavior of the siunitx package in that the thousands separator is not applied to four digit numbers, but is applied when the number of digits exceeds four. In documents that contain pgfplots, \pgfmathprintnumber is used for the formatting of the numbers, but it does not exhibit this behavior:

enter image description here

Is there a setting for \pgfmathprintnumber to format numbers similar to the \num macro from the siunitx package so either method can be freely used with for formatting numbers

Code:

\documentclass{article}

\usepackage{siunitx}
\usepackage{pgf}

\sisetup{
    group-digits=true,
    group-separator={\,},
}

\pgfkeys{/pgf/number format/.cd, set thousands separator={\,}}%

\begin{document}
\begin{tabular}{rll}
siunitx: &\num{9000}                &\num{19000} \\
    pgf: &\pgfmathprintnumber{9000} &\pgfmathprintnumber{19000} \\
\end{tabular}
\end{document}
0

1 Answer 1

32

siunitx-independent PGF solution

The same behaviour of siunitx’ option group-four-digits set to false can be achieved in PGF with the /pgf/number format/min exponent for 1000 sep style.

From the PGF manual, section 66.1 “Changing display styles”, p. 547:

/pgf/number format/min exponent for 1000 sep={<number>} (no default, initially 0)

Defines the smallest exponent in scientic notation which is required to draw thousand separators. The exponent is the number of digits minus one, so <number> = 4 will use thousand separators starting with 1e4 = 10000.

A value of 0 disables this feature (negative values are ignored).

Code

\documentclass{article}

\usepackage{siunitx}
\usepackage{pgf}

\sisetup{
    group-digits=true,
    group-separator={\,},
}

\pgfkeys{
    /pgf/number format/.cd,
        set thousands separator={\,},
        min exponent for 1000 sep=4,
}

\begin{document}
\begin{tabular}{rll}
siunitx: &\num{9000}                &\num{19000} \\
    pgf: &\pgfmathprintnumber{9000} &\pgfmathprintnumber{19000} \\
\end{tabular}
\end{document}

Output

Output of min exponent for 1000 sep = 4

siunitx and PGF

If you want to use siunitx and PGF’s number printing system consistently  together you should check out siunitx “little” \SendSettingsToPgf macro.

From the siunitx manual, section 7.9 “Transferring settings to PGF”, p. 63:

The numerical engine in the pgf package has settings similar to those in siunitx. To enable working with both packages easily, the macro \SendSettingsToPgf is available. It will set some commonly-used numerical formatting options in pgf to the current values used by siunitx to make using the two packages together more convenient for end users. This function can be used at any point after loading both the pgf and siunitx packages.

As group-four-digits is set to false per default there are no further adjustment needed in your example.

Code

\documentclass{article}

\usepackage{siunitx}
\usepackage{pgf}

\sisetup{
    group-digits=true,
    group-separator={\,},
%   group-four-digits=false,% default setting
}
\SendSettingsToPgf

\begin{document}
\begin{tabular}{rll}
siunitx: &\num{9000}                &\num{19000} \\
    pgf: &\pgfmathprintnumber{9000} &\pgfmathprintnumber{19000} \\
\end{tabular}
\end{document}

Output

Output of \SendSettingsToPgf

6
  • I saw that but thought it only applied for scientific notation... Thanks. Commented Dec 29, 2012 at 4:09
  • 6
    You might wan to use \SendSettingsToPgf to send the siunitx settings to pgf, as this deals with the various possibilities automatically without having to have the settings twice explicitly.
    – Joseph Wright
    Commented Dec 29, 2012 at 8:26
  • @Qrrbrbirlbel, the second method doesn't work for me. pgf seems to ignore siunitx settings. I have siunitx v2.5m and pgf v2.10.
    – Luigi
    Commented Dec 29, 2012 at 9:29
  • @Luigi I have used v2.5f in my answer. Though, I experience some inconsistency with v2.5m too. It seems, that not all settings are forwarded correctly, yes. Commented Dec 29, 2012 at 11:35
  • 1
    @Luigi I can confirm that \SendSettingsToPgf works again in v2.5n. Commented Dec 31, 2012 at 6:15

You must log in to answer this question.

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