1

In the minimal example below, the commented out line does not work. Other lines work correctly. I can't understand what the reason is.

Here is a similar question, but my variable \im takes integer values.

\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
  • 2
    \im is a float, you can convert it to int with \pgfmathMod{\i}{5}\pgfmathint{\pgfmathresult} Commented Apr 10, 2024 at 9:41

1 Answer 1

1

If you add \show\im after the \edef, you'll see at the first cycle

> \im=macro: ->0.0. 

and

> \im=macro: ->1.0. 

at the second cycle. This cannot work with \ifthenelse, that expects integers.

Use \pgmathtruncatemacro{\im}{mod(\i,5)} instead.

\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} 

enter image description here

2
  • In general it is strange that the mod function returns a non integer value. But `\pgfmathtruncatemacro{\im}{mod(\i,5)}' works thank you very much. And here's another thing. Why are the blue circles drawn correctly \draw[blue] (u\im) circle (0.04);? Commented Apr 10, 2024 at 10:49
  • @kabenyuk The “mod” function can also be used with nonintegers. Commented Apr 10, 2024 at 13:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.