I have 10 files and each file has different distance variables and color variable in the code:

\draw [\colour_var,fill=\colour_var] (0,0) rectangle  node[text=white,text centered,rotate=270] {This is Number \Number_var} (2,4);

I want to set variable:

  • If Number_var = 1 then x_var = 5cm, y_var = 10cm, colour_var = green;
  • If Number_var = 2 then x_var = 7cm, y_var = 11cm, colour_var = blue;
  • If Number_var = 3 then x_var = 10cm, y_var = 15cm, colour_var = red;
  • ...

and so on.

Please help me on setting variables about distance and colour, and give me an example about how I can call these variables in my code?

Thank you so much.

  • 1
    For the colors: \colorlet{color1}{green}\colorlet{color2}{blue} ... and later use color\numbervar as color name. – Martin Scharrer Feb 8 at 8:26
  • Thanks @MartinScharrer. And Do you any idea for variable of distance? Thanks – latexforti Feb 8 at 8:34
  • Well, it depends a little on how \AbsolutePosition works, but \expandafter\def\csname xvar1\endcsname{5cm} ... and then use \csname xvar\numbervar\endcsname should work. But there are surely nicer ways to do it. – Martin Scharrer Feb 8 at 8:46
  • @MartinScharrer i code with your above guide: \expandafter\def\csname xvar3 \endcsname{50cm} \expandafter\def\csname yvar3 \endcsname{100cm} and then i call 2 method: method A (work well): \AbsolutePosition{\csname xvar3 \endcsname}{\csname yvar3 \endcsname}{ \begin{tikzpicture} \draw [varcolor\numbervar,fill=varcolor\numbervar] (0,0) rectangle node[text=white,text centered,rotate=270] {\textbf{\Huge \numbervar}} (1,2); \end{tikzpicture}}. – latexforti Feb 8 at 13:54
  • 1
    You have spaces after the number, e.g. \def\csname xvar3 \endcsname should be \def\csname xvar3\endcsname. How is \AbsolutePosition defined? Could you please post a full, compilable but minimal example? – Martin Scharrer Feb 8 at 15:54

Your Answer

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

Browse other questions tagged or ask your own question.