Skip to main content
TikZ (\usepackage{tikz}) is a LaTeX package for drawing vector diagrams directly in code using coordinates, paths, and styled nodes inside a tikzpicture environment. For coordinate axes, function graphs, and plotted datasets, use Plotting with pgfplots instead.
first-drawing.tex
Test this example live in your browser. Open a ready-to-compile LaTeX project with TeX Live 2026 preinstalled and zero local setup.Open starter article

Step 1: Draw coordinates, paths, and basic shapes

Every TikZ drawing command ends with a semicolon (;). Default coordinates are in centimetres (1cm), and you can mix three coordinate forms on any path:
  • Cartesian: (2.5, 1.5)
  • Polar: (45:2) (45 degrees, radius 2 cm)
  • Relative: ++(1.4, 0.6) (moves relative to the previous point and updates the current point)
Common path operations include -- (straight segment), -| and |- (orthogonal corners), .. controls (c1) and (c2) .. (cubic Bézier curve), circle (r), rectangle (x,y), and cycle (closes the path). A temporary \draw[help lines, gray!30] (0,0) grid (9,3.5); makes positioning easier while drafting.
coordinates-paths.tex

Step 2: Style nodes with \tikzset

Define reusable styles with \tikzset{...} in the preamble or pass them in the tikzpicture options (such as [every node/.style={font=\small}]). Avoid the older \tikzstyle macro, which is deprecated in current PGF/TikZ. Give any node an identifier in parentheses—\node[process] (load) {Load data};—so you can connect nodes by name (\draw (load) -- (valid);) or attach lines to compass anchors such as (load.east) or (valid.south).

Step 3: Build a flowchart with positioning and arrows.meta

Load three libraries for flowcharts (all included in TeX Live 2026):
  • positioning for relative node placement (below=of start, right=of valid)
  • shapes.geometric for shapes such as diamond and trapezium
  • arrows.meta for configurable arrow tips such as >=Stealth (replacing the older arrows library and lowercase >=stealth)
With positioning, right=of A measures node distance between node borders rather than node centers (unlike the legacy right of=A syntax, which can cause wide nodes to overlap). Set node distance=0.9cm and 1.8cm to control vertical and horizontal spacing separately, and use |- or -| for clean return loops.
flowchart.tex

Step 4: Draw a tree diagram

TikZ builds hierarchical trees from a root \node followed by nested child { node ... } clauses. Control vertical spacing with level distance and horizontal spacing per depth with level 1/.style={sibling distance=...}, level 2/.style={...}. Use child[missing] {} to reserve an empty branch in a binary tree so siblings stay symmetric.
tree.tex

Step 5: Place a diagram in a figure with a caption

Wrap tikzpicture inside a figure environment with \centering, \caption, and \label so LaTeX numbers the diagram and lets you cite it with Figure~\ref{...}. Adjust node distance or coordinate spacing to fit \linewidth before resorting to \resizebox, which also shrinks node text.
figure-caption.tex
Ready to draw diagrams in the browser? Start from the Basic Article template in LaTeX Cloud Studio and replace main.tex with any complete example above.