I'm trying to color a cell using its data value. However, when I try to compute some value (using the content of the cell) then the definition of the color color!\somemacro in the \cellcolor does not work. Where the \somemacro stores the result of the computation.
The error I got is:
! Undefined control sequence. blue!\y
Why is this happening? I guess that the problem has to do with the expansion part of the macros, but I don't know how this works. Can someone also explain how/why this happens and how to avoid it?
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{pgfplotstable}
\pgfplotstableset{
color cells/.style={
col sep=comma,
string type,
postproc cell content/.code={%
\pgfkeysalso{@cell content=\rule{0cm}{2.4ex}%
\pgfmathsetmacro\y{round(##1 * 0.5)}\cellcolor{blue!\y}%
##1}%
}
}
}
\begin{document}
\begin{table}\caption{Colors}
\centering
\pgfplotstabletypeset[color cells]{
a,b,c,d
50,300,200,100
20,0,100,200
}
\end{table}
\end{document}

\edefmakes the\tempmacro to expand to what's inside it when call it, and the\noexpandmakes it print the\cellcolorinto the global macro, and the\ymacro will expand as expected. Did I get it right? I was trying to achieve that behavior but didn't know how. I try putting a naive\expandbut didn't work. – adn May 08 '12 at 12:15