此代码绘制了易经:
\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. [}]
错误。我该怎么办?