Documentation/Tables & Figures/Learn TikZ: Create Diagrams and Graphics in LaTeX
Tables & Figures

Learn TikZ: Create Diagrams and Graphics in LaTeX

TikZ (pronounced 'teeks') is a LaTeX package for creating graphics in code. You get vector diagrams that match your document and scale perfectly. From simple shapes to flowcharts and plots.

Include TikZ in Your Document

Add the package and common libraries in your preamble:

\usepackage{tikz}
\usetikzlibrary{arrows.meta, shapes, positioning}

Your First TikZ Drawing

A tikzpicture environment draws a shape. The draw command connects points:

\begin{tikzpicture}
  \draw (0,0) -- (2,0) -- (2,2) -- (0,2) -- cycle;
\end{tikzpicture}
Output: Draws a square. The -- operator connects points; cycle closes the path.

Basic Shapes

Rectangles, circles, ellipses, and arcs:

\begin{tikzpicture}
  \draw (0,0) rectangle (2,1);
  \draw (4,0.5) circle (0.5);
  \draw (6,0.5) ellipse (0.7 and 0.4);
  \draw (8,0) arc (0:180:0.5);
\end{tikzpicture}

Styling: Lines and Fills

Use options for color, thickness, fill, and line style:

\begin{tikzpicture}
  \draw[blue, thick, fill=blue!20] (0,0) rectangle (2,1);
  \draw[dashed, red] (3,0) -- (5,1);
  \draw[->, thick] (6,0) -- (8,1);
\end{tikzpicture}

Nodes and Labels

Nodes place text or shapes and can be connected with arrows:

\begin{tikzpicture}
  \node at (0,0) {Hello};
  \node[draw, circle] at (2,0) {A};
  \node[draw, rectangle, fill=yellow!30] at (4,0) {Box};
  \node[draw, circle] (a) at (0,-2) {1};
  \node[draw, circle] (b) at (2,-2) {2};
  \draw[->] (a) -- (b);
\end{tikzpicture}

Simple Flowchart

Define styles and connect nodes for a flowchart:

\begin{tikzpicture}[
  node distance=1.5cm,
  box/.style={rectangle, draw, rounded corners},
  arrow/.style={->, thick}
]
  \node[box] (start) {Start};
  \node[box, below of=start] (proc) {Process};
  \node[box, below of=proc] (end) {End};
  \draw[arrow] (start) -- (proc);
  \draw[arrow] (proc) -- (end);
\end{tikzpicture}

Useful TikZ Libraries

Load extra libraries for arrows, positioning, and calc:

\usetikzlibrary{arrows.meta}   % Advanced arrow tips
\usetikzlibrary{positioning} % below=of, right=of, etc.
\usetikzlibrary{shapes}      % More node shapes
\usetikzlibrary{calc}        % Coordinate calculations
\usetikzlibrary{decorations} % Path decorations

💡 Tips

  • •TikZ produces vector graphics—they stay sharp at any zoom level
  • •Use named nodes (e.g. (a), (b)) so you can draw arrows between them easily
  • •For data plots, combine TikZ with PGFPlots (\usepackage{pgfplots})

Try This in Bibby AI

Write LaTeX faster with AI auto-complete and instant compilation.

Start Writing Free

Related Tutorials

Learn TikZ: Create Diagrams and Graphics in LaTeX | Bibby AI | Bibby AI