I created a table of nodes using tikz. And now I want to draw a circle inside every even node. I started from just trying to draw a circle in the second node. But my code is not working:
\begin{center}
\begin{tikzpicture}[->,shorten >=1pt,auto]
\hashcells{12}
\foreach [count=\i from 0] \number in {0, 0, 1, 0, 1, 0, 0}{
\node at (hashcell\i) {\number};
\if \i==2
\draw [fill=yellow] (0,0) circle (0.1cm) node (sun) {};
\fi
}
\end{tikzpicture}
\end{center}
Whereas the code below works fine and draws a circle in the first node. So I suppose there is something wrong with my if
statement:
\begin{center}
\begin{tikzpicture}[->,shorten >=1pt,auto]
\hashcells{12}
\foreach [count=\i from 0] \number in {0, 0, 1, 0, 1, 0, 0}{
\node at (hashcell\i) {\number};
\draw [fill=yellow] (0,0) circle (0.1cm) node (sun) {};
}
\end{tikzpicture}
\end{center}
If someone can suggest what I am doing wrong I will be grateful.
Best Answer
Previous note: Please, next time provide a COMPLETE minimal working (or not) example: starting from
\documentclass...
and finishing with\end{document}
with all libraries and personal functions you use to test your code.Answer: I'm not sure about what you want to do but if you just want to add some
filled circles
to previous defined nodes you can do it outside theforeach
loop. Node names are known afterforeach
so you can make reference to them. There's no need forif
inside the loop to add color to a particular node. If you don't know the particular name or want tocalculate
it forget my answer.If you draw a filled circle at a node center you'll cover its contents, but you can use
backgrounds
library to add the filled circle behind the node. Both examples are shown in next code.Final note: I've suposed that
\hashcell
was related to your previous question Tikz: define label font size under the node