How to Draw Diagrams in LaTeX With TikZ
By Shihab Shahriar Antor · Updated June 2026 · 8 min read
TikZ is LaTeX’s drawing package. Load it with \usepackage{tikz} and draw inside a tikzpicture environment using coordinates and commands like \draw, \node, and \filldraw. You build vector diagrams — graphs, flowcharts, circuits — that scale perfectly and match your document’s fonts. Below are progressive, copy-paste examples from a single line to a flowchart.
Your first TikZ drawing
TikZ draws with coordinates inside a tikzpicture. Everything is vector-based, so it stays sharp at any zoom and uses your document’s fonts. Start with a line and a shape:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (3,1); % a line
\draw (0,0) rectangle (2,1.2); % a rectangle
\filldraw[fill=blue!20] (3,0) circle (0.5); % filled circle
\end{tikzpicture}
\end{document}Nodes: labelled boxes
A \node is a positioned, labelled shape — the building block of graphs and flowcharts. The positioning library lets you place nodes relative to each other:
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
...
\begin{tikzpicture}[node distance=2cm]
\node[draw, circle] (a) {A};
\node[draw, circle, right=of a] (b) {B};
\draw[-{Stealth}] (a) -- (b);
\end{tikzpicture}A flowchart
\usetikzlibrary{shapes.geometric, arrows.meta, positioning}
\tikzset{
box/.style={draw, rounded corners, minimum width=2.5cm, minimum height=1cm},
arrow/.style={-{Stealth}, thick}
}
...
\begin{tikzpicture}[node distance=1.4cm]
\node[box] (start) {Start};
\node[box, below=of start] (work) {Compile};
\node[box, below=of work] (end) {PDF};
\draw[arrow] (start) -- (work);
\draw[arrow] (work) -- (end);
\end{tikzpicture}TikZ can be slow to compile for complex figures. A live editor with a fast compile loop helps you iterate — LetX compiles in 1–2 seconds with a live preview, so you tweak coordinates and see the result immediately. New to LaTeX? Start with Learn LaTeX in 30 minutes.
TikZ vs including an image
| TikZ | \includegraphics | |
|---|---|---|
| Quality at zoom | Vector, always sharp | Depends on source |
| Matches doc fonts | Yes | No |
| Edit later | In source | Re-export externally |
| Compile cost | Higher | Low |
Iterate on TikZ with a 1–2s live preview — free.
Open LetX FreeFrequently asked questions
What is TikZ in LaTeX?
TikZ is LaTeX’s native drawing package. You load it with \usepackage{tikz} and draw vector graphics — lines, shapes, nodes, graphs, flowcharts — inside a tikzpicture environment using coordinates and commands like \draw and \node.
How do I draw a flowchart in LaTeX?
Use TikZ with the shapes.geometric and positioning libraries. Define node styles, place nodes with relative positioning (below=of, right=of), and connect them with arrow draws like \draw[-{Stealth}] (a) -- (b).
Why is my TikZ figure compiling slowly?
Complex TikZ figures do a lot of computation each compile. Use a fast editor (LetX compiles in 1–2 seconds), or externalize figures with the TikZ externalization library to cache them as images.
Should I use TikZ or an external image?
Use TikZ when you want vector quality, fonts matching your document, and editable source. Use \includegraphics for photos or diagrams made in other tools where re-drawing in TikZ isn’t worth it.
Related
Written by Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs. Builder of LetX (collaborative LaTeX) and QuantumSketch (AI STEM video).
