LaTeX TikZ
Programmable vector diagrams inside LaTeX. \usepackage{tikz}, tikzpicture environment, draw shapes with \draw.
Hello TikZ
\usepackage{tikz}
\begin{tikzpicture}
\draw (0,0) -- (2,2); % diagonal line
\draw (0,0) circle (1cm); % circle
\draw (1,0) rectangle (3,1); % rectangle
\fill[blue] (4,0) circle (0.5cm); % filled blue circle
\node at (2,3) {A label}; % text label
\end{tikzpicture}Arrows and connections
\usetikzlibrary{arrows.meta, positioning}
\begin{tikzpicture}
\node[draw, rectangle] (a) {Box A};
\node[draw, rectangle, right=of a] (b) {Box B};
\draw[-Stealth] (a) -- (b); % arrow from a to b
\draw[<->, thick] (a) -- (b); % double-headed thick
\end{tikzpicture}Flowchart example
\usetikzlibrary{shapes.geometric, arrows.meta, positioning}
\begin{tikzpicture}[node distance=1.5cm, every node/.style={align=center}]
\node[draw, rectangle] (start) {Start};
\node[draw, diamond, below=of start] (check) {Valid?};
\node[draw, rectangle, below left=of check] (no) {Reject};
\node[draw, rectangle, below right=of check] (yes) {Accept};
\node[draw, rectangle, below=of yes] (end) {End};
\draw[-Stealth] (start) -- (check);
\draw[-Stealth] (check) -- node[left] {No} (no);
\draw[-Stealth] (check) -- node[right] {Yes} (yes);
\draw[-Stealth] (yes) -- (end);
\draw[-Stealth] (no.east) -- ++(0,-1) -| (end);
\end{tikzpicture}Common TikZ libraries
| Library | Adds |
|---|---|
| arrows.meta | Modern arrow tip styles |
| positioning | above of, right=of, etc. |
| shapes.geometric | Diamond, ellipse, trapezium |
| automata | State machines |
| trees | Tree diagrams |
| decorations.pathreplacing | Curly braces, decorated lines |
| cd | Commutative diagrams |
Speed up TikZ compilation
% Cache each tikzpicture as a separate PDF
\usetikzlibrary{external}
\tikzexternalize
\tikzset{external/system call={
pdflatex \tikzexternalcheckshellescape -halt-on-error
-interaction=batchmode -jobname "\image" "\texsource"
}}
% Now first compile is slow, but subsequent rebuilds are 10-100x faster
% because TikZ pictures are cached as PDFs and only re-rendered if their
% source changes.#import "@preview/cetz:0.2.0": canvas, draw
#canvas({
draw.line((0,0), (2,2))
draw.circle((0,0), radius: 1)
draw.rect((1,0), (3,1))
draw.content((2,3), [A label])
})CeTZ does TikZ-style drawings in Typst — same node-and-path model but compiles 10-100x faster. Try TypeTeX free.
Try TypeTeX freeFrequently Asked Questions
TikZ (and its underlying engine PGF) is a LaTeX package for drawing precise, programmable diagrams directly in your LaTeX source. It produces vector graphics that scale perfectly and integrate with your document's typography. Used for flowcharts, decision trees, neural network diagrams, commutative diagrams, plots, and complex figures where pixel images would look unprofessional.
Add \usepackage{tikz} to your preamble. Wrap your drawing in \begin{tikzpicture} ... \end{tikzpicture}. The simplest example: \begin{tikzpicture} \draw (0,0) -- (2,2); \end{tikzpicture} draws a diagonal line. Coordinates are in centimeters by default.
Lines (\draw (0,0) -- (1,1)), circles (\draw (0,0) circle (1cm)), rectangles (\draw (0,0) rectangle (2,1)), arcs, ellipses, Bézier curves, and arbitrary paths. Filled versions: \fill or \filldraw with a color. With TikZ libraries, you get arrows, mind maps, automata, and 100+ shape types.
Use nodes: \node at (1,1) {Label text}. Or attach to a path: \draw (0,0) -- (2,0) node[midway, above] {label on the line}. The 'midway' positions the node at the midpoint; 'above' places it above the line. nodes can have shapes too: \node[circle, draw] at (1,1) {A} for a circle around 'A'.
Load the arrows.meta library: \usetikzlibrary{arrows.meta}. Then \draw[-Stealth] (0,0) -- (2,0) for a single arrow. Variants: -Latex, -Stealth, -To, -|, |- for arrowhead styles. \draw[<->] for double-headed. \draw[->, thick] for thicker.
Use the shapes.geometric library and the positioning library. Define nodes (process boxes, decision diamonds), then connect them with arrows. Example: \node[draw, rectangle] (start) {Start}; \node[draw, diamond, below of=start] (decision) {Yes?}; \draw[->] (start) -- (decision);. The 'below of=start' positions relative to the previous node.
TikZ compiles to PDF natively (vector). To get PNG: pdflatex your file, then convert PDF to PNG with ImageMagick: convert -density 300 file.pdf file.png. For SVG: use pdf2svg file.pdf file.svg. The pdftoppm tool also works for PNG. Or use the standalone document class to crop the figure before exporting.
TikZ does a lot of computation per drawing. Speed it up by: (1) using \usepackage[mode=buildnew]{standalone} to externalize each figure as a separate PDF, compiled once; (2) using the externalize library directly: \usetikzlibrary{external} \tikzexternalize. After first compile, TikZ caches each figure. Massive speedup on rebuilds.
Yes — CeTZ (CeTZ is for Typst). It's a Typst package that provides similar diagram-drawing capabilities. Same node-and-path style, simpler syntax, and 10-100x faster compile because Typst itself is faster than LaTeX. TypeTeX includes CeTZ-ready Typst projects with examples.