I'm trying to programmatically set the style of the columns of a TikZ matrix. My attempt is the following:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\tikzstyle{mymatrix}=[draw]
\foreach \c [count=\i] in {red, green, blue} {
\globaldefs=1 % make tikz style global
\tikzset{mymatrix/.append style={column \i/.style={nodes={fill=\c}}}}
}
\matrix (m) [matrix of nodes, mymatrix] {
1 & 2 & 3 & 4 \\
5 & 6 & 8 & 8 \\ };
\end{tikzpicture}
\end{document}
Unfortunately, this code does not compile because the commands \i
and \c
are undefined. My guess is that the style inside the for-loop has to be expanded inside the for-loop, but I don't know how to do this. Any ideas?