[Tex/LaTex] How to display decimal place in pgfplotstable when it is 0 (zero)

pgfplotstabletables

Using pgfplotstable I plot a table of data which has more decimal places than 1, however, I just want to display 1 decimal place so I am using precision=1, which works well, except for in cases where the decimal place is a 0. It does not display 14.0 but only 14 although I said precision=1.

Here is a MWE:

\documentclass{article}

\usepackage{mwe}
\usepackage{tikz,pgfplotstable}
\pgfplotsset{compat=newest}
\begin{document}
This is what I get from pgfplotstable:

\pgfplotstabletypeset[col sep=comma, row sep=\\,precision=1,column type={r}
    ]{
    a,     b,     c\\
17.82,  7.51,  7.62\\
17.02, 14.02, 12.01\\
19.43,  6.03,  4.52\\
18.03,  7.41,  6.81\\
}

This is what I want:

\begin{tabular}{rrr}
   a&   b&    c\\
17.8& 7.5&  7.6\\
17.0&14.0& 12.0\\
19.4& 6.0&  4.5\\
18.0& 7.4&  6.8\\
\end{tabular}
\end{document}

How to tell pgfplotstable to print the .0?

Best Answer

, , and use the same number-printing system and one can find a elaborated explanation in both and 's documents.

  • /pgf/number format/fixed rounds the number to a fixed number of digits after the period, discarding any trailing zeros.

    4.57     0     0.1     24,415.98     123,456.12

  • /pgf/number format/fixed zerofill={⟨boolean⟩} enables or disables zero filling for any number drawn in fixed point format.

    4.57     0.00     0.10     24,415.98     123,456.12

  • /pgf/number format/sci configures \pgfmathprintnumber to display numbers in scientific format, that means sign, mantissa and exponent (base 10). The mantissa is rounded to the desired precision (or sci precision, see below).

    4.57·100     5·10-4     1·10-1     2.44·104     1.23·105

  • /pgf/number format/sci zerofill={⟨boolean⟩} enables or disables zero filling for any number drawn in scientific format.

    4.57·100     5.00·10-4     1.00·10-1     2.44·104     1.23·105

  • /pgf/number format/zerofill={⟨boolean⟩} sets both fixed zerofill and sci zerofill at once.

Read the document for more options.

For your case, writing

\pgfplotstabletypeset[col sep=comma, row sep=\\,precision=1,
                      fixed zerofill, column type={r}]

will do the job.

Related Question