TikZ

LaTeX vector graphics library

Syntax

Most basic TikZ diagrams contain a set of nodes and edges. This includes plots, flowcharts, etc where nodes may be (invisible) coordinates or styled shapes or text objects.

Defining nodes

Nodes can be defined inside or outside of a path operation using the following format:

node[<options>](<name>){<text>}

The <name> given to the node can be referenced anywhere in the TikZ plot after being defined.

The draw command

\draw allows you to draw lines between nodes. Nodes can be defined inline, or they can be referred to using a pre-defined identifier. Examples include:

  • Draw a simple line between two coordinates, no visible nodes:

    \draw (0,0) -- (1,1);
  • Add options to the drawn line e.g. arrowhead style, color, thickness, etc

    \draw[->,blue,thick,dotted] (0,0) -- (1,1);
  • Draw shapes, in this case a red rectangle with bottom left corner at (0,0) and top right at (1,1) tex \draw[fill=red] (0,0) rectangle (1,1);

The \draw command is very versatile. The \path command can be used in the exact same way, doing the same thing as \draw but without drawing a line. This can be useful when you just want to outline a shape and fill it without messing with a border.

TODO: -|, ++ syntax, curved arrows, \edge usage, below of= vs below left=of syntax for node positioning

Background in flowcharts

Various tips

  • Scaling: one of the best ways I’ve seen for simply scaling an entire figure is wrapping the \tikzpicture in a \scalebox{<scale>}{...}. From what I’ve seen this seems to work well for most situations without any extra tweaks.