I have two questions concerning pgfplotstable and number formatting with pgf.
Consider the following piece of code:
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{amsmath}
\begin{document}
\pgfplotstableread{
A B C
1.1 12 1300000
21.1 200000 214300000
}\mytable
\pgfplotstabletypeset[columns={A, B, C},
columns/A/.style={postproc cell content/.append style={
/pgfplots/table/@cell content/.add={}{ s}}, fixed zerofill, precision=1
},
columns/C/.style={postproc cell content/.append style={
/pgfplots/table/@cell content/.add={}{ s${}^{-1}$}}, fixed zerofill, precision=1
}
]\mytable
\end{document}
I would like to:
- align the content of the column A at the decimal separator (obviously I've tried
dec sep align
but the it messes up with thepostproc cell content
(it adds the " s" before the dec sep "." – e.g. : 21 s.1 s), other than that it aligns fine, - print the number using engineering notation (the powers of ten must be multiples of three) for the column B – e.g. :
$200\:\cdot\:10^{3}$
instead of$2\:\cdot\:10^{5}$
) - do all these for the column C: append content, print using engineering notation, align on the
\cdot
of the engineering notation (likesci sep align
)
Do you know some way(s) to achieve any of those goals ?
EDIT
Thanks to Jake's answer, I've got almost what I want, however I have one last problem with siunitx. The following piece of code compiles (note the alias
to make it compile, otherwise siunitx fails..)
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\pgfplotstableset{
alias/as/.initial=d,
}
\pgfplotstableread{
d
7000000
}\loadedtable
\pgfplotstabletypeset[columns={as},
columns/as/.style={
column name={$2 \times 3d$},
}
]\loadedtable
\end{document}
This next piece doesn't:
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\pgfplotstableset{
alias/as/.initial=d,
}
\pgfplotstableread{
d
7000000
}\loadedtable
\pgfplotstabletypeset[columns={as},
columns/as/.style={
column name={$2 \times 3d$},
column type={S[round-mode=places, round-precision=1, scientific-notation=engineering, table-format=5.1e1, exponent-product = \cdot]},
string type
}
]\loadedtable
\end{document}
How to avoid siunitx parse the headers ? (that would also, I guess, make it possible to use column identifiers with the letters 'e' and 'd')
Best Answer
You could let
siunitx
take care of the of the alignment and of formatting the numbers: Since version 2.4,siunitx
can format numbers to engineering notation.May I suggest a slight alteration to your table setup? Instead of repeating the unit symbol with each value, I would put it into the header. Here's one example of how that can be accomplished. I've also used the
booktabs
package to make the table a bit easier to grasp:To stop
siunitx
from trying to parse the column names, issue the keymulticolumn names
. This will wrap the cells in the head row in\multicolumn{1}{c}{<column name>}
, which protects them.