3
\documentclass {article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\foreach \n in {8}
  \tikz\foreach \i in {1,...,\n}
    \fill (\i*360/\n:1) coordinate (n\i) circle(2 pt)
     \ifnum \i>0 foreach \j in {\i+1,\i+4}{(n\i) edge (n\j)} \fi;

\end{document}

which leads to:

enter image description here

I want to make an octagon with this type of edges, but I don't know why the edges bewteen \i and \i+1 are not showing up. Any suggestions would be great!

7

Welcome! Since you are loading shapes.geometric, you could just do

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[dot/.style={circle,fill,inner sep=0pt,minimum size=4pt}]
 \draw node[regular polygon,regular polygon sides=8,draw,minimum size=2cm]
 (p8){}
  foreach \X[count=\Y] in {5,...,8} {(p8.corner \X) node[dot](n-\X){}
    -- (p8.corner \Y) node[dot](n-\Y){} };
\end{tikzpicture}
\end{document}

enter image description here

However, there are IMHO better tools available: the graphs library. While it is true that there are not as many examples for those on this site available as for the above (which appeared several times in slight variations), I think this one will be much more powerful if you are really into graph drawing.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{graphs,graphs.standard}
\begin{document}
\begin{tikzpicture}
\begin{scope}[nodes={circle,fill,inner sep=0pt,minimum size=4pt}]
 \graph[empty nodes] { 
  {subgraph C_n [n=8,radius=1cm, counterclockwise] -- 
    0[coordinate]}; 
    };
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.