Text Positioning in TikZ
Load the positioning library for relative node placement, then use anchors and label options for precise text placement.
If right=of, below=of, or a diagonal variant fails, add \usetikzlibrary{positioning} to the preamble. The modern direction=of node syntax is provided by that library.
Quick fix: load the TikZ positioning library
Name the first node, then place later nodes relative to it. By default, node distance separates the node borders; the two-value form sets vertical and horizontal distances.
Prefer right=of start to the older right of=start. The older form measures placement differently and is easy to mix up with the newer border-spacing behavior.
Positioning-library errors and fixes
Unknown operator 'of'or a node appears in the wrong place: loadpositioningbefore the picture.- Nodes overlap: set
node distance=8mm and 14mmor use a local distance such asright=2cm of start. - Text baselines do not line up: use
base right=oforbase left=ofinstead of the ordinary directions. - A node moves when its text changes: relative placement normally measures between borders. Use
on gridonly when you deliberately want center-to-center placement.
Basic Position Keywords
TikZ provides intuitive keywords for common positions:
Distance Control
Control the distance between text and reference point:
Anchor-Based Positioning
Use anchors for precise control over where text is placed:
Labels on Paths
Position text along lines and curves:
Sloped Text
Make text follow the angle of a path:
Rotated Text
Rotate text to any angle:
Text Alignment
Control multi-line text alignment:
Labels with Arrows
Position labels on arrows and annotate diagrams:
Pin and Label
Add labels that point to nodes:
Fit Library for Grouping
Create labels for groups of nodes:
Next Steps
Continue learning TikZ:
- TikZ Basic Setup - Load libraries and start a diagram
- TikZ Arrows - Connect positioned nodes with modern arrow tips
- Annotations - Callouts and explanatory text
- Flowcharts - Apply positioning to diagrams
- Graphs - Label network diagrams
Text Positioning in TikZ
Load the positioning library for relative node placement, then use anchors and label options for precise text placement.
If right=of, below=of, or a diagonal variant fails, add \usetikzlibrary{positioning} to the preamble. The modern direction=of node syntax is provided by that library.
Quick fix: load the TikZ positioning library
Name the first node, then place later nodes relative to it. By default, node distance separates the node borders; the two-value form sets vertical and horizontal distances.
Prefer right=of start to the older right of=start. The older form measures placement differently and is easy to mix up with the newer border-spacing behavior.
Positioning-library errors and fixes
Unknown operator 'of'or a node appears in the wrong place: loadpositioningbefore the picture.- Nodes overlap: set
node distance=8mm and 14mmor use a local distance such asright=2cm of start. - Text baselines do not line up: use
base right=oforbase left=ofinstead of the ordinary directions. - A node moves when its text changes: relative placement normally measures between borders. Use
on gridonly when you deliberately want center-to-center placement.
Basic Position Keywords
TikZ provides intuitive keywords for common positions:
Distance Control
Control the distance between text and reference point:
Anchor-Based Positioning
Use anchors for precise control over where text is placed:
Labels on Paths
Position text along lines and curves:
Sloped Text
Make text follow the angle of a path:
Rotated Text
Rotate text to any angle:
Text Alignment
Control multi-line text alignment:
Labels with Arrows
Position labels on arrows and annotate diagrams:
Pin and Label
Add labels that point to nodes:
Fit Library for Grouping
Create labels for groups of nodes:
Next Steps
Continue learning TikZ:
- TikZ Basic Setup - Load libraries and start a diagram
- TikZ Arrows - Connect positioned nodes with modern arrow tips
- Annotations - Callouts and explanatory text
- Flowcharts - Apply positioning to diagrams
- Graphs - Label network diagrams
