How to Make a TikZ Arrow Label Perpendicular to the Arrow
At a glance
- 1. Attach a node
Put the label in a node on the arrow path, usually at midway.
- 2. Follow the path
Add sloped so the label’s orientation follows the arrow’s direction.
- 3. Turn it perpendicular
Add rotate=90, or rotate=-90, to make the label perpendicular to the path.
To make a TikZ label perpendicular to a single arrow, place the label in a node on the path and combine sloped with rotate=90. The first option aligns the label with the path; the second turns it by a quarter-turn.
Minimal working example
This complete example draws a diagonal arrow and puts a perpendicular label at its midpoint:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->, thick] (0,0) -- (4,2)
node[midway, sloped, rotate=90, fill=white, inner sep=2pt]
{perpendicular label};
\end{tikzpicture}
\end{document}
The midway option puts the node halfway along the arrow. sloped rotates the node to follow the path, and rotate=90 turns it another 90 degrees. The white fill makes the label readable by covering the arrow underneath it. Remove fill=white if you want the line to remain visible behind the text.
Adjusting the position and direction
The label in the example is centered on the arrow. To move it a little to one side, add a placement option such as above=3pt:
\draw[->] (0,0) -- (4,2)
node[midway, sloped, rotate=90, above=3pt] {perpendicular label};
TikZ places above relative to the path, which is useful for keeping a label offset from a diagonal arrow. If the label lands on the undesired side, try below=3pt instead. You can also adjust the distance.
Use rotate=-90 if you want the text to point in the opposite direction. For a label to be perpendicular, either sign works; it changes which way the text faces. By default, TikZ keeps sloped nodes upright, so reversing the endpoints does not necessarily reverse the label’s facing direction. Use allow upside down if you want the node to preserve the full path orientation.
Why both options are needed
sloped alone makes a label parallel to the path. For example, on a rising diagonal arrow, the label rises at the same angle. rotate=90 alone rotates the text by 90 degrees relative to the page, so it is perpendicular only when the arrow itself is horizontal. Combining them makes the turn relative to the arrow’s direction, so it works for diagonal paths too.
The same approach works with a node placed at another position, such as pos=0.3, instead of midway. For a curved path, sloped uses the path direction at the node’s position, so the label is perpendicular to the local tangent there.
Common mistakes
- Using only
rotate=90: This sets a page-relative rotation, not a rotation relative to an angled arrow. - Using only
sloped: The label follows the arrow but remains parallel to it. - Putting the node after the arrow endpoint: A node written after the final coordinate may be placed at the endpoint. Use
midwayorpos=<fraction>to specify where along the path it belongs. - Confusing the arrowhead with the path direction: The label’s angle follows the line segment. The arrowhead indicates travel direction, but does not change the segment’s orientation.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.