# Node on a jointed TikZ path

I have the following code

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-3,-3) rectangle (3,3);
\path[draw,thick] (0,0) |- (1.5,1.5);
\node at (0.75,1.5) [above] {Hi};
\end{tikzpicture}
\end{document}


which results in: In my mind, I can achieve the same effect by doing this:

\path[draw,thick] (0,0) |- node{Hi} (1.5,1.5);


But, when I try, I get: Is there a way to achieve what I want?

In

\path[draw,thick] (0,0) |- node{Hi} (1.5,1.5);


the node is placed at the middle of the path (midway, pos=.5). The |- and -| operators are special because their middle lies exactly on the sharp kink.

The middle of second part of your path is therefore at .75 of your whole path, thus

node[pos=.75,above]


is needed.

### Example

  \path[draw] (0,0) -| (5,-1);
\foreach \x in {0.0,0.25,0.5,0.75,1.0}{
\path[draw] (0,0) -| node[pos=\x] {\x} (5,-1);
}


### Output ## Code

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-3,-3) rectangle (3,3);
\path[draw,thick] (0,0) |- node[pos=.75,above] {Hi} (1.5,1.5);
\end{tikzpicture}
\end{document}


## Output ## A different approach

As Paul Gaborit has mentioned in a comment there is also the possibility to avoid the specialties of |- and -| and actually use two path parts with the coordinate specification |- and -| (which are in fact only short-cuts for the perpendicular coordinate system).

In a path like

\path (<c1>) -- (<c1> |- <c2>) -- node {} (<c2>);


you do have two path parts:

• one from <c1> to the coordinate vertically through <c1> and horizontally through <c2>, and
• one from that point to <c2> where we want to place the node (at the middle of that part, see above).

If you want to use these two-parters repeatedly, I advise you to use custom to paths so that you do not need to repeat both coordinates. (The number stands for the path part where the node shall be placed at.)

## Code

\documentclass[tikz]{standalone}
\tikzset{
|- 1/.style={to path={-- (\tikztostart |- \tikztotarget) \tikztonodes -- (\tikztotarget)}},
|- 2/.style={to path={-- (\tikztostart |- \tikztotarget) -- (\tikztotarget) \tikztonodes}},
-| 1/.style={to path={-- (\tikztostart -| \tikztotarget) \tikztonodes -- (\tikztotarget)}},
-| 2/.style={to path={-- (\tikztostart -| \tikztotarget) -- (\tikztotarget) \tikztonodes}},
}
\begin{document}
\begin{tikzpicture}[draw, thick]
\draw (0,0) to[|- 2] node{Hi} (1.5,1.5);
\draw (0,-1) to[-| 1] node{Hi} ++ (1.5,-1.5);
\end{tikzpicture}
\end{document}


## Output • Another possibility: \path[draw,thick] (0,0) -- (0,0 |- 1.5,1.5) -- node{Hi} (1.5,1.5); Feb 8, 2013 at 22:33
• @PaulGaborit Of course! I have added your possibility to my answer (while bringing in my own thoughts on the subject). Feb 8, 2013 at 23:00