\usetikzlibrary{guide}
Draw anything — flowcharts, circuit diagrams, mathematical plots, geometric shapes, trees — directly inside your LaTeX document. TikZ produces perfect vector graphics that scale at any resolution and stay in sync with your typography.
TikZ stands for “TikZ ist kein Zeichenprogramm” (a recursive German acronym meaning “TikZ is not a drawing program”). Despite the name, it is the most powerful graphics system available for LaTeX — built on top of the lower-level PGF library.
With TikZ you describe graphics programmatically using coordinates, paths, and styles. The result is pixel-perfect vector output embedded directly in your PDF — flowcharts, circuit diagrams, function plots, commutative diagrams, trees, finite automata, and much more.
Add \usepackage{tikz} to your preamble, then wrap your drawing commands in a tikzpicture environment. Every drawing command starts with \draw and ends with a semicolon. Coordinates are (x,y) pairs measured in centimetres.
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% A simple rectangle
\draw (0,0) rectangle (3,2);
% A circle
\draw (5,1) circle (1);
% A line with arrow
\draw[->] (0,3) -- (3,3);
% Text node
\node at (1.5, 1) {Rectangle};
\end{tikzpicture}
\end{document}Four building blocks cover almost every TikZ drawing you will ever need.
Points are written as (x,y) in centimetres by default. Polar coordinates use (angle:radius). The origin (0,0) is at the bottom-left of the picture.
\draw traces a visible stroke. \fill fills a closed shape. \filldraw does both. Every path statement ends with a semicolon.
Square-bracket options follow each command: [color, thick, dashed, ->]. Mix and match freely — TikZ resolves conflicts left-to-right.
\node places a label or box in the picture. Nodes act as named connection points for arrows and can carry any TikZ style.
TikZ uses a mixing syntax for colors: blue!20 means 20% blue mixed with 80% white. red!40!black means 40% red mixed with 60% black. This system works with any named color and integrates with the xcolor package.
Line style options include thick, very thick, dashed, and dotted. Arrow tips are specified as -> (forward), <- (backward), or <-> (both).
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Filled shapes with colors
\draw[fill=blue!20, draw=blue] (0,0) rectangle (2,1.5);
\draw[fill=red!20, draw=red, thick] (3,0.75) circle (0.75);
% Dashed line
\draw[dashed, gray] (0,-0.5) -- (4,-0.5);
% Arrow styles
\draw[->, thick, amber] (0,2) -- (4,2)
node[right] {direction};
\end{tikzpicture}
\end{document}Flowcharts combine three TikZ features: \tikzset to define reusable node styles, shapes.geometric for diamond decision nodes, and positioning for the convenient below of= and right of= placement syntax.
The arrows.meta library provides the modern -Stealth arrow tip (preferred over the legacy -> in professional documents).
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning}
\tikzset{
process/.style = {rectangle, draw, fill=blue!10,
text width=3cm, text centered,
minimum height=1cm},
decision/.style = {diamond, draw, fill=green!10,
text width=2.5cm, text centered,
inner sep=0pt},
arrow/.style = {thick, -Stealth}
}
\begin{document}
\begin{tikzpicture}[node distance=2cm]
\node[process] (start) {Start};
\node[process, below of=start] (input) {Read Input};
\node[decision, below of=input] (check) {Valid?};
\node[process, below of=check] (process) {Process Data};
\node[process, right of=check, xshift=2cm] (error) {Show Error};
\draw[arrow] (start) -- (input);
\draw[arrow] (input) -- (check);
\draw[arrow] (check) -- node[right] {Yes} (process);
\draw[arrow] (check) -- node[above] {No} (error);
\end{tikzpicture}
\end{document}pgfplots is TikZ's dedicated companion package for data and function plots. It wraps a TikZ picture in an axis environment that handles tick marks, labels, legends, and scaling automatically. Add \pgfplotsset{compat=1.18} to your preamble to opt in to the latest behaviour fixes.
Use \addplot for function curves, scatter plots, and bar charts. domain and samples control the plotted range and smoothness.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={Function Plot},
xlabel={$x$},
ylabel={$f(x)$},
grid=major,
width=8cm, height=6cm
]
\addplot[blue, thick, domain=-3:3, samples=100]
{x^2};
\addplot[red, thick, domain=-3:3, samples=100]
{sin(deg(x))};
\legend{$x^2$, $\sin(x)$}
\end{axis}
\end{tikzpicture}
\end{document}Load additional libraries with \usetikzlibrary{name} in your preamble. Multiple libraries can be comma-separated.
| Library | Purpose |
|---|---|
| arrows.meta | Modern, configurable arrow tips |
| shapes.geometric | Diamonds, ellipses, cylinders, etc. |
| positioning | above of=, right of=, below of= syntax |
| calc | Coordinate arithmetic with ($…$) |
| fit | Fit a node tightly around other nodes |
| matrix | Arrange nodes in a grid (matrix of nodes) |
| decorations | Wavy lines, zigzag, brace decorations |
Three errors account for the vast majority of TikZ compilation failures.
Shapes like diamond or arrow tips like Stealth live in optional libraries. Always add \usetikzlibrary{shapes.geometric, arrows.meta} before using them.
TikZ places (0,0) at the bottom-left of the tikzpicture, not the top-left. If your drawing appears upside-down, flip the y-axis with yscale=-1.
Every \draw, \fill, or \node statement must end with a semicolon. Missing one causes a cryptic "missing ; inserted" error from LaTeX.
Open the flowchart example directly in the FormaTeX playground — edit, compile, and download your PDF without installing anything.
One quick thing
We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.