I'd like some help to make a conditional statement in LaTeX and TikZ work. In this M(non-)WE, I'd like the first, third and fifth dots to be larger:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\def\bigdot{5pt}
\def\littledot{1pt}
\begin{centering}
\begin{tikzpicture}
\foreach \x in {0,...,5}{
\draw (\x,0) circle ({int(\x/2)==0?\bigdot:\littledot});
}
\end{tikzpicture}
\end{centering}
\end{document}
What am I not understanding? Thanks for any help or advice.
Best Answer
Welcome! Are you looking for
iseven
?In your code you are asking to make the circles for which
int(\x/2)
is zero big. These are the circles at\x=0
and\x=1
, and this is what you get. However, if you want to have "the first, third and fifth dots to be larger" in a list{0,...,5}
then you can make the dots larger for which\x
is even.ADDENDUM: As for the different question raised in the comments, you can use
mod
, as suggested by AlexG, orMod
, which always returns nonnegative values and helps you to avoid confusion (at least I occasionally wasted a lot of time because I was usingmod
). Both versions are described on p. 1033 of pgfmanual v3.1.5. As above, I prefer the non-deprecated syntaxover the older, deprecated syntax
so the proposal for the question in the comments could be
Note also that if you use
\documentclass[tikz]{standalone}
thentikz
gets automatically loaded, so\usepackage{tikz}
is unnecessary. Also, I generally do not really like\def
s but if you want to use them, use them locally, i.e. inside thetikzpicture
, as above. Yet personally I'd use something like