Skip to main content
Create publication-quality diagrams directly in LaTeX using TikZ. This comprehensive guide covers basic shapes to complex technical illustrations, including flowcharts, graphs, circuits, and scientific diagrams.
Prerequisites: Basic LaTeX knowledge
Time to complete: 40-45 minutes
Difficulty: Intermediate to Advanced
What you’ll learn: TikZ syntax, libraries, drawing techniques, and practical examples

Introduction to TikZ

What is TikZ?

TikZ (TikZ ist kein Zeichenprogramm - TikZ is not a drawing program) is a powerful package for creating graphics programmatically in LaTeX. It provides:

Precise Control

Exact positioning and measurements

Consistency

Matching document fonts and styles

Programmable

Loops, variables, and calculations

Integration

Seamless LaTeX integration

Basic Setup

tikz-setup.tex
Ready to use this syntax? Continue in the browser editor when you want to adapt the example in a real project.Open LaTeX Cloud Studio
basic-shapes.tex

Basic Drawing

Coordinates and Paths

coordinates.tex
path-operations.tex

Nodes and Labels

nodes-basics.tex
node-positioning.tex

Flowcharts and Diagrams

Basic Flowcharts

simple-flowchart.tex
complex-flowchart.tex

State Diagrams

state-diagram.tex
automaton.tex

Graphs and Trees

Graph Structures

simple-graph.tex
directed-graph.tex

Tree Structures

binary-tree.tex
tree-layouts.tex

Scientific Diagrams

Mathematical Diagrams

function-plot.tex
geometric-diagram.tex

Physics Diagrams

physics-diagram.tex
circuit-diagram.tex

Advanced Techniques

Loops and Automation

foreach-loops.tex
calculations.tex

Styles and Scopes

custom-styles.tex
layers.tex

Decorations and Patterns

decorations.tex
patterns-fills.tex

Annotation Layers: Braces and Labels over Figures

TikZ also works as an annotation layer: braces, callouts and arrows drawn over a schematic or over an included image.
annotated-figure.tex
The decorations.pathreplacing library supplies the brace. amplitude sets its depth, and node[midway, above=6pt] places the label at its center. To annotate a photo or plot instead of drawn shapes, put the image in a node and switch to coordinates relative to that node. (0,0) becomes the lower-left corner of the image and (1,1) the upper-right corner, so the annotations stay in place when you change the image width:
annotate-image.tex

Best Practices

Optimization Tips

TikZ best practices:
  1. Use styles - Define reusable styles for consistency
  2. Name nodes - Makes connections easier
  3. Use calculations - Let TikZ compute positions
  4. Layer wisely - Background, main, foreground
  5. Externalize - Compile complex diagrams separately
  6. One file per figure - Keep large pictures in files such as figures/phase-diagram.tikz and pull them in with \input, so the same figure works in a paper, a thesis and slides
  7. Comment code - Especially for complex diagrams
  8. Use libraries - Don’t reinvent the wheel
  9. Test incrementally - Build diagrams step by step

Common Pitfalls

Avoid these TikZ mistakes:
  1. Hardcoded positions - Use relative positioning
  2. Repeated code - Use loops and styles
  3. Complex paths - Break into smaller parts
  4. Missing libraries - Load required libraries
  5. Scale issues - Test at final size
  6. Memory problems - Externalize large diagrams
  7. Forgotten semicolons - Every command needs one

Complete Examples

Network Diagram

network-diagram.tex

Data Flow Diagram

data-flow-diagram.tex

Next Steps

Explore more LaTeX visualization:
Pro tip: Start simple and build complexity gradually. Use the TikZ manual (texdoc tikz) as your reference - it’s comprehensive with excellent examples. Consider externalizing complex diagrams to speed up compilation of your main document.