1

I have just started working with the tkz-berge package, I am trying to draw a network flow problem, I have this so far:

\documentclass[a4paper,oneside,article]{memoir}
\usepackage{tikz}
\usetikzlibrary{arrows,%
    petri,%
    topaths}%
\usepackage{tkz-berge}

\begin{document}

\chapter*{Network Flow Problem}
\begin{tikzpicture}[scale=0.75,transform shape]

    \Vertex{3}
    \Vertex[x=0,y=-3]{1}
    \Vertex[x=2,y=-1.5]{2}
    \Vertex[x=4,y=-1]{5}
    \Vertex[x=4,y=-3]{4}
    \Vertex[x=6,y=-1.5]{8}
    \Vertex[x=8,y=0]{6}
    \Vertex[x=8,y=-3]{7}    

    \tikzstyle{EdgeStyle}=[post,dotted]
    \Edge[label=0](1)(3)
    \Edge[label=1](3)(6)
    \Edge[label=1](6)(8)
    \Edge[label=3](2)(1)
    \Edge[label=0](8)(7)

    \tikzstyle{EdgeStyle}=[post]
    \Edge[label=0](3)(2)
    \Edge[label=2](2)(5)
    \Edge[label=2](5)(4)
    \Edge[label=3](8)(5)
    \Edge[label=1](4)(1)
    \Edge[label=4](7)(4)
    \Edge[label=1](7)(6)
\end{tikzpicture}
\end{document}

And it looks just the way I want it, but I need to get the capacity of each node next to it i.e. b_{3} = 2 NW of vertex 3, I have been reading the documentation, but can't find anything on it.

So can it be done, if so how? Thanks in advance

Best Regards Steffen

P.S. If anyone have a better idea for what package to use to draw graphs like this in general, your advice is surely welcome.

1

It seems that the tkz-berge package has no provisions for two labels per node. But one can use tikz commands to add more of them, using e.g. a command

\extralabel[optional distance]{angle}{new label}{node name}

defined as

\newcommand\extralabel[4][0mm]{\node[label={[label distance=#1]#2:#3}] at (#4){};}

In your code:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,%
    petri,%
    topaths}%
\usepackage{tkz-berge}
\begin{document}

\newcommand\extralabel[4][0mm]{\node[label={[label distance=#1]#2:#3}] at (#4){};}
\begin{tikzpicture}[scale=0.75,transform shape]

    \Vertex{3}            \extralabel  {45}{$b_{3}=2$}{3}
    \Vertex[x=0,y=-3]{1}  \extralabel{-135}{$b_{1}=0$}{1}
    \Vertex[x=2,y=-1.5]{2}\extralabel[1mm]{-90}{$b_{2}=0$}{2}
    \Vertex[x=4,y=-1]{5}
    \Vertex[x=4,y=-3]{4}
    \Vertex[x=6,y=-1.5]{8}
    \Vertex[x=8,y=0]{6}
    \Vertex[x=8,y=-3]{7}    

    \tikzstyle{EdgeStyle}=[post,dotted]
    \Edge[label=0](1)(3)
    \Edge[label=1](3)(6)
    \Edge[label=1](6)(8)
    \Edge[label=3](2)(1)
    \Edge[label=0](8)(7)

    \tikzstyle{EdgeStyle}=[post]
    \Edge[label=0](3)(2)
    \Edge[label=2](2)(5)
    \Edge[label=2](5)(4)
    \Edge[label=3](8)(5)
    \Edge[label=1](4)(1)
    \Edge[label=4](7)(4)
    \Edge[label=1](7)(6)
\end{tikzpicture}
\end{document}

enter image description here

|improve this answer|||||
  • Thanks alot, i decided to take a different approach, but this works a charm :-) – Steffen Hvid Nov 14 '16 at 11:56

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.