I'm trying to use styles to generate TikZ figures that have repeated, regularly spaced elements by looping through an array, but am perplexed by the results I'm getting.
For example, if I define the style
state/.style={circle,draw=none,inner sep=0pt,minimum size=7mm,label=center:$#1$,name=#1}
then when I try to iterate through an array as the source of the arguments to the style, as in
\def\labels{{e,a,a^2,a^3}};\def\dim{4};
\foreach \n in {0,1,2,3} {
\node[state={\labels[\n]}]at({cos(90+\n*(360/\dim))},{sin(90+\n*(360/\dim))}){};}
I get an error: Package pgf Error: No shape named e is known.
If I change around the definition of the array and the iterator(s)a bit,
\def\nodes{0/{e},1/{a},2/{a^2},3/{a^3}};\def\dim{4};
\foreach \n\lab in \nodes{
\node[state={\lab}]at({cos(90+\n*(360/\dim))},{sin(90+\n*(360/\dim))}){};}
I can get the result I want (see MWE), but I'd rather not do this, as it requires an array structure that's not generally useable for my purposes.
How can I get the first form of the iterator and array to work?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{petri}
\begin{document}
\tikzset{
redarrow/.style={->, red, fill=none,>=stealth, thick},
state/.style={circle,draw=gray,inner sep=0pt,minimum size=7mm,label=center:$#1$,name=#1}}
\begin{center}
\begin{tikzpicture}
% This approach results in an error
% \def\labels{{e,a,a^2,a^3}};\def\dim{4};
% \foreach \n in {0,1,2,3} {
% \node[state={\labels[\n]}]at({cos(90+\n*(360/\dim))},{sin(90+\n*(360/\dim))}){};}
\def\nodes{0/{e},1/{a},2/{a^2},3/{a^3}};\def\dim{4};
\foreach \n\lab in \nodes{
\node[state={\lab}]at({cos(90+\n*(360/\dim))},{sin(90+\n*(360/\dim))}){};}
\draw[redarrow](e)--(a);\draw[redarrow](a)--(a^2);\draw[redarrow](a^2)--(a^3);\draw[redarrow](a^3)--(e);
\end{tikzpicture}
\end{center}
\end{document}