31

I am interested in outputting this graph in latex using tikz:

enter image description here

So far I got this:

enter image description here

and my tikz code is

\begin{tikzpicture}
    \node[shape=circle,draw=black] (A) at (0,0) {A};
    \node[shape=circle,draw=black] (B) at (0,3) {B};
    \node[shape=circle,draw=black] (C) at (2.5,4) {C};
    \node[shape=circle,draw=black] (D) at (2.5,1) {D};
    \node[shape=circle,draw=black] (E) at (2.5,-3) {E};
    \node[shape=circle,draw=black] (F) at (5,3) {F} ;

    \path [->] (A) edge node[left] {$5$} (B);
    \path [->](B) edge node[left] {$3$} (C);
    \path [->](A) edge node[left] {$4$} (D);
    \path [->](D) edge node[left] {$3$} (C);
    \path [->](A) edge node[right] {$3$} (E);
    \path [->](D) edge node[left] {$3$} (E);
    \path [->](D) edge node[top] {$3$} (F);
    \path [->](C) edge node[top] {$5$} (F);
    \path [->](E) edge node[right] {$8$} (F);   
\end{tikzpicture}

I want to know how to draw the arc between nodes B and E and also thicker arcs with their lengths in center. Any help is appreciated

  • For the arc, try \draw[->] (B) to [bend right=20] (E);. If the bend doesn't look right you can change the 20 to a different number. – David R Oct 1 '15 at 13:38
  • @DavidRobertson I did something like this based on your input \path [->](B) edge[bend right=60] node[left] {$1$} (E); – Morpheus Oct 1 '15 at 13:44
39

One suggestion, borrowing from David Robertson's comment. A couple of scopes are added, to set the same style easily for all the nodes within them. The weights are set in the center of the line (so left, above etc. are removed), and filled with white, to cover the underlying line. If you really want that, the arrows.meta library lets you set the arrow tip in a different color than the lines.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{scope}[every node/.style={circle,thick,draw}]
    \node (A) at (0,0) {A};
    \node (B) at (0,3) {B};
    \node (C) at (2.5,4) {C};
    \node (D) at (2.5,1) {D};
    \node (E) at (2.5,-3) {E};
    \node (F) at (5,3) {F} ;
\end{scope}

\begin{scope}[>={Stealth[black]},
              every node/.style={fill=white,circle},
              every edge/.style={draw=red,very thick}]
    \path [->] (A) edge node {$5$} (B);
    \path [->] (B) edge node {$3$} (C);
    \path [->] (A) edge node {$4$} (D);
    \path [->] (D) edge node {$3$} (C);
    \path [->] (A) edge node {$3$} (E);
    \path [->] (D) edge node {$3$} (E);
    \path [->] (D) edge node {$3$} (F);
    \path [->] (C) edge node {$5$} (F);
    \path [->] (E) edge node {$8$} (F); 
    \path [->] (B) edge[bend right=60] node {$1$} (E); 
\end{scope}
\end{tikzpicture}
\end{document}

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.