
아래의 최소 예에서는 주석 처리된 행이 작동하지 않습니다. 다른 라인은 올바르게 작동합니다. 이유가 무엇인지 이해할 수 없습니다.
여기비슷한 질문이지만 내 변수는 \im
정수 값을 사용합니다.
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usepackage{ifthen}
\begin{document}
\begin{tikzpicture}
\def\m{12}
\def\n{13}
\foreach \i in {0,...,\m}{\coordinate[label=] (u\i) at (360*\i/\n:1);}
\foreach \i in { 0,...,\m}{%
\pgfmathMod{\i}{5}\edef\im{\pgfmathresult}
\draw[blue] (u\im) circle (0.04);
\ifthenelse{\i =0}{ }{\draw[red,fill] (u\i) circle (0.02);}
%\ifthenelse{\im=0}{ }{\draw[green,fill] (u\i) circle (0.01);}
}
\end{tikzpicture}
\end{document}
답변1
\show\im
뒤에 추가하면 \edef
첫 번째 사이클에 표시됩니다.
> \im=macro:
->0.0.
그리고
> \im=macro:
->1.0.
두 번째 사이클에서. \ifthenelse
정수가 필요한 에서는 작동하지 않습니다 .
대신 사용하세요 \pgmathtruncatemacro{\im}{mod(\i,5)}
.
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usepackage{ifthen}
\begin{document}
\begin{tikzpicture}
\def\m{12}
\def\n{13}
\foreach \i in {0,...,\m}{\coordinate[label=] (u\i) at (360*\i/\n:1);}
\foreach \i in { 0,...,\m}{
\pgfmathtruncatemacro{\im}{mod(\i,5)}
\draw[blue] (u\im) circle (0.04);
\ifthenelse{\im=0}{}{\draw[green,fill] (u\i) circle (0.01);}
}
\end{tikzpicture}
\end{document}