Is it possible to draw graphs like in image below in LaTeX? It doesn't have to look exactly the same. I need arrows with numbers and circles (or dots or other symbol) with text in it (or next to it).


Here's an example, showing how you could do it with TikZ in a short and readable way.

  • Define styles for edges, arrows, and nodes
    • circle style for the main nodes, and font options so we don't need to adjust fonts within the nodes
    • For arrows, we use stealth' which is the name for a kind of arrow tip and shorten to not touch the node
    • The option auto is useful for automatic placement of nodes next to edges, instead of sitting directly on the edge. As we will mostly use left and right options, it will have effect just for one node. But good to have it as general option in the scope.
  • 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

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
                    thick,main node/.style={circle,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);

graph with nodes and edges

  • 1
    That is great! Two additional questions. 1. How can I modify this so it is numbered as figures? Is using \begin{figure}\begin{tikzpicture} correct? 2. How can I make the output bigger? – Ichibann Feb 25 '12 at 12:04
  • Question 3. How can I modify this so it doesn't change the font of entire document? – Ichibann Feb 25 '12 at 12:08
  • 3
    @Ichibann For an additional question, please post a new question instead of a comment, that's the way this question & answer site works. Check existing questions before. In short: 1) yes 2) bigger font, bigger node distance, or scale option 3) use \sffamily in the node style definition – Stefan Kottwitz Feb 25 '12 at 12:24
  • Can you create this kind of graph here with this pkg? Is there some "middle" directory? I am getting new nodes on top of each other here :( – hhh Aug 22 '13 at 16:59
  • @hhh Sure, perhaps post your specific different problem as a new question, if you can describe it well, other than only "draw this for me" ;-) such as with your current code. – Stefan Kottwitz Aug 22 '13 at 18:03

I also suggest the amazing automata library, as seen in Stefan's answer. :)

Just for completeness sake, I'd like to add an answer with one the first packages I used for drawing graphs and automata before I found TikZ: the vaucanson-g package.

This package relies on PSTricks, so we need to compile the following example with xelatex:


% good old times


% first of all, we define our grid

% and then we create the states

% now, transition time

% straight lines

% arcs

% loops



The output:

The output

There we go. :)


I combine tkz-graph and tikz.


enter image description here


\begin{tikzpicture}[->,>=stealth',shorten >=1pt,thick]
% unit
% styles
\SetVertexNormal[Shape=circle,MinSize=1cm,LineWidth =1pt]
\tikzset{VertexStyle/.append style = {font=\Large\bfseries},thick} 
% vertices  
% intern edges
% loops
% intern labels 
\path[every node/.style={swap,auto}]    (2) to node {0.3} (4)
                                            to node {0.2} (3)
                                            to node {0.8} (2)
                                            to node {0.4} (1)
                                            to node {0.6} (4); 
% draw extern edges and label
\draw[<-] (1) to [bend left] node [above right] {0.2} (4);
\draw[<-] (4) to [bend left] node [below right] {0.2} (3);
\draw[<-] (3) to [bend left] node [below left]  {0.1} (2);  
\draw[<-] (2) to [bend left] node [above left]  {0.3} (1);      


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.