1

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

For example, I have a simple line:

\begin{document}

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

\end{document}

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

\begin{document}

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

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

\end{document}

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.

Reason?

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.

2

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.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\newcommand{\myvalue}{10}

First Tikz Picture

\begin{tikzpicture}
    \draw (0,\myvalue) -- (5,5+\myvalue);
\end{tikzpicture}

Second Tikz Picture

\begin{tikzpicture}
    \draw (0,\myvalue) -- (1,1+\myvalue);
\end{tikzpicture}
\end{document}
  • 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 '16 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 '16 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 '16 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.