TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I haven't read the documentation.

\documentclass[tikz,border=12pt]{standalone}
\tikzset
{
    helper/.style={color=#1!50,line width=#2},
    helper/.default={blue,12pt}
}

\begin{document}
\begin{tikzpicture}
    \draw[helper] (0,0) -- (2,2);
\end{tikzpicture}
\end{document}

How to use parameterized style?

share|improve this question
up vote 10 down vote accepted

You must explicitly define the number of parameters the style will take, as in helper/.style 2 args={...}.

Additionally, comma-separated lists are not supported here. So you must do helper/.default={blue}{12pt} for your example above. The same syntax should be used when actually applying parameters to the style.

Here's an example based on your M(n)WE:

The Code

\documentclass[tikz,border=12pt]{standalone}
\tikzset
{
    helper/.style 2 args={color=#1!50,line width=#2},
    helper/.default={blue}{12pt},
}

\begin{document}
\begin{tikzpicture}
    \draw[helper={red}{2pt}] (0,0) -- (2,2);
    \draw[helper] (2,0) -- (0,2);
\end{tikzpicture}
\end{document}

The Output

enter image description here

share|improve this answer

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.