Tutorial

TikZ for Biologists: Programmatic Figures

Stop fighting with alignment tools. Learn how to generate precise, publication-quality vector diagrams using LaTeX and TikZ templates.

Sciicons · Published · Last updated

TikZ for Biologists: Programmatic Figures

We have all been there: trying to align two receptor arrows in PowerPoint, zooming in to 400%, only to find they are still one pixel off. TikZ (TikZ ist kein Zeichenprogramm) is a powerful package in LaTeX that allows you to create graphics programmatically. It ensures perfect alignment, consistent fonts, and infinite scalability.

Why Code Your Figures?

  • Consistency: Use variables for colors and sizes. Change one line, update every figure in your thesis.
  • Version Control: Graphics are text files. You can track changes with Git.
  • Typography: Your figure labels match your document font perfectly.

Basic Setup

Add these packages to your LaTeX preamble to unlock the features used in the examples below.

\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning, shadows, trees}
\usetikzlibrary{decorations.pathmorphing}

% Define your lab colors
\definecolor{cellblue}{RGB}{20, 100, 200}
\definecolor{dnared}{RGB}{200, 50, 50}

Example: FACS Gating

Flow cytometry gates are mathematically defined shapes. Using TikZ, you can draw exact ellipses and rectangles relative to your axes.

\begin{tikzpicture}
    \draw[<->, thick] (0,4) node[left] {CD8 PE} -- (0,0) -- (4,0) node[below] {CD4 FITC};
    \foreach \x in {1,...,20}
        \fill[gray!40] (rand*0.5+1, rand*0.5+1) circle (1pt);
    \foreach \x in {1,...,15}
        \fill[red!60] (rand*0.5+3, rand*0.5+3) circle (1pt);
    \draw[red, dashed, thick] (2.2, 2.2) rectangle (3.8, 3.8);
    \node[red, above] at (3, 3.8) {Q2: Double Pos};
\end{tikzpicture}

Example: Metabolic Pathway

For pathways, the positioning library is your best friend. It allows you to place nodes relative to one another, making the layout flexible if you need to insert a step later.

\begin{tikzpicture}[
    node distance=1.5cm,
    metabolite/.style={rectangle, rounded corners, draw=black, fill=blue!10, thick, minimum size=8mm},
    enzyme/.style={text=red!70!black, font=\itshape\small}
]
\node[metabolite] (glu) {Glucose};
\node[metabolite] (g6p) [below of=glu] {G6P};
\node[metabolite] (f6p) [below of=g6p] {F6P};
\draw[->, thick] (glu) -- (g6p) node[midway, right, enzyme] {Hexokinase};
\draw[->, thick] (g6p) -- (f6p) node[midway, right, enzyme] {Phosphoglucose isomerase};
\end{tikzpicture}

Copy these snippets into Overleaf or your local TeX editor to see the vector output. In a later post, we will cover 3D diagrams using the tikz-3dplot package.

Frequently asked questions

Is TikZ suitable for biologists who do not code daily?
Yes. Start with templates for gates and pathways, then adjust labels and colors. Most lab figures need only positioning and a few node styles.
Can TikZ figures meet journal submission requirements?
TikZ outputs vector PDFs that scale cleanly for Nature, Science, and Cell figure panels, with fonts that match your manuscript.
How does TikZ compare to Illustrator for pathways?
Illustrator is faster for freeform art. TikZ wins when you need reproducible alignment, version control, and consistent typography across many panels.

More guides on the Sciicons blog · Browse scientific illustrations · Free figure tools