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.

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}
share|improve this question
    
Here is hack that seems to work: drop shadow={fill=white, opacity=1, draw=white}. –  Peter Grill Aug 28 at 1:20
    
@PeterGrill Unfortunately, that only colours the shadow white; that won't do, because I may have stuff in the background. –  Jubobs Aug 28 at 7:38

2 Answers 2

up vote 8 down vote accepted

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}
share|improve this answer
    
Thanks for that, Paul. –  Jubobs Aug 28 at 7:35
    
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 Aug 28 at 10:49
1  
@skpblack: Try the following: \begin{scope}[every node/.append style={reset preaction}] –  Claudio Fiandrino Aug 28 at 11:51

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

share|improve this answer
    
Thanks; that works too, but I find Paul's approach easier to use. –  Jubobs Aug 28 at 7:34
    
@Jubobs That is the difference between an expert (who knows internal code of tikz) and a beginner. –  skpblack Aug 28 at 10:19

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.