[Tex/LaTex] Postprocessing pgfplotstable results using siunitx

pgfplotspgfplotstablesiunitx

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}

enter image description here

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}

enter image description here

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, {}, {}
 }

enter image description here

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:
enter image description here

Best Answer

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}

enter image description here

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}

enter image description here

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.

Related Question