我不知道我的代码出了什么问题。错误消息
Package PGF Math Error: Unknown function `red' (in '{ red,green,blue,purple
编译此代码时发生:
\documentclass{article}
\usepackage{tikz}
%% defining parallel looping
\pgfset{
foreach/parallel foreach/.style args={#1in#2via#3}{
evaluate=#3 as #1 using {{#2}[#3-1]}
},
}
\begin{document}
%% defining three array's
\newcommand{\myArrayI}{Marco,Andrea,Kiara,Carmen,Sebastian,Kurt}
\newcommand{\myArrayII}{33,26,2,45,18,41}
\newcommand{\myArrayIII}{red,green,blue,purple,yellow,black}
%% parallel looping
\foreach \ia [count=\cnt,
parallel foreach=\ib in \myArrayII via \cnt,
parallel foreach=\ic in \myArrayIII via \cnt] in \myArrayI
{
iteration \cnt: \ia, \ib, \ic \\
}
\end{document}
答案1
最后,我自己解决了这个问题。我只是在第三个数组中的每个元素周围添加了双引号,\myArrayIII
如下所示。
\newcommand{\myArrayIII}{"red","green","blue","purple","yellow","black"}
并且它成功了。完整代码请见此处:
\documentclass{article}
\usepackage{tikz}
%% defining parallel looping
\pgfset{
foreach/parallel foreach/.style args={#1in#2via#3}{
evaluate=#3 as #1 using {{#2}[#3-1]}
},
}
\begin{document}
%% defining three array's
\newcommand{\myArrayI}{Marco,Andrea,Kiara,Carmen,Sebastian,Kurt}
\newcommand{\myArrayII}{33,26,2,45,18,41}
\newcommand{\myArrayIII}{"red","green","blue","purple","yellow","black"}
%% parallel looping
\foreach \ia [count=\cnt,
parallel foreach=\ib in \myArrayII via \cnt,
parallel foreach=\ic in \myArrayIII via \cnt] in \myArrayI
{
iteration \cnt: \ia, \ib, \ic \\
}
\end{document}