4

In the code below, one of the edge enters into the circle of vertex 1. How to modify this code.

\documentclass[tikz,margin=5pt]{standalone}

\begin{document}
\begin{tikzpicture} 
\foreach \n [count=\i] in {3,4,5} {
    \pgfmathsetmacro{\nfold}{360/\n}
    \begin{scope}[xshift=5*\i cm]
    \begin{scope}[rotate=-60-\nfold]
    \foreach \rot in {1,2,...,\n} { 
        \pgfmathsetmacro{\next}{\rot*\nfold +\nfold}
        \draw[very thick] (\next:1.5)  --(\rot*\nfold:1.5);
        \draw[black,fill=black]  (\rot*\nfold:1.5) circle (0.08);
        \node[inner sep=1pt, fill=white, circle, draw=black] at (\rot*\nfold:1.5) {\rot}; 
    }
      \end{scope}
    \node[below] at (0,-2.) {$C_{\n}$};
    \end{scope}
}
\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    I'd draw the nodes first and then draw the edges between the names of the notes (remember to name your nodes). The problem here is the timing of the elements. There is probably also some leayer feature one use, just don't know the code for it.
    – daleif
    Feb 28 at 10:23
  • 2
    So basically split the inner foreach into two foreach, first defines and names all the nodes. The second draws the edges. Then because it is nodes you draw between and not points (draw between the node names) the lines will go from edge to edge
    – daleif
    Feb 28 at 10:25

1 Answer 1

4
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture} 
\foreach \n [count=\i] in {3,4,5}{
\pgfmathsetmacro{\nfold}{360/\n}
\begin{scope}[xshift=5*\i cm]
\begin{scope}[rotate=-60-\nfold]
\foreach \rot in {1,2,...,\n} 
  \draw[very thick] (\rot*\nfold+\nfold:1.5) -- (\rot*\nfold:1.5);
\foreach \rot in {1,2,...,\n}
  \node[inner sep=1pt, fill=white, circle, draw] at (\rot*\nfold:1.5) {\rot}; 
\end{scope}
\node[below] at (0,-2.) {$C_{\n}$};
\end{scope}
}
\end{tikzpicture}
\end{document}

Triangle square and pentagon with numbers at nodes

0

You must log in to answer this question.

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