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


\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?


  • 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).
    – Zarko
    Jul 30 '19 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).

    \coordinate (a) at (0,0);
    \coordinate (b) at (1,1);
    \draw [->] (a) -- (a -| b);

    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.)

    output of code

    \coordinate (a) at (0,0);
    \coordinate (b) at (1,1);
    \draw [->] (a) -| (b);
  • 13
    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) ;.
    – And R
    Nov 15 '17 at 22:11

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.

  • 2
    This is already mentioned in Torbjorn's answer no?
    – percusse
    Nov 15 '17 at 14:10
  • 2
    No, MathJax doesn't work. See tex.meta.stackexchange.com/questions/1272/… and linked questions. Nov 15 '17 at 14:36
  • 1
    The second line should be a-|b := (b_x, a_y)... Feb 25 '19 at 6:14
  • @PaulGaborit The user is not a frequent "flyer" of TeX.SE. I edited the answer directly.
    – CarLaTeX
    Feb 25 '19 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.
    – CarLaTeX
    Feb 25 '19 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.