Position nodes in TikZ with relative directions and anchors.
Place nodes relative to each other using the positioning library and direction keywords like right=of instead of manual coordinates. Control spacing with node distance and align shapes precisely with named anchors.
The short answer: load \usetikzlibrary{positioning} in your preamble, name your nodes, and use direction keywords like right=of to build diagrams that adjust automatically when text changes.
Load the positioning library
| Goal | Older Syntax | Modern Syntax (Positioning Library) |
|---|---|---|
| Place node to the right | \node[right of=a] (b) {B}; | \node[right=of a] (b) {B}; |
| Custom distance | \node[right=2cm of a] (b) {B}; | \node[right=2cm of a] (b) {B}; |
| Anchor alignment | Requires manual shifts | \node[above right=of a.east] (b) {B}; |
Relative placement in TikZ requires the positioning library. Without it, modern direction syntax fails or places nodes incorrectly.
Add \usetikzlibrary{positioning} to your document preamble before you start drawing diagrams.
Four steps for relative placement
Follow these steps to build clean, maintainable flowchart and diagram layouts.
Positioning methods and syntax
Basic direction keywords
Use above, below, right, left, and their diagonal combinations to place nodes relative to a named anchor without calculating coordinates.
\node[draw] (a) {A}; \node[draw, right=of a] (b) {B}; \node[draw, below=of a] (c) {C};Adjusting distance locally
Override the global node distance for a single node by passing a dimension directly into the placement key.
\node[draw] (a) {A}; \node[draw, right=2cm of a] (b) {B};Aligning specific anchors
Connect a specific anchor of the reference node to an anchor of the new node for precise alignment.
\node[draw] (a) {A}; \node[draw, above=of a.north west, anchor=south west] (b) {B};Setting global spacing
Configure default spacing across the entire picture scope using node distance in the tikzpicture options.
\begin{tikzpicture}[node distance=8mm and 12mm] \node[draw] (a) {A}; \node[draw, right=of a] (b) {B}; \end{tikzpicture}
Common positioning errors and fixes
Unknown operator of
If TikZ throws an error on right=of, check that \usetikzlibrary{positioning} is loaded in the preamble and appears before \begin{document}.
Nodes overlapping unexpectedly
The modern positioning library measures distance between node outer borders rather than centers. Adjust node distance or check inner and outer separator values.
Text baselines out of alignment
When placing text-heavy nodes side by side, use base right=of or base left=of to keep text baselines aligned horizontally.
Questions
Why does right=of fail in my TikZ diagram?
The right=of syntax requires the positioning library. Add \usetikzlibrary{positioning} to your preamble. Without it, TikZ only recognizes the older right of= syntax.
What is the difference between right of=a and right=of a?
The older right of= syntax places the node center at a fixed distance from the reference node center. The modern right=of syntax measures distance between the outer borders of the node boxes.
How do I change the distance between two specific nodes?
Pass a dimension directly into the placement key, such as \node[right=2.5cm of a] (b) {B};. This overrides the default node distance for that single placement.
Can I position a node using exact coordinates instead?
Yes. Use the at coordinate syntax like \node[draw] at (3, 2) (a) {A}; to place a node at an absolute position on the grid.
How do I align the top edges of two nodes?
Reference the north anchor of the first node and set the anchor option on the second node, such as \node[right=of a.north, anchor=north] (b) {B};.
Does Texeno support all TikZ positioning libraries?
Yes. Texeno compiles with TeX Live 2026 and supports the positioning library, calc library, and all standard TikZ extension packages.
Try your own paper in Texeno.
Start free, upload a project as a .zip and press Recompile. Upgrade when you need longer compiles.
Start writing