Drawing Trace Diagrams with TikZ

This page describes some basic functionality of TikZ, and provides instructions for using TikZ to draw trace diagrams. Several of the author's TikZ stylistic commands are included.

Introduction to TikZ

PGF (Portable Graphics Format) & TikZ (TikZ ist kein Zeichenprogramm) are a combination of $\TeX$ packages that can be used for generating high-quality graphics using a $\LaTeX$-like syntax. I like TikZ because it generates graphics on the fly, without the need for separate files for each picture… this is a lifesaver for papers that have hundreds of diagrams. It is also has a very natural and intuitive syntax. For example, the command to draw a line between $(0,0)$ and $(1,1)$ is

\tikz{ \draw(0,0)to(1,1); }

See this tutorial at the pracTeX Journal for help on getting started with PGF/TikZ. The instructions here require version 2.00 which is available at http://sourceforge.net/projects/pgf/, with documentation here. Another great resource is this PGF/TikZ Gallery.

PGF/TikZ is a great tool for drawing diagrams, because it allows for multiple diagrams to use the same styles. This allows one to, for instance, change the look of all matrices in a paper by changing a single line. The diagrams below are created using a combination of structure and styling. Frequently, a single diagram may be drawn using many different styles and labels, which indicate the proper way to read the diagram. So an optimal approach should separate (i) the drawing of lines, (ii) the annotation of the lines with matrices, nodes, and labels, and (iii) the appropriate styling of lines, nodes, etc.

Consistency of notation is extremely important when diagrams are an essential part of a paper. This includes consistency in style, as well as consistency in the way in which the lines are drawn. All the diagrams should have the same "look". All the lines, nodes, labels, and so on, should be drawn in a consistent manner.

Another advantage to this approach is that different styles can be used depending on whether the diagrams should be larger or smaller, black and white or colored, in paper form or in web form.

TikZ Style Key Definitions and Usage

TikZ has keys which can be used to efficiently apply a style to lots of different diagrams. The styles can then be changed once, rather than in each diagram separately. To implement this, I wrote TikZ style definitions for several of the styles that I use most frequently. This makes it easy to adjust the format of a diagram in a consistent manner. See tikzsamples.pdf to see some examples of how these are used.

In a typical file, I will include the following lines before writing any diagram code:


This loads in the appropriate packages required for the diagrams, and the custom key definitions, which are defined in tikzstyledefs.tex. The shapes and decorations.markings are special libraries required to draw certain elements. You can check out the source code or the sample file (source code for sample) to get a sense for which keys are available and how they work.

Keys for Nodes, Vectors, and Matrices

TikZ has a \node command which is used to draw nodes at a specified point. The simplest syntax for this is

\node at(0,0){text};

Certain parameters called keys can be passed to the node to determine how it is drawn. With these parameters, the syntax is:


Here are the keys defined in the tikzstyledefs.tex file:
Draw a dot at the given coordinate. Sample usage: \node[vertex]at(0,0){};
Draw a small red dot useful for representing a ciliation.
Draw a dot using the vertex style, together with a ciliation at the given angle as specified with the ciliation style. Sample usage: \node[ciliatednode=150]at(0,0){}; (Draws ciliation at angle of 150degrees relative to (0,0).)
Draw a vector, in a small yellow box. Sample usage: {{\draw(0,-1.5)node[vector]{$u$}; In addition, [small vector] yields a smaller yellow box, while [plain vector] yields a vector without a box.
Draw a matrix, oriented upward; drawn as a blue "signal" shape. In addition, [small matrix] gives a smaller matrix, and [reverse matrix], [reverse small matrix] produce matrices with opposite orientations.

When matrices are drawn along paths, it is better to use a special command to ensure they are oriented properly, as follows:

[matrix on edge]
Draw a matrix along an edge; actually uses the smaller size matrix. Ensures proper orientation. Sample usage: \draw(0,0)to node[matrix on edge]{$A$}(0,1); In addition, [reverse matrix on edge] yields a matrix with opposite orientation.

Keys for Lines and Curves

I have defined several keys for use with drawing lines and curves. The syntax for these is:


The impact varies from key to key, but generally these styles might make a line thicker or thinner, or display an orientation on an edge. The general line styles are:
Draws a thicker line than normal; a pseudonym for the predefined TikZ very thick style. Sample usage: \draw[trivalent](0,0)to(.5,1);
Draws three dots along a path instead of the path. Useful for representing an unknown number of edges.
Prescribes the tangents at the beginning and end of the path to be vertical. May be used in conjunction with other keys, for example: \draw[trivalent,wavyup](0,0)to(.5,1);

Keys Diagram Sizing

The following keys are used to adjust a diagram's baseline and scale, to make it easier to include diagrams inline with text. The syntax for usage is:

produces figure with baseline at about $y=0.5$
produces figure with baseline at about $y=0.75$
produces figure with baseline at about $y=1$
produces figure with baseline at about $y=1.5$

In addition, smaller versions can be used with the keys [heightones], [heighttwos], and [heightthrees].

Source code for \tikzstyle key diagram definitions

Here is the source code for the styles:


In this section we give the code for several simple TikZ diagrams. More complex examples are at my TikZ Snippets page.

Simple Diagrams


trivalent regular/tall/kinked:

Trivalent Diagrams

A shortcut is to apply the "basiclabel" style at the outset rather than for each node separately. This only works if these labels are the only types of nodes in the diagram.

\tikz[trivalent,every node/.style={basiclabel}]{
\node at(-.5,.85){$a$};
\node at(.5,.85){$b$};
\node at(1.2,1.1){$c$};}
  edge[bend right]node[leftlabel,pos=1]{$a$}(-.4,0)
  edge[bend left]node[rightlabel,pos=1]{$b$}(.4,0)
  edge[bend left]node[leftlabel,pos=1]{$a$}(-.6,1.15);
  edge[bend left]node[basiclabel,pos=.7,right=2pt]{$e$}(vxa)
  edge[bend left]node[leftlabel,pos=1]{$b$}(0,1.15)
  edge[bend right]node[rightlabel,pos=1]{$c$}(.6,1.15);}
  edge[]node[leftlabel,pos=1]{$d$}(0,-.15)edge[bend right]node[rightlabel,pos=1]{$c$}(.6,1.15);
  edge[bend right]node[basiclabel,pos=.7,left=3pt]{$f$}(vxa)
  edge[bend right]node[rightlabel,pos=1]{$b$}(0,1.15)edge[bend left]node[leftlabel,pos=1]{$a$}(-.6,1.15);}
\tikz[trivalent,every node/.style={basiclabel}]{
 \node at(-.5,.7){$a$};
 \node at(.5,.7){$b$};

Inward leaning edges helps give the impression that the strands are being glued.


When several vertices are in the figure, I like to specify and name their positions precisely using \coordinate or \node. The edge command is great for drawing edges between various nodes, but it requires placing the node command within the edge and thus specifying the coordinate precisely. Using the bend left and bend right keys is a nice easy way to curve the edges. The auto key automatically places a label along an edge to one side.

  edge[bend right]node[leftlabel,pos=1]{$a$}(-.3,-.2)
  edge[bend left]node[rightlabel,pos=1]{$b$}(.3,-.2);
  edge[bend left]node[leftlabel,pos=1]{$a$}(-.3,1.2)
  edge[bend right]node[rightlabel,pos=1]{$b$}(.3,1.2);}
         edge[bend right](-.3,.2)edge[bend left](.3,.2)edge[]node[rightlabel,pos=1]{$c$}(0,1);
  edge[bend left](-.2,.7)
  edge[bend right](.2,.65);
  (.45,0)node[rightlabel]{$b$}to[wavyup](.55,.6)to[bend right=90,looseness=2](.2,.65);}

Gallery of TikZ snippets with "tracediagram" tag


6j Symbols

(last edited on 26 Jan 2009 15:22 by elishapetersonelishapeterson)



(last edited on 11 Feb 2009 19:55 by elishapetersonelishapeterson)


Central Functions of Rank 1-3

(last edited on 11 Feb 2009 19:45 by elishapetersonelishapeterson)


Dot and Cross Products & Vector Identities

(last edited on 15 Feb 2010 15:44 by elishapetersonelishapeterson)


Examples for Various \tikzstyle keys

(last edited on 15 Feb 2010 15:01 by elishapetersonelishapeterson)


Fundamental Binor Identity

(last edited on 28 Oct 2008 11:49 by elishapetersonelishapeterson)


Pretty Simple Loop Recurrence

(last edited on 19 Jan 2009 19:21 by elishapetersonelishapeterson)


Simple Tensor Diagrams

(last edited on 11 Feb 2009 19:54 by elishapetersonelishapeterson)


Symmetrizers & Basic Trivalent Diagrams

(last edited on 11 Feb 2009 19:59 by elishapetersonelishapeterson)


Trace Relations via Binor Identity

(last edited on 28 Oct 2008 11:53 by elishapetersonelishapeterson)


Triple Vector Product Identity

(last edited on 15 Feb 2010 15:31 by elishapetersonelishapeterson)


Trivalent Spin Networks & Identities

(last edited on 11 Feb 2009 20:01 by elishapetersonelishapeterson)


Vectors and Matrices in Trace Diagrams

(last edited on 15 Feb 2010 15:40 by elishapetersonelishapeterson)

Figures attached to this page

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License