TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
TikZ: Node at same x-coordinate as another node, but specified y-coordinate?
Extract x, y coordinate of an arbitrary point in TikZ

How to use x coordinate of a point and y coordinate of other point? I need similar to

\coordinate (A) at (2,1);
\coordinate (B) at (3,0);
\coordinate (C) at (4,3);
\coordinate (D) at (5,-1);

\draw (xA,yB) -- (xC,yD);
share|improve this question

marked as duplicate by Jake, Alain Matthes, Claudio Fiandrino, percusse, Torbjørn T. Jul 17 '12 at 14:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

You can also extract the x and y coordinates as per Extract x, y coordinate of an arbitrary point in TikZ. – Peter Grill Jul 16 '12 at 22:44

You can use the orthogonal coordinate system identifiers -| and |-. They indicate horizontal component of the first and vertical component of the second for -| and vice versa for |-.

I have converted the coordinates to nodes to show the locations.

\node (A) at (2,1) {a};
\node (B) at (3,0) {b};
\node (C) at (4,3) {c};
\node (D) at (5,-1) {d};

\draw (A |- B) -- (C |- D);

enter image description here

share|improve this answer

Here's a less convenient solution than the solution proposed by Percusse but closer to the initial demand.

    \node (A) at (2,1) {a};
    \node (B) at (3,0) {b};
    \node (C) at (4,3) {c};
    \node (D) at (5,-1) {d};

    \draw let \p{A}=(A), \p{B}=(B), \p{C}=(C), \p{D}=(D) in
    (\x{A},\y{B}) -- (\x{C},\y{D});

The result is exactly the same...

share|improve this answer

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