Wednesday, February 4, 2009

tkz-graph example (A latex graph drawing package)

The tkz-graph documentation seems very good, but it's in french. I don't know french. However I managed to make a little graph with loops and edge labelling. I have to say I'm pretty impressed with the results. Here's the Latex:

\documentclass{article}
\usepackage{slashbox}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames,pdftex]{xcolor}
\usepackage{fullpage}
\usepackage{tkz-graph}
%\usepackage[upright]{fourier}
\usepackage[left=3cm,top=3cm,right=3cm]{geometry}

\usetikzlibrary{arrows}
\thispagestyle{empty}
\title{Graph}
\begin{document}
\maketitle

\begin{center}
\begin{tikzpicture}[>=latex']
\tikzset{node distance = 5cm}
\GraphInit[vstyle=Normal]
\Vertex{0}
\EA(0){1}

\tikzset{LabelStyle/.style = {fill=white,sloped}}
\tikzset{EdgeStyle/.style = {->,bend left}}
\Loop[label=$0$,dir=WE](0)
\Loop[label=$1$,dir=EA](1)
\Edge[label=$1$](0)(1)
\Edge[label=$0$](1)(0)
\end{tikzpicture}
\end{center}

\end{document}



And here's how it renders:



That's actually a De Bruijn graph for alphabet size 2, k=2 if I've done it right.

1 comments:

new said...

Other odds and ends... You see all those EAs? That means east. So \EA(0){1} means make a new vertex labelled 1 east of the vertex labelled 0. NO, SO, EA and WE are all valid. As are NOEA SOWE etc.