12

How can I extract only the x or y part of a predefined coordinate?

For instance, let's say we have

\coordinate (A) at (1,2);

And I want to use the x part of (A) like this

\draw (x of A,3)--(0,0);

15

I'm not aware of any direct syntax to do that (though I would love to have one). You can however use the let operation (section 14.15 in the TikZ v2.10 manual):

\usetikzlibrary{calc}

[...]

\draw let \p1 = (A) in (\x1,3) -- (0,0); 
| improve this answer | |
  • I thought at first that \pgfextractx should work with \coordinate, but it doesn't. – Gonzalo Medina Mar 22 '11 at 2:19
  • 2
    @Gonzalo: \newdimen\mydim, \pgfextractx\mydim{\pgfpointanchor{A}{center}}. – Caramdir Mar 22 '11 at 2:59
  • thank you; \pgfpointanchor is what I didn't know. – Gonzalo Medina Mar 22 '11 at 16:01
  • 1
    You should point out that this requires the calc tikzlibrary. – Martin Scharrer May 24 '11 at 18:42
3

For the second part of your question: You can do that with the |- syntax.

\coordinate (A) at (1,2);

\draw (A |- 0,3) -- (0,0);

Note that for pgfplots you need to set the version to at least 1.11 (e.g., \pgfplotsset{compat=1.11} or \pgfplotsset{compat=newest}) or use coordinates in the (axis cs:x,y) format for the intended behaviour.

| improve this answer | |
  • 1
    You do not need tmp here. You can use directly (A|-0,3) or even (A|-,3) (which is equivalent to (A|-1,3)) or (,3-|A). – Kpym Apr 4 '19 at 10:44
  • That's great! I updated the answer. – Scz Apr 4 '19 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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