# TikZ: What EXACTLY does the the |- notation for arrows do?

I am currently trying to work out how the perpendicular arrows work, and I fail.

Taking:

\draw [arrow] (node1) -- node[sloped, above] {Caption} (node1 |- node2.north west);


I suspected that the notation meant:
Draw an arrow from node 1, to the north-west corner of node 2.
Make the arrow perpendicular to node 1.

Further attempts to draw arrows told me: No, that's not it. I have sadly failed to figure out what exactly the notation is supposed to be doing though! Is there any "explanation for dummies" that will lead me to understand what exactly

node1 |-


Is supposed to do?

Thanks!

• This is clearly explained in section "13.3.1 Intersections of Perpendicular Lines" in the TikZ and PGF manual (page 141 in v 3.1.4a). Commented Jul 30, 2019 at 20:09

There are two different places to use -|/|-:

1. In a coordinate specification.

This is what you have used, the general form is

(a -| b)


where a and b are named nodes or coordinates. This means the coordinate that is at the y-coordinate of a, and x-coordinate of b. Similarly, (a |- b) has the x-coordinate of a and y-coordinate of b.

For example, the following code draws a horizontal arrow from a at (0,0) to (1,0).

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,1);

\draw [->] (a) -- (a -| b);
\end{tikzpicture}
\end{document}


You can also use this as

\coordinate (c) at (a -| b);


and then \draw [->] (a) -- (c); does the same as the above.

2. As a path specification.

This is used between two coordinates, in place of --.

With \draw [->] (a) -| (b); the arrow goes horizontally from a, then vertically up to b. (And with |- it would be vertically first, then horizontally.)

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,1);

\draw [->] (a) -| (b);
\end{tikzpicture}
\end{document}

• The analogy between the coordinate and path specifications can be seen by noting that \draw (a) -| (b); is equivalent to \draw (a) -- (a-|b) -- (b) ;. Commented Nov 15, 2017 at 22:11
• For anyone else who has issues deducing what exactly - and | mean: I define | as the vertical (y)-axis, and - as the horizontal (x)-axis. The notation now means "ignores the value of", i.e. (a |- b) means that "the y-axis of a and the x-axis of b is ignored", which in turn leads to the x value of a and the y value of b for that particular coordinate. Commented Aug 20, 2022 at 11:47

If a is a coordinate/node at position (a_x, a_y) and
b is at (b_x, b_y) then

a |- b := (a_x, b_y)

a -| b := (b_x, a_y)


They're just shorthands for combining the x/y coordinates of two points.

• This is already mentioned in Torbjorn's answer no? Commented Nov 15, 2017 at 14:10
• No, MathJax doesn't work. See tex.meta.stackexchange.com/questions/1272/… and linked questions. Commented Nov 15, 2017 at 14:36
• The second line should be a-|b := (b_x, a_y)... Commented Feb 25, 2019 at 6:14
• @PaulGaborit The user is not a frequent "flyer" of TeX.SE. I edited the answer directly. Commented Feb 25, 2019 at 6:42
• @percusse Yes, this is already mentioned in Torbjørn's answer. Nevertheless, I think this straightforward notation could be useful, in some way. Commented Feb 25, 2019 at 6:47