It is possible to give in the coordinate of the point by an outside variable?

For example, I have a simple line:


\draw (0,0) -- (5,5);


I would like to parametrize the x-coordinate, such as:


*(some command that defines y)* y = 10;

\draw (0,y) -- (5,5+y);


I am familiar with the command coordinate: Define a variable in TikZ

But with it I need to add coordinate of the point. I would like to parametrize one coordinate.


I have two drawings in the same Tikz picture, one above the other. It is very likely that I will want to adjust the distance between them. The solution above would enable me to simply "shift" one of the figures up or down by changing the value of y associated with every y coordinate.


1 Answer 1


As already mentioned in the answers to the question you linked, you can do that. Just define a macro outside of the tikz environment. You can then use this macro in each of the multiple tikz pictures.


First Tikz Picture

    \draw (0,\myvalue) -- (5,5+\myvalue);

Second Tikz Picture

    \draw (0,\myvalue) -- (1,1+\myvalue);
  • Actually, if you define two tikzpicture environments, there's no need for this shift, because they won't overlap by default. The shift would make sense in the same picture. cc @nevermind
    – Alenanno
    Jan 29, 2016 at 13:23
  • @Alenanno You are right. I haven't really read what his goal is. I just read his original question about how to define an "outside" variable.
    – Benjamin
    Jan 29, 2016 at 13:32
  • I need both figures in the same environment because they are related and I am drawing some lines from the "top" one to the "bottom" one, so Benjamin's answer is precisely what I needed. Although, of course, I can define \myvalue inside the environment.
    – nevermind
    Jan 29, 2016 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .