0

I want to draw a cycle with 12 vertices, and the circle's style is a regular 12-sided polygon, so I use the following code:

\documentclass[tikz, border=1mm]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}
  \node[regular polygon, regular polygon sides=12, draw, minimum size=6cm] 
  (outer_poly) {};
  \foreach \n in {1,...,12}
  {
    \fill (outer_poly.corner \n) circle (5pt)  {};
  }
\end{tikzpicture}
\end{document}

I want to change the vertices with odd-numbered indices to squares, and I do not how to change.

\documentclass[tikz, border=1mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
  \tikzset{bluenode/.style={fill=blue, draw=blue, shape=rectangle, minimum 
  size=0.15cm, inner sep=4pt}};
  \node[regular polygon, regular polygon sides=12, draw, minimum size=3cm] 
  (outer_poly)  {};
  \foreach \i in {1,...,12}
  {
     \ifodd\i % test if i odd or even 
            \fill (outer_poly.corner \i) circle (2pt); % I want to change the style of bluenode!
        \else          
            \fill (outer_poly.corner \i) circle (2pt);
        \fi
    }
\end{tikzpicture}
\end{document}
 

I want to draw it in the following style:

![enter image description here

1
  • 2
    Instead of inserting a circle at vertex position, insert a node and fill it.
    – Sigur
    Mar 22 at 12:25

1 Answer 1

3

For example, with a couple of styles:

\documentclass[tikz, border=1mm]{standalone}
\usetikzlibrary{shapes.geometric}

\tikzset
{
  node 0/.style={minimum size=5pt,circle,fill=black},
  node 1/.style={minimum size=5pt,rectangle,fill=blue},
}

\begin{document}
\begin{tikzpicture}
  \node[regular polygon, regular polygon sides=12, draw, minimum size=6cm] 
  (outer_poly) {};
  \foreach \n in {1,...,12}
     \pgfmathtruncatemacro\i{mod(\n,2)}
     \node[node \i] at (outer_poly.corner \n) {};
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .