2

I am trying to draw a hexagon that is connected to a set of vertices and edges within the borders of the hexagon itself. It is similar to a Grötzsch graph but is a hexagon rather than a pentagon.

So far I have this code that I found from others creating a Grötzsch graph. I tried to create it with 6 vertices.

This is the photo I'm trying to create using tikz:

enter image description here

This is the code I have right now but I'm stuck on the middle of the hexagon. I got this code from another post answer on here that I hardly changed at all but pointed me in the right direction (https://tex.stackexchange.com/a/674043/283535)

\begin{tikzpicture}
\node[thick,regular polygon,regular polygon sides=6, minimum size=7cm,draw] (poli) at (0,0) {};

\coordinate (v1) at (poli.corner 2);
\coordinate (v2) at (poli.corner 3);
\coordinate (v3) at (poli.corner 4);
\coordinate (v4) at (poli.corner 5);
\coordinate (v5) at (poli.corner 1);
\coordinate (v6) at (poli.corner 6);


\filldraw (v1) node[left]{$v_1$} circle (2pt);
\filldraw (v2) node[left]{$v_2$} circle (2pt);
\filldraw (v3) node[right]{$v_3$} circle (2pt);
\filldraw (v4) node[right]{$v_4$} circle (2pt);
\filldraw (v5) node[above]{$v_5$} circle (2pt);
\filldraw (v6) node[right]{$v_6$} circle (2pt);

\draw (v1) -- (v3)
 (v1) -- (v4)
 (v2) -- (v4)
 (v2) -- (v5)
 (v3) -- (v5);

\coordinate (u1) at ($0.5*(v2)+0.5*(v5)$);
\coordinate (u2) at ($0.5*(v1)+0.5*(v3)$);
\coordinate (u3) at ($0.5*(v2)+0.5*(v4)$);
\coordinate (u4) at ($0.5*(v3)+0.5*(v5)$);
\coordinate (u5) at ($0.5*(v1)+0.5*(v4)$);
\coordinate (w) at (poli.center);

\filldraw (u1) node[left]{$u_1$} circle (2pt);
\filldraw (u2) node[left]{$u_2$} circle (2pt);
\filldraw (u3) node[right]{$u_3$} circle (2pt);
\filldraw (u4) node[right]{$u_4$} circle (2pt);
\filldraw (u5) node[above]{$u_5$} circle (2pt);
\filldraw (w) node[right]{$w$} circle (2pt);

\draw (u1) -- (w)
 (u2) -- (w)
 (u3) -- (w)
 (u4) -- (w)
 (u5) -- (w);

\end{tikzpicture}

I changed the polygon and the vertices. I am now trying to connect them to the new set of vertices (u_1, ..., u_6) but they are showing up strange for me at the moment.

Thank you for any and all help!

3
  • Yes, you cite the source. In that question/answer, hit the "Share" link below it, and copy. Then insert it in your question. At the same time, take the chance to complete your minimal example so that it is a file that compiles. Also, you keep writing hexagon, but the image shows rather a pentagon. I don't understand if you want to draw a hexagon or a pentagon (but that might just be me).
    – mickep
    Commented Sep 8, 2023 at 5:19
  • u4 and u5 should probably be \coordinate (u4) at ($0.5*(v3)+0.5*(v6)$); \coordinate (u5) at ($0.5*(v4)+0.5*(v5)$);. Commented Sep 8, 2023 at 10:10
  • @mickep Thank you! With the original code, it compiles on my end as a hexagon with just the inside of the shape incorrect.
    – user283535
    Commented Sep 15, 2023 at 1:31

1 Answer 1

1

I would usually recommend the graphs library's clockwise placement in combination with a subgraph X_n but adding the labels to the nodes gets tedious then.

Placing nodes on the corner of a polygon is always pretty easy by using polar coordinates and calculating the angles:

\foreach \rad/\ltr in {1.2/u, 2.4/v}
  \foreach[count=\j from 0, evaluate={\ang=90+\j/6*360;}] \i in {1, ..., 6}
    \node[n, label={[anchor=\ang+180, inner sep=+.15em]\ang:\mathstrut\ltr_\i}]
      (\ltr_\i) at (\ang:\rad) {};

Reusing the \angle allows us to place the labels in the same direction.

For connecting the nodes, the graphs library can still be used because the syntax is much shorter:

\graph[use existing nodes]{
  w -- {\foreach \i in {1, ..., 6}{u_\i}},
  {[cycle] \foreach \i in {1, ..., 6}{v_\i}},
  {[cycle] u_1, v_2, u_3, v_4, u_5, v_6},
  {[cycle] u_2, v_3, u_4, v_5, u_6, v_1},
};

The cycle operator will connect all given nodes.

Instead of (a) edge (b) (b) edge (c) (c) edge … edge (n) (n) edge (a) we can just write [cycle] a, b, c, … n or even use a \foreach loop for this.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{graphs, quotes}
\begin{document}
\begin{tikzpicture}[
  math nodes/.style={execute at begin node=$, execute at end node=$},
  every label/.append style=math nodes,
  n/.style={shape=circle, fill, inner sep=+0pt, minimum size=+4pt, outer sep=+0pt},
]
\node[n, "w" right] (w) {};
\foreach \rad/\ltr in {1.2/u, 2.4/v}
  \foreach[count=\j from 0, evaluate={\ang=90+\j/6*360;}] \i in {1, ..., 6}
    \node[n, label={[anchor=\ang+180, inner sep=+.15em]\ang:\mathstrut\ltr_\i}]
      (\ltr_\i) at (\ang:\rad) {};

\graph[use existing nodes]{
  w -- {\foreach \i in {1, ..., 6}{u_\i}},
  {[cycle] \foreach \i in {1, ..., 6}{v_\i}},
  {[cycle] u_1, v_2, u_3, v_4, u_5, v_6},
  {[cycle] u_2, v_3, u_4, v_5, u_6, v_1},
};
\end{tikzpicture}
\end{document}

Output

enter image description here

1
  • Try changing the radii, say to 1.5/u, 2.4/v, gives an output closer to your image without having to adjust any calculations. Commented Sep 8, 2023 at 10:23

You must log in to answer this question.