Hi following on from the following question on multi-line headers with pgfplotstable, the solution was to set each affected cell individually. I decided to throw together a command to do that but keep hitting an the error Argument of \reserved@a has an extra }. <inserted text> \par
The snippet I'm using is attached below -
\DeclareRobustCommand{\pgfplotstableeach}[4][1]{
\foreach \col in {#1,...,#2}
\foreach \ro in {0,...,#3}
{\ifthenelse{\col=#2 \AND \ro=#3}{every row \ro\ column \col/.style=\{#4\}}{every row \ro\ column \col/.style=\{#4\},}}
}
and this works fine to produce the text outside a pgfplotstabletypeset
environment but fails inside one.
I've tried \newcommand
and \newcommand{\protect\pgfplotstableeach}{<macro>}
but neither works.
If I replace the macro with the text I want to input e.g. "every row 0 column 1/.style=..."
it fails with a Missing \endcsname inserted. <to be read again> \protect
. I actually thought this would be fairly straightforward but I'm completely bewildered by the error.
What am I doing wrong?
edited to include MWE below
\documentclass{article}
\usepackage{array,datatool,pgfplotstable}
\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}
\DeclareRobustCommand{\pgfplotstableeach}[4][1]{
\foreach \col in {#1,...,#2}
\foreach \ro in {0,...,#3}
{\ifthenelse{\col=#2 \AND \ro=#3}
{every row \ro\ column \col/.style=\{#4\}}
{every row \ro\ column \col/.style=\{#4\},}}
}
\begin{document}
\pgfplotstableread[col sep=comma,header=false]{sample.csv}\mystuff
\pgfplotstabletypeset[fixed,
\pgfplotstableeach{4}{4}{string type}]\mystuff
\end{document}
{...}
argument which you appear to be missing, apart from that it would be easier to understand the example if you posted a complete example from\documentclass
to\end{document}
showing the packages used and a test case for the construction.\foreach
loop works okay outside thepgfplotstabletypeset
environment. I think its described in the Tikz/PGF Manual on loops as a special case where two\foreach
commands are nested. (and I was being a bit lazy..)