Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

1 Answer 1

up vote 9 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.