# Placing nodes midway on paths using |- or -| in tikz

I make frequent use of |- and -| with computed points in diagrams, like so:

\coordinate (a) at (0,0);
\foreach \x in (1,...,10) {
\coordinate (b) at ({whateverFunction(\x)},{whateverOtherFunction(\x)});
\draw (a) |- (b); %Straight line segment
\draw (b) -| (a); %Another straight line segment
\coordinate (a) at (b);
}


To get plots like:

I would like to be able to label the midpoint of each line segment, but doing something like node[midway,above] {a} does not act like expected:

I want something like:

Why does midway not work, and what is a good workaround here?

• Did you try \draw (a) |-node{$a$} (b);? – Sigur Jan 26 '17 at 22:59
• @Sigur Yep- that does the same thing. – Chris Jan 26 '17 at 23:02

With -| and |-, midway (or pos=.5) is defined as the point where the two legs meet, regardless of how uneven the two legs are.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (3,1);
\draw (a) |- node[pos=.25,left]{A}
node[pos=.5,above left]{B}
node[pos=.75,above]{C} (b);
\end{tikzpicture}
\end{document}