# Difference between -| and |- in TikZ

Based on this tutorial, I understand symbols -| and |- are used to draw perpendicular lines.

But I wish to understand the difference between the two.

There are the following related questions:

But none of them seem to use the approach of -| and |-.

Understand it as it looks like:

• -| is "horizontal line → vertical line":

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) coordinate (1) node[below] {$(0,0)$};
\draw (2,2) coordinate (2) node[above] {$(2,2)$};
\draw (1) -| (2);
% -------------
\draw (4,2) coordinate (x) node[above] {$(4,2)$};
\draw (6,0) coordinate (y) node[below] {$(6,0)$};
\draw (x) -| (y);
\end{tikzpicture}
\end{document}


Mathematically, (x,y) -| (a,b) and (x,y) -- (a,y) -- (a,b) are the same.

• |- is "vertical line → horizontal line":

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) coordinate (1) node[below] {$(0,0)$};
\draw (2,2) coordinate (2) node[above] {$(2,2)$};
\draw (1) |- (2);
% -------------
\draw (4,2) coordinate (x) node[above] {$(4,2)$};
\draw (6,0) coordinate (y) node[below] {$(6,0)$};
\draw (x) |- (y);
\end{tikzpicture}
\end{document}


Mathematically, (x,y) |- (a,b) and (x,y) -- (x,b) -- (a,b) are the same.

They are clearly very different.

I'd like to add to JouleV's answer another use of -| and |-.

Given two nodes, A and B:

• if you use (A |- B) you have a point with the x coordinate of A and the y coordinate of B
• if you use (A -| B) you have a point with the x coordinate of B and the y coordinate of A.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
\node[draw] (A) {A};
\node[draw, above right =4cm of A] (B) {B};
\node[draw] at (A |- B) {$x$ of A, $y$ of B};
\node[draw] at (A -| B) {$x$ of B, $y$ of A};
\end{tikzpicture}
\end{document}


PSTricks version for @CarLaTeX's explanation:

• (A|-B) (TikZ) = (A|B) (PSTricks)
• (A-|B) (TikZ) = (B|A) (PSTricks)