5

I'd like to use pgfkeys to define the scale for a number of tikz pictures. However, wenn I do the following:

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \pgfkeys{/my special/variable/.code={.1}}
    \begin{tikzpicture}[scale={/my special/variable}]
        \draw (0,0) -- (1,1);
    \end{tikzpicture}
\end{document}

I get: Package PGF Math Error: Unknown function 'my' (in '/my special/variable').

... [scale = \pgfkeys{/my special/variable}] ... does not work, either. LaTeX complains: TeX capacity exceeded, sorry.

What's the right way to define a variable that can be used to set a style or other variable in TikZ?

1 Answer 1

6

Try some thing like

\documentclass{article}
\usepackage{tikz}
\pgfkeys{/tikz/.cd,
  myvar/.store in=\myvar,
  myvar=0.1,
   }
\begin{document}
    \begin{tikzpicture}[myvar=2,scale={\myvar}]
        \draw (0,0) -- (1,1);
    \end{tikzpicture}
\end{document}

If you don't give myvar=2,, the intial value (0.1) is used.

8
  • 1
    beat me by 4 secs!
    – Bordaigorl
    Feb 13, 2015 at 18:03
  • 1
    +1, though I did not understand the need of doing this ;) Feb 13, 2015 at 18:37
  • @ClaudioFiandrino Just playing safe. :-)
    – user11232
    Feb 13, 2015 at 23:02
  • Hmm. Is there any benefit over \newcommand{\myvar}{.2}, then? Feb 15, 2015 at 18:12
  • @JohannesBauer This is tikz way!
    – user11232
    Feb 15, 2015 at 21:26

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.