![\foreach 可以处理列表列表吗?](https://linux22.com/image/317123/%5Cforeach%20%E5%8F%AF%E4%BB%A5%E5%A4%84%E7%90%86%E5%88%97%E8%A1%A8%E5%88%97%E8%A1%A8%E5%90%97%EF%BC%9F.png)
此代码绘制了易经:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\usepackage{ifthen}
\begin{document}
\begin{tikzpicture}
\tikzset{
hexagram/.pic={
\foreach \d [count=\n] in {#1}{
\ifthenelse{\d=0}
{\draw [yshift=\n*2cm, line width=1cm, purple] (-6,0) -- (-1,0) (1,0) -- (6,0);}
{\draw [yshift=\n*2cm, line width=1cm, purple] (-6,0) -- (6,0);}
}}
}
\pic at (15,0) {hexagram = {0,0,0,0,0,0}};
\end{tikzpicture}
\end{document}
当我尝试用绘制所有剩余的 63 个卦时,foreach
我得到了一个错误,好像foreach
无法处理元素为列表的列表:用以下行替换
\pic at (15,0) {hexagram = {0,0,0,0,0,0}};
比如说,
\foreach [count=\n] \m in {{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1},
{0, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 1, 1},
{0, 0, 0, 1, 0, 0},
{0, 0, 0, 1, 0, 1},
{0, 0, 0, 1, 1, 0},
{0, 0, 0, 1, 1, 1}}{
\pic at (\n*15,0) {hexagram = \m};
}
我获得了
./iching2.tex:28: Missing = inserted for \ifnum. [}] ./iching2.tex:28: Missing number, treated as zero. [}]
错误。我该怎么办?