# Postprocessing pgfplotstable results using siunitx

I am trying to use the \num command from siunitx inside a table made with pgfplotstable, because I need the format given by siunitx with \sisetup{scientific-notation = true} and all the advantages of pgfplotstable. My base code is

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\pgfplotsset{compat=1.8}
\usepackage{booktabs}
\usepackage{colortbl}
\begin{document}
\sisetup{scientific-notation = true}%

\vspace{3ex}
\pgfplotstabletypeset[col sep=comma,trim cells=true,
% dec sep align=S,
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
%%
columns/Variable/.style={string type, column name=Quantity},
%
columns/error/.style={numeric type,dec sep align}
]{
Variable,           error,  IS value,   custom units value,
mass error,         6.124218320291899e-16,  {}, {}
omega error,        {}, {}, {}
J error,            0.387621076355607,  {}, {}
%Mb error           Indeterminate,  {}, {}, {}
Mbnew error,        0.21146255277063972,    {}, {}
Mp error,           0.21146255277063972,    {}, {}
Ebind error,        0.6604389526233243, {}, {}
}
\end{document}


but when I try to postprocess the numeric data with this

 \sisetup{scientific-notation = true}%

\pgfplotstabletypeset[col sep=comma,trim cells=true,
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
%%
columns/Variable/.style={string type, column name=Quantity},
%
columns/error/.style={numeric type,%dec sep align,
%preproc cell content/.append style={column type=S},
postproc cell content/.append style={
/pgfplots/table/@cell content/.add={$\num{}{}$}},
%postproc cell content/.append style={
%/pgfplots/table/dec sep align={@}
%},
%postproc cell content/.append style={dec sep align=true
%}
%}
}
]{
Variable,           error,  IS value,   custom units value
mass error,         6.124218320291899e-16,  {}, {}
omega error,        {}, {}, {}
J error,            0.387621076355607,  {}, {}
%Mb error,          Indeterminate,  {}, {}, {}
Mbnew error,        0.21146255277063972,    {}, {}
Mp error,           0.01146255277063972,    {}, {}
Ebind error,        0.6604389526233243, {}, {}
}
\num{0.001}
\end{document}


the numbers are clearly not processed by \num{} and I have to comment the dec sep align option to avoid errors. Any idea on how to combine these two tools? The reason to need num{} is that the sci option of pgfplotstable gives ugly 10^0 terms, as can be seen in

 \pgfplotstabletypeset[col sep=comma,trim cells=true,
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
%%
columns/Variable/.style={string type,  column name=Quantity},
%
columns/error/.style={numeric type,dec sep align,sci,zerofill
}
]{
Variable,          error,  IS value,   custom units value
mass error,        6.124218320291899e-16,  {}, {}
Ebind error,       0.6604389526233243, {}, {}
Ebind2 error,      1.6604389526233243, {}, {}
}


and the default numeric format is not able to convert 0.1234 into 1.234, so the numbers are not homogeneously formatted. What I need would look like that the following:

• When trying to run your MWE as posted here I get the error that the numbers could not be parsed (just get NaN in the table). Apr 17, 2013 at 17:26
• I think the error is due to the fact that the tabs get lost when posting the code on TeX.sx. Javier, could you replace all the tabs in your table with commas, and use col sep=comma instead? Then the code should be robust for posting.
– Jake
Apr 17, 2013 at 17:32
• Could you add the exact layout or rules about it how which numbers should be printed (or the equivalent of a (manually typed) table with S columns)? Take a look at this answer of mine which used siunitx’s S column (quite painfully as, in that case, it could be done much better with percusse’s dec sep align key). Apr 17, 2013 at 18:23

You don't need the siunitx syntax. pgfplotstable also works with the pgfmath module and has a very strong number formatting ability. You can find it pgfplotstable manual for more information and it works well with siunitx. Example,

\documentclass{article}
\usepackage{pgfplotstable,siunitx,booktabs,colortbl}
\begin{document}

\pgfplotstabletypeset[col sep=comma,trim cells=true,
every even row/.style={
before row={\rowcolor[gray]{0.9}}},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/Variable/.style={string type, column name=Quantity},
columns/error/.style={numeric type,sci,precision=2,zerofill,dec sep align}
]{
Variable,            error,   IS value,    custom
mass error,          6.124218320291899e-16,    {},  {}
omega error,                              ,    {},  {}
J error,             0.387621076355607    ,    {},  {}
Mbnew error,         0.21146255277063972  ,    {},  {}
Mp error,            0.01146255277063972  ,    {},  {}
Ebind error,         0.6604389526233243   ,    {},  {}
}

\end{document}


After the edit, it is NOT the sci but std number format you are looking for. Let me reemphasize that you should not remove zero exponent from scientific notation. Then the example becomes

\documentclass{article}
\usepackage{pgfplotstable,booktabs,colortbl}

\begin{document}

\pgfplotstabletypeset[col sep=comma,trim cells=true,
every even row/.style={before row={\rowcolor[gray]{0.9}}},
every head row/.style={before row=\toprule, after row=\midrule},
every last row/.style={after row=\bottomrule},
columns/Variable/.style={string type, column name=Quantity},
columns/error/.append style={std=0,dec sep align,zerofill},
]{
Variable,            error       ,   IS value,   custom
mass error,          6.124218320291899e-16,         {},   {}
omega error,                              ,         {},   {}
J error,             1.387621076355607    ,         {},   {}
Mbnew error,         2.1146255277063972   ,         {},   {}
Mp error,            0.01146255277063972  ,         {},   {}
Ebind error,         0.6604389526233243   ,         {},   {}
}

\end{document}


To be honest, if this is going to be a long and involved table, you would be torturing the reader by omitting the exponent and having the ragged look.

• Ah! You might emphasize more on the key dec sep align which is key here (and a key from the pgfplotstable package itself and not a standard /pgf/number format key)! No wonder I couldn’t find an appropriate key in the PGF manual. Though, it seems not that flexible as the S column. Apr 17, 2013 at 17:56
• The fundamental problem is that the format given by sci together with dec sep align for a number like 1.2345 is 1.234·10^0 what is what I need to avoid. I need avoid it at the same time as having 0.12345 written as 1.2345·10^{-1}. I have not found a way to avoid the 10^0 term in the pgfplotstable manual other than using the postprocessing. And I don't really know why it doesn't seem to work with the \num command from siunitx. Actually, the code /pgfplots/table/@cell content/.add={$\num{}{}$}} from the first example is not even the first guess from what the manual says Apr 17, 2013 at 18:16
• Thanks! std=0 is indeed what I needed. I appreciate the comments on the scientific notation, though. I simply want to suppress it because I do not recall seeing it often at all. Do you happen to know of some scientific journal where keeping the $10^0$ is actually encouraged? Apr 17, 2013 at 19:34
• @JavierE.Cuchí It's actually the standard itself. So the journals should encourage it regardless but let's not go into the journal quality etc. :) Apr 17, 2013 at 19:48