TikZ: What EXACTLY does the the |- notation for arrows do?
There are two different places to use -|
/|-
:
In a coordinate specification.
This is what you have used, the general form is
(a -| b)
where
a
andb
are namednode
s orcoordinate
s. This means the coordinate that is at the y-coordinate ofa
, and x-coordinate ofb
. Similarly,(a |- b)
has the x-coordinate ofa
and y-coordinate ofb
.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.As a path specification.
This is used between two coordinates, in place of
--
.With
\draw [->] (a) -| (b);
the arrow goes horizontally froma
, then vertically up tob
. (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}
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.