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 have a macro that will draw several things in a TikZ picture using some styles I defined, which include fills:

\documentclass{article}
\usepackage{tikz}
\tikzset{%
mystyle1/.style={fill=red,font={\bfseries}},
mystyle2/.style={fill=yellow,draw=blue}
}
\newcommand{\doit}{%
 \begin{tikzpicture}
  \node[mystyle1,circle]at(0,0){Text1};
  \node[mystyle2,rectangle] at (3,0){Text2};
 \end{tikzpicture}
}
\begin{document}
Foo

\doit

bar
\end{document}

Which looks like

have

How can I tell TikZ, before or after the \tikzset, to

don't do the fills but everything else

without redefining all the styles? (Here it's only two, but in my real applications it's many and they may change.)

So, the result should look like this:

want

I thought, that something like

\tikzset{every node/.append style={fill=none}}

should work, but it doesn't.

share|improve this question

3 Answers 3

I would recommend you allow for an optional Parameter to the \doit macro with which you can specify other options.. So \doit produces the first image and \doit[fill=none] produces the second:

enter image description here

If you want more flexibility you can have two optional parameters to control the options for the circle and rectangle separately. So the third option below was produced with:

\doit[fill=orange, draw=blue, ultra thick][fill=green!50, draw=magenta, ultra thick]

enter image description here

Notes:

  • I used the xparse package to provide the macro that allows for two optional parameters. If you do not want to include an additional package, there are probably other ways to accomplish this.

Code: One Optional Parameter

\documentclass{article}
\usepackage{tikz}
\tikzset{%
    mystyle1/.style={fill=red,font={\bfseries}},
    mystyle2/.style={fill=yellow,draw=blue}
}

\newcommand{\doit}[1][]{%
 \begin{tikzpicture}
  \node[mystyle1, circle, #1] at (0,0){Text1};
  \node[mystyle2, rectangle, #1] at (3,0){Text2};
 \end{tikzpicture}
}
\begin{document}
Foo

\doit

\doit[fill=none]


bar
\end{document}

Code: Two Optional Parameters

\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}

\tikzset{%
    mystyle1/.style={fill=red,font={\bfseries}},
    mystyle2/.style={fill=yellow,draw=blue}
}

\NewDocumentCommand{\doit}{O{} O{}}{%
 \begin{tikzpicture}
  \node[mystyle1, circle, #1] at (0,0){Text1};
  \node[mystyle2, rectangle, #2] at (3,0){Text2};
 \end{tikzpicture}
}
\begin{document}
Foo

\doit

\doit[fill=none][fill=none]

\doit[fill=orange, draw=blue, ultra thick][fill=green!50, draw=magenta, ultra thick]

bar
\end{document}
share|improve this answer
    
Thanks. But I wanted a solution without redefining the styles. –  Toscho Jan 20 at 18:51
    
Perhaps I am not fully understanding your comment, but I am not redefining the styles, just adding to them as needed. Your complete style is applied then only what you specify in the optional parameter is overwritten. –  Peter Grill Jan 20 at 18:53
2  
I have made no changes to mystyle1 and mystyle2. –  Peter Grill Jan 20 at 19:49
    
Ah, sorry, confused the lines. –  Toscho Jan 21 at 16:42

One solution could be to define a style myfill which can be switched on and off.

\documentclass{article}
\usepackage{tikz}
\tikzset{myfill/.style={fill=#1}}

\tikzset{%
mystyle1/.style={myfill=red,font={\bfseries}},
mystyle2/.style={myfill=yellow,draw=blue}
}
\newcommand{\doit}{%
 \begin{tikzpicture}
  \node[mystyle1,circle]at(0,0){Text1};
  \node[mystyle2,rectangle] at (3,0){Text2};
 \end{tikzpicture}
}
\begin{document}
Foo

\doit

bar

\tikzset{myfill/.style=}
\doit

off
\end{document}

enter image description here

share|improve this answer

Thanks to inspiration from Thomas F. Sturm and Peter Grill I have found a nice solution for myself:

Just redefine the fill-style:

\tikzset{fill/.style={}}

Please comment, if this is an acceptable way or should be put into l2tabu.

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.