在 foreach 循环中使用 tkz-euclide 发出标签点

在 foreach 循环中使用 tkz-euclide 发出标签点

我希望显示一些编号的球,但不知何故,无论是由于我误用了 tkz-euclide 还是 foreach,我都无法正确标记球。

这是一个 MWE。

\documentclass{article}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\tkzDefPoints{0/0/B1, 2/0/B2, 4/0/B3, 6/0/B4}
\tkzDefPoints{1/1.732/B5, 5/1.732/B6}
\foreach \color/\numero [count=\index] in {blue/1, orange/2, orange/1, green/1, orange/3, blue/2} {
    \tkzDrawCircle[R, color=black, fill=\color!40](B\index, 1cm)
    \tkzLabelPoint[anchor=center](B\index){\numero}
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

您应该避免使用诸如 之类的宏\color,它在内部处理颜色时用作循环变量。如果您改用 eg \coloro,则没有问题。

\documentclass{article}
\usepackage{tkz-euclide}
\begin{document}
\begin{tikzpicture}[scale=0.5]
\tkzDefPoints{0/0/B1, 2/0/B2, 4/0/B3, 6/0/B4}
\tkzDefPoints{1/1.732/B5, 5/1.732/B6}
\foreach \coloro/\numero [count=\index] in {blue/1, orange/2, orange/1, green/1, orange/3, blue/2} {
    \tkzDrawCircle[R, color=black, fill=\coloro!40](B\index, 1cm)
    \tkzLabelPoint[anchor=center](B\index){\numero}
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容