I am trying to draw just the nodes (no sides) at the vertices of a regular hexagon. This answer should be easily modified to accomplish what I want, but I am such a novice that I have difficulty understanding the example. Ideally, each vertex would be a separate named node so that I can easily draw edges between them (I will be making several different graphs using these same nodes).
[Tex/LaTex] Draw Vertices of Regular Polygon
asymptotediagramspstrickstikz-pgf
Related Solutions
Here's a simple hack that redefines the naming code inside the scope to append a prefix. You can't use a .
as a separator though as that would confuse the parser. I've used a space, but you could use something else (some punctuation, such as .
is special, there's a list somewhere here).
\documentclass{article}
%\url{http://tex.stackexchange.com/q/128049/86}
\usepackage{tikz}
\begin{document}
\tikzstyle{vertex}=[circle,draw,fill=black!20]
\makeatletter
\tikzset{%
prefix node name/.code={%
\tikzset{%
name/.code={\edef\tikz@fig@name{#1 ##1}}
}%
}%
}
\makeatother
\begin{tikzpicture}
% ---- Copy 1
\begin{scope}[yshift=-32pt,prefix node name=G1]
\node[vertex] (u) at (0, 0) {u};
\node[vertex] (v) at (0, 0) {v};
\end{scope}
% ---- Copy 2
\begin{scope}[yshift=32pt,prefix node name=G2]
\node[vertex] (u) at (0, 0) {u};
\node[vertex] (v) at (0, 0) {v};
\end{scope}
\draw (G1 u) -- (G2 v);
\end{tikzpicture}
\end{document}
Note that this works both with implicit and explicit naming of nodes (ie via name=<name>
and \node (name) ...
).
You can do that with two loops: one running from 1 to n-1, the other from the current value of the first to n. Here an example for six:
Code
\documentclass[tikz,convert=false]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5,auto=left,every node/.style={circle,fill=black!20}]
\foreach \x in {1,...,6}
{ \node (n\x) at (\x*60:3) {\x};
}
\foreach \x in {1,...,5}
{ \pgfmathtruncatemacro{\lowerbound}{\x+1}
\foreach \y in {\lowerbound,...,6}
{ \draw (n\x) -- (n\y);
% for labelled edges
%\draw (n\x) -- (n\y) node[sloped,pos=0.39,fill=white,fill opacity=0.3,above=0.1mm,rectangle, inner sep=0.1mm] {\tiny \x-\y};
}
}
\end{tikzpicture}
\end{document}
Best Answer
You can use the
regular polygon
shape from theshapes.geometric
library, settingdraw=none
. Giving the node the namea
, the vertices will be nameda.corner 1
,a.corner 2
etc.