如何让 TikZforeach
循环连续迭代两个列表?我曾希望在下面的代码中,表达式的\firstlist,\secondlist
计算结果为2,3,5,7,1,4,6
,但它不起作用。我尝试过温和的变体,如{\firstlist,\secondlist}
和\firstlist\secondlist
,但没有成功。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\def\firstlist{2,3,5,7}
\def\secondlist{1,4,6}
\begin{tikzpicture}
\foreach\x in \firstlist,\secondlist
\node[shape=circle,draw=black] at (\x,0) {\x};
\end{tikzpicture}
\end{document}
答案1
您还可以使用\newforeach
:
\usepackage{tikz}
\usepackage{loops}[2013/05/01]
\begin{document}
\def\firstlist{1,3,...,9}
\def\secondlist{2,4,...,10}
\begin{tikzpicture}
\newforeach[expand list] \x in {\firstlist,\secondlist}
\node[shape=circle,draw=black] at (\x,0) {\x};
\end{tikzpicture}
\end{document}