3

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

enter image description here

\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
  • 1
    @cfr I think that works only if the matrix is a matrix of nodes... – CarLaTeX May 3 '17 at 5:44
1

enter image description here

\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}
11

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}

enter image description here

Some advice:

  1. read the tutorials in the TikZ & PGF Manual, in particular, Section 5
  2. read our TeX.SX starter guide (the red words are a link, please click on it!)
  3. put a complete minimal working example (MWE) of what you have tried, not only a snippet of an answer to one previous question of yours
  4. accept the answer that solves your problem, you have many answers to your previous questions but you haven't accepted any.
  • thank you very much, im happy to registrar in stack exchange – Maryam Fasfous May 3 '17 at 6:46
  • 4
    @MaryamFasfous You're welcome! The best way to thank people here is by accepting the answer clicking on the check mark you find on the top left of the question (please do it also for your previous questions)! – CarLaTeX May 3 '17 at 6:54
  • @MaryamFasfous I think you accepted the wrong answer. – CarLaTeX Apr 16 at 6:41

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.