13

In the example below, the style I've defined for every node uses a drop shadow. My a node uses that default style without modification. However, I'd like to override that style for node b, which should have no shadow at all.

I've tried to

  • pass fill opacity=0 to drop shadow locally, or
  • pass nothing to the option (drop shadow=,),

but node b still has a shadow.

I've read section 66 of the TikZ/PGF (v3.0) manual about the shadows library, but I haven't found a way of overriding a drop shadow style. Any help?

enter image description here

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,shadows}

\tikzset{
  every node/.style={
    draw,
    drop shadow = {opacity=0.5,fill=red},
    fill        = white,
  },
}

\begin{document}
\begin{tikzpicture}
\node (a) {a};
\node[
  right=of a,
  drop shadow={opacity=0}, % the shadow is still there
% drop shadow=,            % also no effet
] (b) {b};
\end{tikzpicture}
\end{document}
2
  • 1
    Here is hack that seems to work: drop shadow={fill=white, opacity=1, draw=white}. Commented Aug 28, 2014 at 1:20
  • @PeterGrill Unfortunately, that only colours the shadow white; that won't do, because I may have stuff in the background.
    – jub0bs
    Commented Aug 28, 2014 at 7:38

2 Answers 2

12

A shadow adds a preaction. TikZ does not provide a way to remove preactions. In your preamble, you may define your own reset preactions key :

\makeatletter
\tikzset{reset preactions/.code={\def\tikz@preactions{}}}
\makeatother

Here is a complete example:

enter image description here

\documentclass[margin=2mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning,shadows}

\makeatletter
\tikzset{reset preactions/.code={\def\tikz@preactions{}}}
\makeatother

\tikzset{
  every node/.style={
    draw,
    drop shadow = {opacity=0.5,fill=red},
    fill        = white,
  },
}

\begin{document}
\begin{tikzpicture}
\node (a) {a};
\node[right=of a,reset preactions] (b) {b};
\end{tikzpicture}
\end{document}

As suggested by Claudio Fiandrino in its comment, to apply this new key to all nodes in a scope, you may append it to every node style:

\documentclass[margin=2mm]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning,shadows}

\makeatletter
\tikzset{reset preactions/.code={\def\tikz@preactions{}}}
\makeatother

\tikzset{
  every node/.style={
    draw,
    drop shadow = {opacity=0.5,fill=red},
    fill        = white,
  },
}

\begin{document}
\begin{tikzpicture}
\node (a) {a};
\begin{scope}[every node/.append style={reset preactions}]
  \node[right=of a] (b) {b}; 
  \node[right=of b] (c) {c};
\end{scope}
\end{tikzpicture}
\end{document}
2
  • However, i don't know how to do it work in several nodes enclosed in a scope (like in my answer) without add reset preaction in each one.
    – skpblack
    Commented Aug 28, 2014 at 10:49
  • 1
    @skpblack: Try the following: \begin{scope}[every node/.append style={reset preaction}] Commented Aug 28, 2014 at 11:51
10

What if we enclose the node (or nodes that we don't want to shade) in a scope with the option general shadow/.style={}?

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,shadows}

\tikzset{
  every node/.style={
    draw,
    drop shadow = {opacity=0.5,fill=red},
    fill        = white,
  },
}

\begin{document}
\begin{tikzpicture}
\node (a) {a};
\begin{scope}[general shadow/.style={}]
\node[right=of a] (b) {b};
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

With more nodes we can better observe the effect.

\begin{tikzpicture}
\node (a) {a};
\begin{scope}[general shadow/.style={}]
\node[right=of a] (b) {b};
\node[right=of b] (c) {c};
\end{scope}
\node[right=of c] (d) {d};
\end{tikzpicture}

enter image description here

3
  • Thanks; that works too, but I find Paul's approach easier to use.
    – jub0bs
    Commented Aug 28, 2014 at 7:34
  • @Jubobs That is the difference between an expert (who knows internal code of tikz) and a beginner.
    – skpblack
    Commented Aug 28, 2014 at 10:19
  • I like your solution (I've just been reading about scopes, and it's a good illustration).
    – PatrickT
    Commented May 20, 2016 at 20:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .