Let
X
Journal

How to Draw Diagrams in LaTeX With TikZ

SPECIMEN IDLETX-SPEC-TIKZ
DATE RECORDEDMay 1, 2026
READING COMPLEXITY2 min read
TAG INDEX
latextikzdiagramstutorial
Document Abstract

TikZ is LaTeX's native drawing package. Draw inside a tikzpicture using coordinates, nodes, and edges to make flowcharts, graphs, and plots that scale perfectly.

TikZ is LaTeX's native vector-drawing package: you draw inside a tikzpicture environment using coordinates, nodes, and connecting edges. Because the output is vector graphics that share your document's fonts, TikZ diagrams stay perfectly sharp at any size and never look pasted-in. Load it with \usepackage{tikz} and you can build flowcharts, graphs, circuits, and plots.

1. Your first drawing

\usepackage{tikz}
...
\begin{tikzpicture}
  \draw (0,0) -- (2,0) -- (2,2) -- (0,2) -- cycle;  % a square
  \draw[->] (0,0) -- (3,1);                          % an arrow
  \filldraw[blue] (1,1) circle (2pt);                % a dot
\end{tikzpicture}

Coordinates are (x,y) in centimetres by default. -- connects points; cycle closes a path; options in [...] set color, arrows, and thickness.

2. Nodes — the building block of diagrams

A node is a labelled shape you can place and connect. Nodes make flowcharts trivial.

\begin{tikzpicture}[node distance=2cm, every node/.style={draw, rounded corners, fill=gray!10}]
  \node (start) {Input};
  \node (proc) [right of=start] {Process};
  \node (out)  [right of=proc]  {Output};
  \draw[->] (start) -- (proc);
  \draw[->] (proc) -- (out);
\end{tikzpicture}

Name each node (start) so you can draw edges between names instead of raw coordinates.

3. Useful libraries

Load TikZ libraries to unlock shapes and styles:

| Library | Adds | |---|---| | arrows.meta | Modern arrow tips (-{Stealth}) | | positioning | below=of, right=of placement | | shapes.geometric | Diamonds, ellipses for flowcharts | | calc | Coordinate arithmetic | | external | Cache compiled pictures (speed) |

\usetikzlibrary{positioning, arrows.meta}

4. Plots with pgfplots

pgfplots is built on TikZ and produces publication-grade charts:

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
...
\begin{tikzpicture}
  \begin{axis}[xlabel=$x$, ylabel=$f(x)$, grid=both]
    \addplot[blue, thick] {x^2};
    \addplot[red] table {data.dat};
  \end{axis}
\end{tikzpicture}

It draws axes, ticks, and legends automatically — and the fonts match your paper, unlike a chart exported from a spreadsheet.

5. Keep it fast and reusable

Complex pictures slow compilation. Use the external library to cache each diagram, and develop drawings in a standalone document, then \input them — see Multi-File LaTeX Projects. For raster images instead of drawings, use the images and figures guide.

→ Iterate on TikZ with instant preview in LetX. Want AI-generated math animations instead of static diagrams? See QuantumSketch.


Written by Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs, maker of LetX.

Frequently Asked Questions

Is TikZ better than importing an image for diagrams?

For schematics, flowcharts, graphs, and plots, yes. TikZ output is vector, so it stays razor-sharp at any zoom and at print resolution, and it uses the same fonts and line weights as your document, so a diagram never looks pasted-in. Imported PNG or JPG images blur when scaled and rarely match your typography. The trade-off is that TikZ has a learning curve and compiles more slowly, so for photographs or complex figures from other software, importing is still the right call.

Why is my tikzpicture compiling so slowly?

Complex TikZ pictures, especially pgfplots charts with many data points, are computed at compile time and can take seconds each. Speed it up with the external library: \usetikzlibrary{external} and \tikzexternalize compiles each picture once to a standalone PDF and reuses it until the code changes. During drafting, you can also comment out heavy figures. Online editors cache unchanged output between compiles, which hides most of this cost.

How do I draw a function plot in LaTeX?

Use pgfplots, which is built on TikZ. Load \usepackage{pgfplots}, set \pgfplotsset{compat=1.18}, then inside an axis environment use \addplot {x^2}; for a function or \addplot table {data.dat}; for data. pgfplots handles axes, ticks, legends, and log scales automatically, producing publication-quality charts that match your document fonts — a common reason researchers prefer it over exporting from a spreadsheet.