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.

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:

\begin{tikzpicture}
   \coordinate [label=left:$D$] (D) at (0.3,0.5);
\end{tikzpicture}

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!!

share|improve this question
    
look up the let keyword –  daleif Aug 6 '12 at 22:21
    
    
I noticed that you haven't accepted any answer to your questions, Please consider doing so; in case of doubt on how/why to accept answers, please see How do you accept an answer?. –  Gonzalo Medina Aug 6 '12 at 22:40
add comment

3 Answers 3

up vote 8 down vote accepted

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:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}
  \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);
\end{tikzpicture}

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

\end{document}

enter image description here

share|improve this answer
2  
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. –  Gonzalo Medina Aug 6 '12 at 22:31
1  
\draw (D |- 0,0) -- (0.75,1.1); works too. –  Paul Gaborit Oct 10 '13 at 9:22
add comment

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.

Code:

\usepackage{tikz}
\usetikzlibrary{calc}

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


\begin{document}

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

  \ExtractCoordinate{D}
  \draw[gray] (\XCoord,0) node[below, red] {$c$} -- (0.75,1.1);
\end{tikzpicture}
share|improve this answer
    
Thank you very much. It is very helpful for me. –  jafan Aug 7 '12 at 6:48
add comment

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.

share|improve this answer
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.