# Help in drawing a graph (graph theory)

Can anyone help me to write the code to have the same graph as in the image below?

\begin{tikzpicture}
\matrix[column sep=2em, row sep=10ex, inner sep=0pt, minimum width=6pt] (M) {%
\node[mypoint, label={[left,xshift=-4pt]V1}, fill=green] (V1) {}; & & & & & \node[mypoint, label={above:$V_{2}$}] (V2) {};\\

\node[mypoint, label={[left,xshift=-4pt]V5}] (V5) {}; & & & & &
\node[mypoint, label={below left:V4}] (V4) {}; & & & & &
\node[mypoint, label={[right,xshift=2pt]V3}] (V3) {};\\
};
\draw (V1) -- (V2);
\draw (V5) -- (V1);
\draw (V5) -- (V4);

\end{tikzpicture}

• Welcome! Please can you complete your code with a minimal preamble and document environment? Right now, nobody but you knows how your custom style is defined, for example, so nobody can compile what you have. – cfr May 3 '17 at 2:12
• Note that you don't need to name the nodes. You can use M-1-1 etc. to refer to them, as you've named the matrix already. – cfr May 3 '17 at 2:13
• thank you, but i dont understand what do you mean – Maryam Fasfous May 3 '17 at 3:08
• @cfr I think that works only if the matrix is a matrix of nodes... – CarLaTeX May 3 '17 at 5:44 \documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-2.,0.)-- (2.,0.);
\draw(-2.,-1.) circle (1.cm);
\draw (-2.,4.)-- (-2.,0.);
\draw [rotate around={0.:(0.,4.)}] (0.,4.) ellipse (2.1cm and 0.5cm);
\draw (0.2,5.2) node[anchor=north west] {$e_1$};
\draw (0.2,3.4) node[anchor=north west] {$e_2$};
\draw (2.1,4.3) node[anchor=north west] {$v_4$};
\draw (-2.7,4.4) node[anchor=north west] {$v_3$};
\draw (-2.7,2.3) node[anchor=north west] {$e_3$};
\draw (2.2,0.4) node[anchor=north west] {$v_1$};
\draw (-2.8,0.4) node[anchor=north west] {$v_2$};
\draw (-2.8,-2.0) node[anchor=north west] {$e_4$};
\draw (0.1,-0.1) node[anchor=north west] {$e_5$};
\begin{scriptsize}
\draw [fill=black] (-2.,0.) circle (3.5pt);
\draw [fill=black] (2.,0.) circle (3.5pt);
\draw [fill=black] (-2.,4.) circle (3.5pt);
\draw [fill=black] (2.,4.) circle (3.5pt);
\end{scriptsize}
\end{tikzpicture}
\end{document}


Let me try to explain a bit the code.

\matrix[<options>] (<name>) {<code>};


produces a matrix (similar to a tabular) with some <options>, called <name>, whose rows are specified in <code>. I think it could be a good exercise for you to search for the meaning of the various options I used in the TikZ & PGF Manual.

\node[<options>] (<name>) {<text>};


produces a point called <name>, with the characteristic specified by <options> and some <text> inside. Since your nodes don't have text inside but outside I used the option label={[<label-options>]<label-text>}, which put a label, with a text <label-text>, near the node (the position of the label is specified by the <label-options>). Note that, since all your nodes are circle, fill=black, I've also created a style called mypoint to avoid writing the common options every time.

\draw (<node-start>) to [<options>] node[<label-position>]{<label-text>} (<node-end>);


draws a line from <node-start> to <node-end>, with some <options>, with a <label-text> positioned at <label-position>.

\draw (<node>) arc (<start-angle>:<stop-angle>:<radius>) node[<label-position>] {<label-text>};


draws an arc around <node> which begins at <start-angle> and ends at <stop-angle>, with a radius <radius> and a <label-text> positioned at <label-position>.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{%
mypoint/.style={circle, fill=black},
}

\begin{document}
\begin{tikzpicture}
\matrix[column sep=6em, row sep=10ex, inner sep=0pt, minimum width=6pt] (M) {%
\node[mypoint, label={[left,xshift=-6pt,yshift=-3pt]V3}] (V3) {}; & \node[mypoint, label={[right,xshift=6pt,yshift=-3pt]V4}] (V4) {}; \\
\node[mypoint, label={[right,xshift=2pt,yshift=4pt]V2}] (V2) {}; & \node[mypoint, label={[right,xshift=6pt,yshift=-3pt]V1}] (V1) {}; \\
};
\draw (V3) to [bend left] node[above]{e1}  (V4);
\draw (V3) to [bend right] node[below]{e2} (V4);
\draw (V3) -- node[left]{e3} (V2);
\draw (V2) -- node[below]{e5} (V1);
\draw (V2) arc (45:360+45:4mm) node[below left,xshift=-14pt,yshift=-14pt] {e4};
\end{tikzpicture}
\end{document} 