The key idea is to use
a preprocessing style which multiplies the values by 100
a postprocessing style which appends the percent sign
However, the postprocessing style is applied to two cells because dec sep align
creates two artifical cells. The manual states that \pgfplotstablepartno
can be used to identify which part is currently being postprocessed. A complete solution could be
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstabletypeset[
columns/A/.style={
column type=r,
dec sep align,
preproc/expr={100*##1},
postproc cell content/.append code={
\ifnum1=\pgfplotstablepartno
\pgfkeysalso{@cell content/.add={}{\%}}%
\fi
},
fixed,
fixed zerofill,
},
]
{
A
0.01
1
0.1234
0.5
}
\end{document}
As pgfplotstable
does not yet support multiline headers, you need to format the cells on these rows specially. I couldn't get the row styles to do this for me, so ended up formatting each individual cell:
\documentclass{article}
\usepackage{array,datatool,pgfplotstable}
\pgfplotsset{compat=1.6}
\begin{filecontents}{sample.csv}
item,2008,2009,2010,2011
,Actual,Actual,Forecast,Forecast
,GBP,GBP,GBP,GBP
,('000),('000),('000),('000) rounded
Area 1 OP, 1000000,1500000,1750000,250000
Area 2 OP, 400000,500000, 450000,-50000
Area 51 OP, 300000,375000,390000,15000
No P, 1250000, 1000000, 950000, 50000
Residuals, 800000, 80000, 90000, 10000
\end{filecontents}
\pgfplotstableread[col sep=comma]{sample.csv}\mystuff
\begin{document}
\pgfplotstabletypeset[
fixed,
display columns/0/.style={string type},
every row 0 column 1/.style={string type},
every row 0 column 2/.style={string type},
every row 0 column 3/.style={string type},
every row 0 column 4/.style={string type},
every row 1 column 1/.style={string type},
every row 1 column 2/.style={string type},
every row 1 column 3/.style={string type},
every row 1 column 4/.style={string type},
every row 2 column 1/.style={string type},
every row 2 column 2/.style={string type},
every row 2 column 3/.style={string type},
every row 2 column 4/.style={string type}]\mystuff
\end{document}
Note that I have specified fixed
for the default cell formatting. Your original attempt could have just been styled with a singel string type
rather than specifying this for each individual column.
Best Answer
This answer is heavily inspired from Create a contingency table using pgfplotstable (I even stole the example table). For the second part (only treat some columns) it borrows from How to mark/label nth data point from file in pgfplots?.
The basic idea is: It is relatively easy to add columns to a table with entries computed from other columns, but it is not possible to add rows. Thus, we transpose, then add columns, then we transpose again. Since selecting a subset of the columns may not be what everyone needs, the below solution contains a macro
\addstatistics
that adds sum, mean and standard deviation for all columns as well as a macro\addsomestatistics
that accepts as a third argument a list of columns (numbers between 0 and the number of data columns minus one in the tikzforeach
list format). The first two arguments in both cases are the table and the name of the label column. See the code for examples how to use it.