8

I have a csv file with percentages to load into a pgfplotstable. I already format them with siunitx but I did not find a possibility to shift the decimal point (multiply by 100) to get percentage numbers.

Here is a MWE:

\documentclass[12pt]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\begin{document}

\begin{filecontents}{data.csv}
0.563725,0.819520,0.713402
0.563725,0.819520,0.713402
\end{filecontents}

\sisetup{
  round-mode          = places,
  round-precision     = 2,
}
\pgfplotstabletypeset[ 
      col sep=comma,
      display columns/0/.style={column type={S},string type},
      display columns/1/.style={column type={S},string type},
      display columns/2/.style={column type={S},string type}
    ]{data.csv}
\end{document}
0
5

You can apply a preprocessing operation to the typeset definition:

\pgfplotstabletypeset[ 
   col sep=comma,
   columns/0/.style={preproc/expr={100*##1}},
   columns/1/.style={preproc/expr={100*##1}},
   columns/2/.style={preproc/expr={100*##1}},
]{data.csv}

See the PgfplotsTable manual, section "Preprocessing Cell Content".

5

Despite the accepted answer, I found another solution by using the built in style attribute multiply with:

\pgfplotstabletypeset[ 
  col sep=comma,
  display columns/0/.style={column type={S},string type,multiply with=100},
  display columns/1/.style={column type={S},string type,multiply with=100},
  display columns/2/.style={column type={S},string type,multiply with=100}
]{data.csv}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.