Website review
This review may include AI-generated content and is not individually verified. Domain, certificate and other facts come from the observed data on this page.
What is TikZ?
TikZ is a TeX package for drawing graphics directly in LaTeX documents. You write commands such as \draw (0,0) -- (1,1); and TikZ renders the line as vector graphics, so it prints sharply at any size and uses the same fonts and math as the surrounding text. Because the picture lives in the source file, it stays versionable and reproducible alongside the document.
What it is good for
- Diagrams that must match the text: geometry figures, plots, trees, automata, circuits, Petri nets and mind maps are all covered by dedicated libraries in the manual.
- Precision and consistency: coordinates, styles and loops (
\foreach) let you generate repeated elements systematically rather than drawing by hand. - Publication workflows: authors who already compile with LaTeX avoid exporting and re-importing images.
The trade-off is the learning curve. The manual itself notes that the range of options "is often daunting to beginners," and that is the honest cost: TikZ rewards practice and punishes one-off, complex illustrations that would be faster in a point-and-click tool. For a quick freeform drawing, a vector editor is usually quicker; for a diagram that will be reused, restyled or embedded in an academic paper, TikZ often wins.
Where to start
Begin with the slowly-paced tutorials in the manual rather than the reference chapters — the "Picture for Karl's Students" and "Petri-Net for Hagen" walkthroughs teach most of the core syntax. The full documentation is available at PGF/TikZ Manual - Complete Online Documentation. For community examples and finished code to adapt, TeX - LaTeX Stack Exchange is the practical companion; for general LaTeX help, see TeXdoc.
A useful decision rule: if you can express the figure as coordinates, paths and labels, TikZ is a good fit; if it depends on hand-drawn curves or photographic detail, use another tool and include the result as an image.
How do I create my first TikZ picture with a simple draw command?
Start with a minimal tikzpicture environment and a \draw path between two coordinates. On PGF/TikZ Manual the manual's own example is \tikz \draw (0pt,0pt) -- (20pt,6pt);, which draws a straight line. In a document you would usually wrap it:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (2,1);
\end{tikzpicture}
\end{document}
The (0,0) and (2,1) are coordinates; -- means "connect with a straight line." Add \fill[orange] (1,1) circle (2pt); inside the same environment to place a small dot, or use \draw[thick, ->] for a thicker arrow. Compile with pdfLaTeX, XeLaTeX or LuaLaTeX, since the manual is built around TeX producing PDF graphics.
As a next step, work through the manual's "Tutorial: A Picture for Karl's Students," which is designed for first-time users and builds up from a single line to labeled nodes and repeated elements. If you prefer a gentler standalone introduction, Overleaf has a TikZ tutorial with editable examples, and CTAN hosts the same official manual as a downloadable PDF for offline reading.
How can I position and align nodes in a TikZ diagram?
Position nodes with \node at an explicit coordinate, then align them using anchors, relative placement, or a matrix. The manual's tutorials and the "Nodes and Edges" and "Matrices and Alignment" chapters cover these approaches.
Placing a node
\node at (2,1) {Label};
\node[anchor=west] at (2,1) {Label};
The coordinate is where the node's anchor sits. By default, the node is centered on the coordinate, but anchor=west puts the node's west side at that point.
Aligning nodes
- Anchors:
anchor=north,anchor=south west, and so on, align node edges to a coordinate. - Relative placement:
right=of A,below=of A, andabove left=of Aplace nodes relative to another node. These need thepositioninglibrary. - Matrices: A
matrixplaces nodes in rows and columns with consistent spacing, which suits tables of labels or diagram grids. - Named nodes: Give a node a name (
\node (A) at (0,0) {A};) so later nodes and edges can refer to it.
Choosing an approach
| Approach | Good for | Trade-off |
|---|---|---|
| Explicit coordinates | Small diagrams with known positions | Manual adjusting when the layout changes |
positioning |
Flowcharts and connected node diagrams | Requires the library; spacing needs tuning |
matrix |
Grids of labels or repeated elements | Less flexible for irregular layouts |
For a decision, use positioning when nodes connect to each other and may move; use a matrix when you need regular rows and columns. The manual's "Tutorial: A Picture for Karl's Students" is a practical starting point for combining placement with edges.
What is the best way to draw a flowchart or graph with nodes and edges in TikZ?
The practical route is to use TikZ's dedicated graph syntax rather than placing nodes and drawing edges by hand. The manual's graph chapters and the "Diagrams as Simple Graphs" tutorial cover exactly this workflow: you declare nodes, connect them with edge operators, and let TikZ handle placement and routing. For flowcharts where you want precise control over each box position, plain \node and \draw with named coordinates remains the more predictable choice.
Choosing between the two approaches
| Situation | Better fit | Trade-off |
|---|---|---|
| Flowchart with fixed, deliberate layout | Manual \node[...] plus \draw (a) -- (b); |
Full control, but you position everything yourself |
| Graph with many nodes and connections | Graph syntax (\graph, \node, edge) |
Less manual work, but layout defaults may need tuning |
| Trees and hierarchies | Graph drawing layouts (trees, layered) | Automatic layout, less control over exact coordinates |
| Small diagrams in a paper or slide | Manual placement | Quickest to reason about for a handful of boxes |
A concrete starting scenario
Suppose you are writing a paper and need a five-box process diagram. Name each node (\node (start) at (0,0) {Start};), then connect with \draw[->] (start) -- (next);. This keeps coordinates explicit and easy to adjust. If the diagram grows past roughly ten nodes, switch to the graph syntax and let a layout algorithm place them; the manual's graph drawing introduction explains the available layouts, including layered layouts that suit directed flowcharts.
Next step
Work through the "Diagrams as Simple Graphs" tutorial in the manual first, then skim the graph drawing layout chapters to see which layout matches your diagram type. The full manual is at PGF/TikZ Manual. For broader LaTeX drawing alternatives, CTAN hosts package documentation, and TeX Stack Exchange has worked examples for common flowchart patterns.
How do I plot a mathematical function or data visualization in TikZ?
Use TikZ's plots library for mathematical functions and its datavisualization library for data-driven charts. The manual's tutorial chapters are the fastest route in: the function-plotting material sits alongside the "Plots of Functions" and "Repeating Things: Foreach" sections, while data visualization has its own dedicated part covering axes, visualizers, style sheets and legends.
Plotting a function
Add \usetikzlibrary{plots} to your preamble, then use the plot path operation inside a tikzpicture (or axis environment) with a domain and sample count. A typical workflow:
- Set the domain, e.g.
domain=-3:3. - Choose a sampling density with
samples=— higher for oscillating functions, lower for smooth ones. - Either give an expression (
plot (\x, {\x*\x})) or supply coordinates from a file (plot file {data.dat}). - Add axes, labels and a legend; the manual's
axisenvironment handles ticks and grid lines more cleanly than hand-drawn arrows.
Data visualization
For real datasets, the datavisualization library is the intended tool: you describe data, axes and a visualizer (line, scatter, etc.) declaratively rather than computing coordinates yourself. The manual's "Data Visualization" part walks through providing data, selecting axes, and applying style sheets and legends — useful when the same chart style must be reused across a document.
Practical trade-offs
| Need | Better fit |
|---|---|
| A quick inline sketch of a function | plot with a domain, no axes environment |
| Publication-quality chart with ticks and legend | axis environment or datavisualization |
| Data already in a CSV | datavisualization or plot file |
| Reproducible styling across many figures | datavisualization style sheets |
A useful next step: open the tutorial "A Picture for Karl's Students" in PGF/TikZ Manual and work through it before jumping to the plotting chapters — it establishes the coordinate and path syntax that every plot example assumes. If you prefer a broader LaTeX reference alongside it, TeX - LaTeX Stack Exchange has worked examples for common plot problems.
How can I use TikZ libraries like circuits, trees, or mindmaps to draw specialized diagrams?
TikZ's libraries extend the core drawing language with ready-made shapes, placement rules and shortcuts, so specialized diagrams like circuits, trees and mindmaps don't need to be built from raw paths. The manual documents each library in its own chapter, alongside tutorials that walk through complete examples rather than isolated commands.
What each library is good for
- Circuits: The circuit library provides components (resistors, capacitors, sources and similar symbols) and conventions for placing and connecting them, so schematics read like standard electrical drawings instead of hand-placed lines and shapes. It suits engineers and students producing publication-quality figures.
- Trees: The "Making Trees Grow" material handles parent-child structures with automatic layout, so you describe the hierarchy and TikZ positions the nodes. This is practical for syntax trees, decision structures and org charts where manual coordinates would be tedious.
- Mindmaps: The mindmap library arranges ideas radially around a central concept, with branches growing outward automatically. It is aimed at overview diagrams and brainstorming maps rather than precise geometric layouts.
- Graphs and data: Separate chapters cover specifying graphs, graph-drawing layouts (trees, layered, force-based, circular, phylogenetic) and data visualization with axes and legends, for readers who need network or chart-style figures.
How to approach them
Start from the tutorial that matches your diagram type—the Petri-net and "diagrams as simple graphs" tutorials show library use in context—then open the library's reference chapter when you need a specific option. A useful decision rule: if the diagram's structure is hierarchical or relational, let a library handle placement; if it is a one-off geometric figure, plain paths and nodes are usually faster. The manual itself notes that the breadth of options can be daunting to beginners, which is why the paced tutorials come first.
For LaTeX-specific drawing questions outside the manual, the TeX community at TeX - LaTeX Stack Exchange often has worked TikZ examples.
User reviews (0)