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

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

    output of code

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

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.

Tags:

Tikz Arrows