I'm practicing using pin and marks on \coordinate and \node.
Goal/Expected output
- A regular polygon
- parametrized by the number of sides n
- with each vertex marked by a circular dot
- and a label outside the polygon.
\documentclass[dvisvgm]{standalone}
\usepackage{tikz}
\begin{document}
\newcommand\myR{2}
\newcommand\n{7}
\newcommand\dTheta{360/\n}
\tikzset{
every pin edge/.style={opacity=0},
pin distance=2pt,
mypt/.style={circle,fill=black,minimum size=0.5pt,inner sep=-2pt},
}
\begin{tikzpicture}
\foreach \k in {1,...,\n} {\coordinate[mypt,pin={\dTheta*\k}:{$V_{\k}$}] (V\k) at ({\dTheta*\k}:\myR);}
\foreach \k in {2,...,\n} {\draw (V\the\numexpr\k-1) -- (V\k);}
\draw (V\n) -- (V1);
\end{tikzpicture}
\end{document}
Problem
Why the technique of
\draw (1) \foreach \n in {2,...,5} {--(\n)} --cycle;
in this accepted answer doesn't work when I included the styles for a vertex mypt?
\documentclass[dvisvgm]{standalone}
\usepackage{tikz}
\begin{document}
\newcommand\myR{2}
\newcommand\n{7}
\newcommand\dTheta{360/\n}
\tikzset{
every pin edge/.style={opacity=0},
pin distance=2pt,
mypt/.style={circle,fill=black,minimum size=0.5pt,inner sep=-2pt},
}
\begin{tikzpicture}
\foreach \k in {1,...,\n} {\coordinate[mypt,pin={\dTheta*\k}:{$V_{\k}$}] (V\k) at ({\dTheta*\k}:\myR);}
\draw (V1) foreach \k in {2,...,\n} { -- (V\k)} -- cycle;
\end{tikzpicture}
\end{document}
Note that if I remove mypt, from the above code block, then the edges will be correctly drawn.
Related question: \foreach and names







myptis a node(styles for a node), so you create nodes instead of coordinates. Then you probably want(V1.center)and(V\k.center). But why create nodes? -and why use apin, when you do not want a pin? – hpekristiansen Jun 28 '22 at 00:32myptstyle overrides the\coordinatealias and forces the points to become nodes which means that the bug that Jasper links to comes into force. Also, - minor point - if you want to usepinwithout the edge then you should uselabel. – Andrew Stacey Aug 06 '22 at 07:13