# I need help with latex tiKz code for drawing the graph

I need some help with drawing this graph in LaTeX. The learning curve is quite steep!

• Do you have the coordinates of the nodes at hand? Jul 26, 2020 at 14:24

Like this:

• for positions of dots are used corners of regular shape from the library shapes.geometric
• dots and connection lines are drawn in the loops
• labels of dots are defined with counters in the loop
\documentclass[tikz, border=3mm]{standalone}
\usetikzlibrary{shapes.geometric}

\tikzset{
dot/.style = {circle, inner sep=1pt, fill,
node contents={}},
PG/.style = {% PentaGon
regular polygon, regular polygon sides=5,
minimum size=#1cm,
node contents={}},
every label/.append style = {inner sep=1pt, font=\tiny}
}

\begin{document}
\begin{tikzpicture}
\node (n1) [PG=6, draw];
\node (n2) [PG=4];
\node (n3) [PG=2];
%
\foreach \i/\ii [evaluate=\ii as \jj using int(\ii+5),
evaluate=\ii as \kk using int(\ii+10)]
in {1/1,2/5,3/4,4/3,5/2}
{
\node at (n1.corner \i) [dot, label=90+\i*360/5:\ii];
\node at (n2.corner \i) [dot, label=90+\i*360/5:\jj];
\node at (n3.corner \i) [dot, label=90+\i*360/5:\kk];
}
%%
\foreach \j [count=\i from 0] in {1,...,5}
{
\pgfmathsetmacro{\k}{int(1+Mod(\i+1,5))}
\pgfmathsetmacro{\l}{int(1+Mod(\i+3,5))}
\pgfmathsetmacro{\m}{int(1+Mod(\i+2,5))}
\draw   (n1.corner \j) -- (n3.corner \j)
(n1.corner \j) -- (n2.corner \k)
(n2.corner \j) -- (n3.corner \l)
(n3.corner \j) -- (n3.corner \l);
}

\end{tikzpicture}
\end{document}


Edit: in the first version of answer was direction the labeling of nodes in opposite direction as is shown in OP images. Now this is corrected with replacing original loop

\foreach \i [count=\j from 6,
count=\k from 11] in {1,...,5}
{
\node at (n1.corner \i) [dot, label=90+\i*360/5:\i];
\node at (n2.corner \i) [dot, label=90+\i*360/5:\j];
\node at (n3.corner \i) [dot, label=90+\i*360/5:\k];
}


with code which is now in above MWE.

• You forgot to give the code for your solution. Jul 26, 2020 at 16:51
• I want to say I like your solution more than mine. ;-) Jul 26, 2020 at 17:26
• +1. Very nice solution. Jul 26, 2020 at 18:20
• @AndréC, thank you very much. And special thanks to pointed me that I forgot upload MWE in my answer! Jul 26, 2020 at 18:22
• @MrWhite, you are right. Nodes were labeled/numbered in opposite direction as OP show in question. Now this is corrected. Jul 27, 2020 at 0:24

A simple approach for you to start with, it defines a node style mynodes that can be used later. Then you can draw nodes at various locations, e.g. in a polar coordinate system, where the first value is the angle and the second the distance. Then in the end you can \draw from any node to any node.

Here is my start for you, but as I didn't find a systematic in the edges, you an probably finish it for yourself:

\documentclass[tikz,border=5mm]{standalone}

\begin{document}
\tikzset{mynodes/.style={inner sep=2pt,fill=black,circle}}
\begin{tikzpicture}[scale=2]
\node[mynodes](N1) at (90:3){};
\node[mynodes](N2) at (18:3){};
\node[mynodes](N3) at (-54:3){};
\node[mynodes](N4) at (-126:3){};
\node[mynodes](N5) at (-198:3){};

\node[mynodes](N6) at (90:2){};
\node[mynodes](N7) at (18:2){};
\node[mynodes](N8) at (-54:2){};
\node[mynodes](N9) at (-126:2){};
\node[mynodes](N10) at (-198:2){};

\node[mynodes](N11) at (90:1){};
\node[mynodes](N12) at (18:1){};
\node[mynodes](N13) at (-54:1){};
\node[mynodes](N14) at (-126:1){};
\node[mynodes](N15) at (-198:1){};

\draw (N1) -- (N2) -- (N3) -- (N4) -- (N5) -- (N1);

\draw (N1) -- (N10);
\draw (N2) -- (N6);
\draw (N3) -- (N7);
\draw (N4) -- (N8);
\draw (N5) -- (N9);

\draw (N4) -- (N9) -- (N14) -- (N12) -- (N7) -- (N2);
\draw (N3) -- (N8) -- (N13) -- (N15) -- (N10) -- (N5);

\draw (N1) -- (N6) -- (N11) -- (N9);

\end{tikzpicture}
\end{document}


Complications could be introduced by using \pgfforeach to define the cyclic nodes, but I avoided that as you mentioned, you are a beginner. For less code this would be useful however.

For compare purpose.

Compile with Ahihi đồ ngốc.(please don't fix it)

size(7cm);
pair[] P,Q,T;
for (int i=0; i<5;++i){
P.push(dir(90-i*72));
Q.push(2/3*dir(90-i*72));
T.push(1/3*dir(90-i*72));
}
P.cyclic=true;
T.cyclic=true;
for (int i=0; i<P.length;++i){
label(scale(0.6)*Label("$"+(string) (i+1) +"$"),P[i],dir(degrees(P[i])));
label(scale(0.6)*Label("$"+(string) (i+6) +"$"),Q[i],dir(degrees(Q[i])+90));
label(scale(0.6)*Label("$"+(string) (i+11) +"$"),T[i],dir(degrees(T[i])+90));
draw(P[i]--T[i]);
draw(P[i+1]--Q[i]);
draw(Q[i]--T[i+2]);
}
draw(T[0]--T[2]--T[4]--T[1]--T[3]--cycle);
path pentagon=operator --(... P)--cycle;
draw(pentagon);
dot(P);
dot(Q);
dot(T);