Example: Simple graph

Published 2012-02-26 | Author: Stefan Kottwitz

A simple example of a graph with straight and bend arrows and loops. It has been posted as answer to the question Drawing graphs in LaTeX of Ichibann.

  • Define styles for edges, arrows, and nodes
  • Place the main nodes
  • Draw edges with nodes for description
  • Use options loop and bend for loops and bent edges
  • Specify left and right for bend direction and node placement

Download as: [PDF] [TEX]  •  [Open in writeLaTeX]

Simple graph

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de.

% A simple graph with straight and bend arrows and loops
% Stefan Kottwitz
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
  thick,main node/.style={circle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]

  \node[main node] (1) {1};
  \node[main node] (2) [below left of=1] {2};
  \node[main node] (3) [below right of=2] {3};
  \node[main node] (4) [below right of=1] {4};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node [left] {0.6} (4)
        edge [bend right] node[left] {0.3} (2)
        edge [loop above] node {0.1} (1)
    (2) edge node [right] {0.4} (1)
        edge node {0.3} (4)
        edge [loop left] node {0.4} (2)
        edge [bend right] node[left] {0.1} (3)
    (3) edge node [right] {0.8} (2)
        edge [bend right] node[right] {0.2} (4)
    (4) edge node [left] {0.2} (3)
        edge [loop right] node {0.6} (4)
        edge [bend right] node[right] {0.2} (1);


  • #1 Richard Hsu, November 2, 2012 at 2:38 a.m.

    One of the best examples that beginners can use to create graphs without spending hours trying to figure out how to make something. Very clean! Thank you!

  • #2 Al.tro., September 5, 2013 at 12:04 p.m.

    Brilliant example. Which version of pgf-tikz does it need?

Adding comments is currently not enabled.