maybe I'm stupid, I looked at the many examples in which somehow shows the work with the coordinates, but I don't understand it. Simple example - I have:

   \coordinate [label=left:$D$] (D) at (0.3,0.5);

Now I would like to use x-part of my coordinate in the next \draw command, but I don't know how to simply extract it.

\draw[name path=my_line, gray] (**x-part of D coordinate**,0) node[below, red]{$c$} -- (0.75,1.1);

I hope that's my question is obvious. Thanks!!


You can use the let syntax (See Section 14.15 The Let Operation of the manual); another option (suggested by percusse in a comment) is to use the |- syntax (page 131 of the manual). An example with both possibilities:



  \coordinate [label=left:$D$] (D) at (0.3,0.5);
  \draw[name path=my_line, gray] let \p1=(D) in (\x1,0) node[below, red] {$c$} -- (0.75,1.1);

  \coordinate [label=left:$D$] (D) at (0.3,0.5);
  \draw (D |- {{(0,0)}}) node[below, red] {$c$} -- (0.75,1.1);


Quoting from the manual:

the meaning of (p-|q) is ''the intersection of a vertical line through p and a horizontal line through q''.

enter image description here

  • 4
    You can also use \draw (D |- {{(0,0)}}) -- (0.75,1.1);.
    – percusse
    Aug 6 '12 at 22:30
  • @percusse yes, you're right: I keep forgetting about this (simpler) way; I'll add it to my answer. Aug 6 '12 at 22:31
  • 3
    \draw (D |- 0,0) -- (0.75,1.1); works too. Oct 10 '13 at 9:22

You can also adapt the solution from Extract x, y coordinate of an arbitrary point in TikZ and invoke \ExtractCoordinate{D} before you need the coordinates of this point and then use \XCoord or \YCoord where you need the value.

The code below produces output identical to Gonzalo Medina's answer.



% https://tex.stackexchange.com/questions/33703/extract-x-y-coordinate-of-an-arbitrary-point-in-tikz
\newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoord}{\YCoord};}%


   \coordinate [label=left:$D$] (D) at (0.3,0.5);

  \draw[gray] (\XCoord,0) node[below, red] {$c$} -- (0.75,1.1);

For the sake of completeness and future reference, if you have a point (a) defined, you can define a new point (b) which depends on the coordinates of (a) using the let as follows:

\path let \p1 = (a) in coordinate (b) at (2*\x1,\y1/2);

Since \coordinate is an alias for \path coordinate you have to use the above code if you want to use let for the definition of a coordinate.

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.