[Tex/LaTex] How to use \pgfextractx, \setlength and so on together, to achieve a task using paths


The following code attempts to absolutely position two nodes with rectangular outlines, then draw a line that goes from the right-hand side of one to the left-hand side of the other, along orthogonal lines with the vertical segment lying directly between the two nodes. But instead of getting that result, this happens:

alt text

I can't get the hang of how LaTeX and TikZ length commands work. How can I fix what I've got here?





[yscale = -1]

\begin{scope} % Boxes
[ every node/.style = { draw,
                        inner sep = 3mm,
    \node (a) at (0,20mm) {Apple};
    \node (b) at (28mm,0) {Banana};

\begin{scope} % Arrows
[->, > = angle 90, very thick]
    \setlength{\mylengthC}{\mylengthA/2 + \mylengthB/2}
    \draw (\mylengthA,20mm) -- (\mylengthC,20mm) |- (\mylengthB,0);



Best Answer

This works:

% mark the midpoint between nodes a and b
\path (a.east) -- (b.west) node[coordinate,midway] (c) {};
% Arrows
\draw[->,>=angle 90, very thick] (a.east) -| (c) |- (b.west);

You almost never have to use \pgfextracts. Instead, use named coordinate nodes and transformations.