Example: The tkz-berge graph package

Published 2007-05-08 | Author: Alain Matthes

The tkz-berge package is a set of convenient macros for drawing typical textbook graphs. It is built on top of TikZ' node and edge constructs, but adds several shortcuts for placing, arranging and connecting vertices. Visit the package's home page to see more examples.

Documentation only available in French. However, the code and the numerous examples speak for themselves.

Download:tkz-berge.sty
Author:Alain Matthes
Source:Altermundus

Download as: [PDF] [TEX]

The tkz-berge graph package

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. En français: TeXnique.fr.

% The tkz-berge graph package
% Author: Alain Matthes (http://altermundus.fr/)

\documentclass[]{article}
\usepackage{tikz}
\usepackage{tikz,fullpage}
\usetikzlibrary{arrows,%
                petri,%
                topaths}%
\usepackage{tkz-berge}
\usepackage[position=top]{subfig}
\begin{document}
\begin{figure}
\centering
\subfloat[]{
\begin{tikzpicture}[scale=0.75,transform shape]
  \Vertex[x=0,y=0](K)
  \Vertex[x=0,y=2](F)
  \Vertex[x=-1,y=4](D)
  \Vertex[x=3,y=7](H)
  \Vertex[x=8,y=5](B)
  \Vertex[x=9,y=2](N)
  \Vertex[x=5,y=0](M)
  \Vertex[x=3,y=1](S)
  \tikzstyle{LabelStyle}=[fill=white,sloped]
  \tikzstyle{EdgeStyle}=[bend left]
  \Edge[label=$120$](K)(F)
  \Edge[label=$650$](H)(S)
  \Edge[label=$780$](H)(M)
  \Edge[label=$490$](D)(B)
  \Edge[label=$600$](D)(M)
  \Edge[label=$580$](B)(M)
  \Edge[label=$600$](H)(N)
  \Edge[label=$490$](F)(H)
  \tikzstyle{EdgeStyle}=[bend right]
  \Edge[label=$630$](S)(B)
  \Edge[label=$210$](S)(N)
  \Edge[label=$230$](S)(M)
\end{tikzpicture}
}
\subfloat[]{
\begin{tikzpicture}[scale=0.75,transform shape]
  \tikzstyle{every node}=[node distance = 4cm,%
                          bend angle    = 45,%
                          fill          = gray!30]
  \Vertex(P)
  \NOEA{P}(B)
  \SOEA{P}(M)
  \NOEA{B}(D)
  \SOEA{B}(C)
  \SOEA{C}(L)
  \tikzstyle{EdgeStyle}=[pre and post]
  \Edge[label=$4$](P)(M)
  \Edge[label=$9$](C)(M)
  \Edge[label=$4$](C)(L)
  \Edge[label=$5$](C)(D)
  \Edge[label=$10$](B)(M)
  \tikzstyle{EdgeStyle}=[pre and post,bend right]
  \Edge[label=$11$](L)(D)
  \tikzstyle{EdgeStyle}=[post]
  \Edge[label=$3$](C)(B)
  \Edge[label=$10$](D)(B)
  \Edge[label=$10$](L)(M)
  \Edge[label=$10$](B)(P)
\end{tikzpicture}
}
\end{figure}
\end{document}

Comments

  • #1 Oliver Schrenk, June 25, 2010 at 11:25 p.m.

    I wanted to use this example as a template for my graphs, but I have some problems converting it.

    I'm converting the document via $ wget http://media.texample.net/tikz/examples/TEX/tkz-berge.tex $ xelatex tkz-berge.tex

    I'm using MaxTex 2009 on OSX. I followed the installation manual as far as I could, installing the missing .sty like so

    wget http://altermundus.com/downloads/packages/tkz-graph.sty wget http://altermundus.com/downloads/packages/tkz-arith.sty wget http://altermundus.com/downloads/packages/tkz-berge.sty sudo mkdir /usr/local/texlive/2009/texmf-dist/tex/latex/prof sudo mv tkz-* /usr/local/texlive/2009/texmf-dist/tex/latex/prof sudo texhash

    Before I installed the .sty files I got error messages. Obviously!

    Now I got

    ! Package pgf Error: No shape named K is known.

    Any hints for resolving the issue?

  • #2 Oliver Schrenk, June 29, 2010 at 12:20 a.m.

    Another developer/user was so nice to point out

    The example uses round braces for the last argument of \Vertex

    \Vertex[x=0,y=0](K).

    The examples in TKZdoc-graph.pdf uses curly braces:

    \Vertex[x=0,y=0]{G}

    It helped me at least.

  • #3 KaharoryHar, January 24, 2012 at 12:54 p.m.

    Good evening!
    Happy New Year! Health, luck and love!

Adding comments is currently not enabled.