Skip to content

Drawings with TikZ

Inside a tikzpicture, write path commands such as \draw (0,0) -- (2,1);, \draw (1,1) circle (0.5); or \fill[blue] (0,0) rectangle (1,1);, each ending with a semicolon.

Lines and coordinates

Load TikZ with \usepackage{tikz}. A drawing lives in a tikzpicture. \draw strokes a path, and -- joins points with straight lines. Plain coordinates such as (2,1) are in centimetres.

A polyline, a closed triangle and a grid

LaTeXPreamble: \usepackage{tikz}Open in editor (opens in a new tab)
\begin{tikzpicture}
  \draw[help lines] (0,0) grid (5,3);
  \draw[thick] (0,0) -- (1,2) -- (2,1) -- (3,2.5);
  \draw[blue, fill=blue!15] (3.5,0.5) -- (5,0.5) -- (4.25,2) -- cycle;
\end{tikzpicture}

-- cycle closes a path back to its start, so a fill has a clean corner.

Shapes

PathDraws
(0,0) rectangle (2,1)a rectangle from one corner to the other
(1,1) circle (0.5) or circle[radius=0.5]a circle around a centre
(1,1) ellipse (1 and 0.5)an ellipse with two radii
(1,0) arc (0:90:1) or arc[start angle=0, end angle=90, radius=1]an arc from the current point
(0,0) grid (3,2)grid lines, 1 cm apart (step=0.5 for others)
(0,0) .. controls (1,1) and (2,1) .. (3,0)a Bézier curve
(0,0) to[out=90, in=180] (2,2)a curve leaving and entering at angles

Rectangle, circle, ellipse, arc and curves

LaTeXPreamble: \usepackage{tikz}Open in editor (opens in a new tab)
\begin{tikzpicture}
  \draw[rounded corners, fill=yellow!30] (0,0) rectangle (2,1.2);
  \draw[red, fill=red!20] (3,0.6) circle (0.6);
  \draw[teal, thick] (5,0.6) ellipse (0.9 and 0.5);
  \draw[->, thick] (7.2,0) arc (0:90:1);
  \draw[purple, thick] (0,-1.5) .. controls (1,0) and (2,-3) .. (3,-1.5);
  \draw[orange, thick] (4,-2) to[out=90, in=180] (6,-1);
\end{tikzpicture}

Colours, line widths and dashes

Options in square brackets style the path. A bare colour name sets the stroke; fill= fills the shape, and \fill fills without a stroke. \filldraw does both.

Line widths, dash patterns, colours and opacity

LaTeXPreamble: \usepackage{tikz}Open in editor (opens in a new tab)
\begin{tikzpicture}
  \draw[ultra thin]  (0,2) -- (3,2);
  \draw[thick]       (0,1.6) -- (3,1.6);
  \draw[line width=3pt, blue!60] (0,1.2) -- (3,1.2);
  \draw[dashed]      (0,0.8) -- (3,0.8);
  \draw[dotted, thick] (0,0.4) -- (3,0.4);
  \draw[dash pattern=on 6pt off 2pt on 1pt off 2pt] (0,0) -- (3,0);
  \fill[green!50!black] (4,1) circle (0.5);
  \filldraw[fill=orange, draw=black, opacity=0.6] (4.5,0.6) rectangle (5.5,1.6);
  \draw[<->, red, thick] (4,-0.2) -- (6,-0.2);
\end{tikzpicture}

Colours can be any xcolor name (red, teal, violet ...), a mix such as blue!30!white, or a colour you define with \definecolor{mine}{HTML}{0072B2}.

Shading

\shade fills a shape with a colour gradient: left color and right color (or top color and bottom color) for a linear one, inner color and outer color for a radial one, and ball color for a lit sphere.

Linear, radial and ball shading

LaTeXPreamble: \usepackage{tikz}Open in editor (opens in a new tab)
\begin{tikzpicture}
  \shade[left color=blue!60, right color=white] (0,0) rectangle (2.5,1);
  \shade[top color=orange, bottom color=yellow] (3,0) rectangle (4,1);
  \shade[inner color=white, outer color=teal] (5.2,0.5) circle (0.5);
  \shade[ball color=red] (6.7,0.5) circle (0.5);
\end{tikzpicture}

Repeating with foreach

\foreach repeats a command for each value in a list. {0,1,...,5} fills in the steps. The loop variable can be used in coordinates, colours and text.

Circles and labels from a loop

LaTeXPreamble: \usepackage{tikz}Open in editor (opens in a new tab)
\begin{tikzpicture}
  \foreach \i in {0,1,...,5} {
    \draw[fill=blue!\i0] (1.2*\i,0) circle (0.45);
    \node at (1.2*\i,-0.8) {$\i$};
  }
  \foreach \a in {0,45,...,315}
    \draw[->] (9,0) -- ++(\a:0.9);
\end{tikzpicture}

(\a:0.9) is a polar coordinate: angle and distance. ++ makes a coordinate relative to the previous point.

Scopes and transformations

A scope applies options to everything inside it: colours, line styles, and transformations such as shift, rotate, scale, xscale and yscale.

The same square, shifted, rotated and scaled

LaTeXPreamble: \usepackage{tikz}Open in editor (opens in a new tab)
\begin{tikzpicture}
  \draw (0,0) rectangle (1,1);
  \begin{scope}[shift={(2,0)}, rotate=30, red]
    \draw (0,0) rectangle (1,1);
  \end{scope}
  \begin{scope}[shift={(4,0)}, scale=0.5, blue, thick]
    \draw (0,0) rectangle (1,1);
  \end{scope}
  \begin{scope}[shift={(5.5,0)}, xscale=2, dashed]
    \draw (0,0) rectangle (1,1);
  \end{scope}
\end{tikzpicture}

A small picture in the text

\tikz draws a small picture inside a paragraph, such as a coloured dot next to a word. Write the path right after it, ending with a semicolon.

\tikz inside a sentence

LaTeXPreamble: \usepackage{tikz}Open in editor (opens in a new tab)
Status: \tikz \fill[green!60!black] (0,0) circle (3pt); running,
\tikz \fill[red] (0,0) circle (3pt); stopped.

What differs from a TeX installation

The TikZ manual is part of PGF on CTAN: ctan.org/pkg/pgf. For plots with axes, use pgfplots.

Questions and answers

How do I draw a circle in LaTeX?

Load TikZ and write \begin{tikzpicture} \draw (0,0) circle (1); \end{tikzpicture}. The value in parentheses is the radius in centimetres.

What unit do TikZ coordinates use?

Plain numbers are centimetres. You can also write units, for example (2pt,1mm) or (1in,0).

How do I fill a shape with colour?

Use \fill[blue] ...; for a fill without an outline, or \draw[fill=blue!20] ...; for both.

Every example on this page is typeset by Scissor LaTeX when the site is built. Last updated 2026-11-06.