[Tex/LaTex] Tikz: draw a circle only in selected nodes

conditionalsdiagramstikz-pgf

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 the foreach loop. Node names are known after foreach so you can make reference to them. There's no need for if inside the loop to add color to a particular node. If you don't know the particular name or want to calculate 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

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{backgrounds}
\tikzset{
  cell/.style = {draw, minimum width=0.5cm, minimum height=0.5cm, minimum size = 0.5cm}
}


\begin{document}

\begin{tikzpicture}

\foreach [count=\i from 0] \j  in {1,...,7} {
    \node[cell,label=below:{\scriptsize \i}] (cell\i) at (\i*0.5,0) {};}

\foreach [count=\i from 0] \number in {0, 0, 1, 0, 1, 0, 0}{
              \node at (cell\i) {\number};
              }

               \draw [fill=yellow] (0,0) circle (0.2cm) node (sun) {};

    \begin{scope}[on background layer] 
              \draw [fill=yellow] (cell2.center) circle (0.2cm) node (sun) {};
    \end{scope}

\end{tikzpicture}
\end{document}

enter image description here