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.

How do I do a definecolor in a /.style?

\pgfkeys{/IMMstyle/.style={
         inputnode/.style={shape=ellipse,draw,inner sep=2pt,minimum size=5.0mm},
         \definecolor{dpred}{rgb}{0.50,0.35,0}
        }}

doesn't work.

share|improve this question
    
Does this post help: tex.stackexchange.com/questions/19190/… –  cmhughes Sep 25 '11 at 1:48

2 Answers 2

up vote 7 down vote accepted

You can define a /.code (or /.code 2 args, or /.code n args) key that executes your desired code. To define a new color within a style, you could define a key

\tikzset{
    define color/.code 2 args={
        \definecolor{#1}{rgb}{#2}
    }
}

Your example could look like this

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}

\tikzset{
    define color/.code 2 args={
        \definecolor{#1}{rgb}{#2}
    },
    /IMMstyle/.style={
         inputnode/.style={
            shape=ellipse,
            draw,
            inner sep=2pt,
            minimum size=5mm
         },
         define color={dpred}{0.80,0.35,0}
    }
}

\begin{tikzpicture}
\node [/IMMstyle,inputnode,fill=dpred] {x};
\end{tikzpicture}

\end{document}
share|improve this answer

For future reference, I would guess that most Googlers will arrive here trying to define a style which contains a defined colour (rather than defining the colour within the style itself).

That's easy to do:

\begin{tikzpicture}
\definecolor{dkblue}{rgb} {0.00,0.33,0.68}
\tikzset{
    myStyle/.style = {draw=dkblue, very thick, rectangle}
}

\node [myStyle] {x};
\end{tikzpicture}
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.