# Draw a graph with vertex pairs

I want to draw in LaTex a Petersen Graph using Kneser graph K(2,5) notation. And i'll do the same with the hypercube. Like this exemple: How can i do it please ?

• Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – Stefan Pinnow May 20 '18 at 12:05

The labeling of this graph is based on the Kneser notation example in Wikipedia.

\documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}

\tikzset{c/.style={draw,circle,fill=black,minimum size=4pt,inner sep=0pt,
anchor=center},
d/.style={draw,circle,fill=white,minimum size=4pt,inner sep=0pt, anchor=center}}
% from https://tex.stackexchange.com/a/294254/121799
\def\colorlist{{"cyan", "red", "orange", "yellow", "green", "gray", "blue", "violet"}}

\begin{tikzpicture}[font=\tiny]
\pgfmathtruncatemacro{\Ncorners}{5}
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3cm]
(poly\Ncorners) {};
\node[draw,regular polygon,regular polygon sides=\Ncorners,minimum size=5cm]
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
\pgfmathtruncatemacro{\myprevx}{ifthenelse(\x==1,5,mod(\Ncorners+\x-1,\Ncorners))}
\pgfmathtruncatemacro{\mynextx}{mod(\Ncorners+\x,\Ncorners)+1}
\pgfmathsetmacro\myfill{\colorlist[\myprevx]}
\node[d,label={{18+\x*72}:{$\{\myprevx,\mynextx\}$}},color=\myfill] (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){};
\pgfmathtruncatemacro{\myprevx}{ifthenelse(\x==2,5,mod(\Ncorners+\x-2,\Ncorners))}
\pgfmathtruncatemacro{\mynextx}{mod(\Ncorners+\x+1,\Ncorners)+1}
\ifcase\x
\pgfmathtruncatemacro{\ang}{0}
\or
\pgfmathtruncatemacro{\ang}{0}
\or
\pgfmathtruncatemacro{\ang}{90}
\or
\pgfmathtruncatemacro{\ang}{120}
\or
\pgfmathtruncatemacro{\ang}{60}
\or
\pgfmathtruncatemacro{\ang}{90}
\fi
\pgfmathsetmacro\myfill{\colorlist[\myprevx]}
\node[d,label={{\ang}:{$\{\myprevx,\mynextx\}$}},color=\myfill] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
\draw (poly\Ncorners-\x) -- (outerpoly\Ncorners-\x);
}
\foreach\X in {1,...,\Ncorners}{
\foreach\Y in {1,...,\Ncorners}{
\pgfmathtruncatemacro{\Z}{abs(mod(abs(\Ncorners+\X-\Y),\Ncorners)-2)}
\ifnum\Z=0
\draw (poly\Ncorners-\X) -- (poly\Ncorners-\Y);
\fi
}
}
\end{tikzpicture}
\end{document}


UPDATE: Colors.

• Thank u, can i ask you for the coloring ? For exemple; red for {5,2},{3,2},{2,1},{2,4}, blue for {1,3}, {4,3}, {4,1}, and green for {5,4}, {1,5}, {3,5}. You're code is a little bit complicated for me, so i don't find how to do it. I used to do simple \node for vertex and \draw for bridges so... – Massyl Kaci May 20 '18 at 16:53
• This code uses simple nodes for the vertices and draw for the bridges, but in a foreach loop and using the predefined corners of regular polygons. What do you want to have colored, vertices, texts, or both? And is there a mathematical pattern for the coloring, which can be implemented in the loop? – marmot May 20 '18 at 16:59
• I work on the chromatic number, so i want to have the vertices minimal coloring, there are many alghorithms that gives this coloration. In its simplest form, it is a way of coloring the vertices of a graph such that no two adjacent vertices share the same color. – Massyl Kaci May 20 '18 at 17:59
• @MassylKaci Meaning that I can take the color according to the index of one of its neighbors? – marmot May 20 '18 at 18:04
• But it's not the optimum, we only need 3 colors for the Petersen's graph, as i said color 1 for {5,2},{3,2},{2,1},{2,4}, color 2 for{1,3}, {4,3}, {4,1} color 3 for {5,4}, {1,5}, {3,5} – Massyl Kaci May 20 '18 at 19:39