## PGF and TikZ — Wow!

Mikkel and I have been working on a poster for the Summer School in Game Theory next week. For a poster you obviously need some graphics, and at first we started out with using PSTricks. That worked quite well and I was surpriced how easy it was to generate good pictures.

But PSTricks doesn’t work in pdfLaTeX, and for some reason the PostScript output didn’t work as well for me as PDF output. I then found the amazing PGF and TikZ packages with which you can make beautiful graphics for both PostScript and PDF output. The TikZ syntax is very clever and easy on the eyes, it’s inspired by PSTricks and MetaPost, another favorite program of mine.

With TikZ you get a very nice highlevel programming language for producing graphics in (La)TeX. For example, this code (taken roughly from the frontpage of the PGF and TikZ manual):

```
\tikzstyle{level 1}=[sibling angle=120]
\tikzstyle{level 2}=[sibling angle=60]
\tikzstyle{level 3}=[sibling angle=30]
\tikzstyle{every node}=[fill]
\tikzstyle{edge from parent}=[snake=expanding waves, segment length=1mm, segment angle=10,draw]
\tikz [grow cyclic, shape=circle, thick, level distance=10mm, cap=round]
\node {} child [color=\A] foreach \A in {red,green,blue}
{ node {} child [color=\A!50!\B] foreach \B in {red,green,blue}
{ node {} child [color=\A!50!\B!50!\C] foreach \C in {black,gray,white}
{ node {} }
}
```

gives you this:

and this little piece of code:

```
\begin{tikzpicture}[line width=3pt]
\draw[->] ( 0,-1) — ( 0,20) node[above] {Expenses};
\draw[->] (-1, 0) — (20, 0) node[below] {Income};
\draw[->, >=latex, blue!20!white, line width=72pt]
(4, 16) — node [black,sloped] {Optimization} +(-45:17cm);
\draw[draw=blue, loosely dashed]
(1.5,1.5) coordinate (C1) node[below=3pt] {$C_1$} –
(10, 3) coordinate (C2) node[below=3pt] {$C_2$} –
(13.5, 5) coordinate (C3) node[below right=3pt] {$C_3$} –
(17, 10) coordinate (C4) node[right=3pt] {$C_4$} –
(19, 18) coordinate (C5) node[right=3pt] {$C_5$};
\fill (C1) circle (5pt) (C2) circle (5pt) (C3) circle (5pt)
(C4) circle (5pt) (C5) circle (5pt);
\path (9,16) coordinate (C0);
\path (intersection of C3–C4 and C0– 19,6) coordinate (opt);
\draw[|->, red, shorten >= 5pt] (C0) — (opt);
\filldraw[red] (C0) node[above left] {$C_0$}
(opt) node[below right, text width=4.5cm] {Optimization Target} circle (5pt);
\end{tikzpicture}
```

gives you this graphic, which we used for our poster:

The graphic illustrates how company *C _{0}* ought to be more efficient by reaching the optimization target indicated. Notice how the target is found automatically as the intersection between the line segment from

*C*to

_{3}*C*and the line going downwards in a -45° angle from

_{4}*C*. Features like that used to belong only to MetaPost. Please also note now the color of the big arrow is specified as 20% blue mixed with 80% white. This easy and powerful way of selecting colors is possible thanks to the xxcolor package.

_{0}So if you’re into [LaTeX][] and need to include graphics in your documents, then look into PGF and TikZ. The installation is extremely easy: simply unpack the tarball and move some directories into your `~/texmf`

directory.