Here’s a new installment to the never-ending debate about the best way to draw figures in LaTeX. (A previous suggestion: Adobe Illustrator.)

Stereographic projection image made using TikZ by Thomas Trzeciak, available at TeXample.net.

Stereographic projection image made using TikZ by Thomas Trzeciak, available at TeXample.net.

A promising solution is the combination of PGF (“Portable Graphics Format”) and TikZ (“TikZ ist kein Zeichenprogramm,” or “TikZ is not a drawing program”), both developed by Till Tantau, whom you may know better for creating Beamer.

PGF is the ‘base system’ that provides commands to draw vector images. This layer of the graphics system is tedious to use directly since it only provides the most basic tools. TikZ is a frontend that provies a user-friendly environment for writing commands to draw diagrams.

Like other LaTeX drawing packages (the picture environment, axodraw, etc.), the TikZ figures are a series of in-line commands and so are extremely compact and easy to modify. Unlike other LaTeX packages, though, TikZ provides a powerful layer of abstraction that makes it relatively easy to make fairly complicated diagrams.  Further, the entire system is PDFLaTeX-friendly, which is more than one can say for pstricks-based drawing options.

The cost is that the system has a bit of a learning curve. Like LaTeX itself, there are many commands and techniques that one must gradually become familiar with in order to make figures. Fortunately, there is a very pedagogical and comprehensive manual available. Unfortunately the manual is rather lengthy and many of the examples contain small errors that prevent the code from compiling. TeXample.net comes to the rescue, however, witha nice gallery of TikZ examples (with source code), including those from the manual. If you’re thinking about learning TikZ, go ahead and browse some of the examples right now; the range of possibilities is really impressive.

To properly learn how to use TikZ, I would suggest setting aside a day or two to go through the tutorials (Part I) of the manual. Start from the beginning and work your way through one page at a time. The manual was written in such a way that you can’t just skip to a picture that you like and copy the source code, you need to be sure to include all the libraries and define all the variables that are discussed over the course of each tutorial. (You can always consult the source code at the gallery of TikZ examples in a pinch.)

Let me just mention two really neat things that TikZ can do which sold me onto the system.

TikZ Feynman Diagram by K. Fauske, available at TeXample.net

TikZ Feynman Diagram by K. Fauske, available at TeXample.net.

The first example is, of course, drawing a Feynman diagram. The TikZ code isn’t necessarily any cleaner than what one would generate using Jaxodraw, but TikZ offers much more control in changing the way things look. For example, one could turn all fermions blue without having to modify each line.

TikZ used to draw arrows on a Beamer presentation. Image by K. Fauske, available at TeXample.net

TikZ arrows on a Beamer presentation. Image by K. Fauske, available at TeXample.net

The next example is a solution to one of the most difficult aspects of Beamer: drawing arrows between elements of a frame. This is consistently the feature that PowerPoint, Keynote, and the ‘ol chalkboard always do better than Beamer. No longer!

Check out the source code for the example above. Adding arrows is as easy as defining some nodes and writing one line of code for each line. The lines are curved ‘naturally’ and the trick works with Beamer’s overlays. (Beamer is also built on PGF.)

Anyway, for those with the time to properly work through the tutorials, TikZ has the potential to be a very powerful tool to add to one’s LaTeX arsenal.

Pros

  • Tools for creating high-quality vector graphics
  • “Node” structure is very useful for drawing charts and Feynman diagrams
  • Works with PDFLaTeX
  • Images are drawn ‘in-line’ (no need to attach extra files)
  • Easy to insert TeX into images

Cons

  • A bit of a learning curve to overcome
  • No standard GUI interface

Download PGF/TikZ. Installation instructions: place the files into your texmf tree. For Mac OS X users, this means putting everything into a subdirectory of ~/Library/texmf/tex/latex/.

About these ads