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:
Best Answer
You don't need the
siunitx
syntax.pgfplotstable
also works with thepgfmath
module and has a very strong number formatting ability. You can find it pgfplotstable manual for more information and it works well withsiunitx
. Example,After the edit, it is NOT the
sci
butstd
number format you are looking for. Let me reemphasize that you should not remove zero exponent from scientific notation. Then the example becomesTo 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.