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.
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\begin{document}
\pgfplotstableread{
A B C
1.1 12 1300000
21.1 200000 214300000
}\mytable
\pgfplotstabletypeset[columns={A, B, C},
columns/A/.style={
column type={S[table-format=2.1]},
string type,
postproc cell content/.append style={
/pgfplots/table/@cell content/.add={}{\,s}
}
},
columns/B/.style={
column type={S[round-mode=figures, round-precision=3, scientific-notation=engineering, table-format=3e1]},
string type,
postproc cell content/.append style={
/pgfplots/table/@cell content/.add={}{\,\si{\per\second}}
}
},
columns/C/.style={
column type={S[round-mode=figures, round-precision=3, scientific-notation=engineering, table-format=5.2e1]},
string type,
postproc cell content/.append style={
/pgfplots/table/@cell content/.add={}{\,s}
}
},
]\mytable
\end{document}
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:
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\pgfplotstableread{
A B C
1.1 12 1300000
21.1 200000 214300000
}\mytable
\pgfplotstabletypeset[columns={A, B, C},
columns/A/.style={
column type={S[table-format=2.1]},
string type
},
columns/B/.style={
column type={S[round-mode=figures, round-precision=3, scientific-notation=engineering, table-format=3e1]},
string type
},
columns/C/.style={
column type={S[round-mode=figures, round-precision=3, scientific-notation=engineering, table-format=3.2e1]},
string type
},
every head row/.style={
before row={\toprule},
after row={\si{\second} & \si{\per\second} & \si{\second}\\ \midrule}
},
every last row/.style={after row=\bottomrule}
]\mytable
\end{document}
To stop siunitx
from trying to parse the column names, issue the key multicolumn names
. This will wrap the cells in the head row in \multicolumn{1}{c}{<column name>}
, which protects them.
\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\pgfplotstableread{
d
7000000
}\loadedtable
\pgfplotstabletypeset[
multicolumn names,
columns/d/.style={
column name=$\gamma \times \epsilon$,
column type={
S[
round-mode=places,
round-precision=1,
scientific-notation=engineering,
table-format=1.1e1,
exponent-product = \cdot
]
},
string type
}
]\loadedtable
\end{document}
You have to first clear the column type defaults and then say, use tabularx
type of table. That needs two additional options to change the default table commands. The rest is using rules at the bottom and up.
\documentclass{article}
\usepackage{pgfplotstable,tabularx,booktabs}
\begin{document}
\noindent%
\pgfplotstabletypeset[column type=,
begin table={\begin{tabularx}{\textwidth}{X c c c}},
end table={\end{tabularx}},
columns/Species/.style={string type},
every head row/.style={before row=\toprule},
every last row/.style={after row=\bottomrule},
]{
Species {Moles (1)} {Moles (2)} {Moles (3)}
Ca++ 1.8887e-4 1.9476e-4 3.4462e-2
CaCl+ 3.7537e-5 3.8262e-5 6.7001e-3
CaCl2(aq) 7.2626e-6 7.3202e-6 1.2881e-3
CaCO3(aq) 6.6707e-6 2.1461e-11 6.5734e-6
Cl- 1.9999e+0 1.9999e+0 1.9904e+0
CO2(aq) 9.8315e-8 7.5467e-1 7.4064e-1
H+ 4.6749e-10 8.7625e-4 1.7078e-5
H2O(l) 5.5508e+1 5.5434e+1 5.5391e+1
HCO3- 4.2763e-4 1.7492e-3 8.8265e-2
Mg++ 1.6018e-4 1.6223e-4 1.3874e-3
MgCl+ 3.3875e-5 3.3911e-5 2.8623e-4
MgCO3(aq) 2.0802e-6 1.0114e-11 9.8367e-8
Na+ 2.0000e+0 2.0000e+0 2.0000e+0
OH- 4.2783e-4 2.3555e-10 1.1323e-8
}
\end{document}
Best Answer
The error for the A and B column comes from the fact that
pgfplotstables
expects numerical data unless specified otherwise. To make the column handle strings, you have to setcolumns/colnames/.style={string type}
.To get the index to start at one, I would suggest to create a new column on the fly and using this for the column names with the key
colnames from=<name>
.Here's an MWE: