Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

\documentclass[a4paper]{amsart}

\usepackage{calc,fullpage,tikz}
\usetikzlibrary{arrows}

\newlength{\mylengthA}
\newlength{\mylengthB}
\newlength{\mylengthC}

\begin{document}

\begin{center}\begin{tikzpicture}
[yscale = -1]

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

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

\end{tikzpicture}\end{center}

\end{document}
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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.

share|improve this answer
    
Works great, thanks. –  Hammerite Oct 11 '10 at 9:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.