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.

Background

Epigraphs are in a box with rounded corners. The boxes have a drop-shadow.

Example

Picture #1 shows a shadow, while Picture #2 shows a shadow that fades out (soft blur):

  1. shadow
  2. blurred shadow

Problem

The code for Picture #1, which is relatively simple, resembles:

\tikzstyle{epibox} = [
  draw=epigraphbordercolour,
  shade,
  top color=epigraphfillcolour!40,
  bottom color=epigraphfillcolour!5,
  drop shadow=dropshadowcolour,
  very thick,
  rectangle,
  rounded corners,
  inner sep=10pt,
  inner ysep=15pt
]

Related

Question

How do you make a drop-shadow fade out using Tikz, such as Picture #2?

share|improve this question
    
@Caramdir: This thorough edit should make you a top candidate in the election! –  Hendrik Vogt Feb 17 '11 at 10:44
    
@Hendrik: I'm not sure what you mean. I just deleted a bunch of unnecessary stuff from a MWE (like I did several times before). –  Caramdir Feb 17 '11 at 15:44
1  
@Caramdir: I don't understand the "just" here. It seems that you very carefully deleted half of the code, thus improving the question a lot. I found that rather admirable, and I'm being plain serious here. –  Hendrik Vogt Feb 17 '11 at 15:47
add comment

4 Answers

up vote 16 down vote accepted

You could use the pgf-blur package, which gives you this:

a rounded rectangle node with faded drop shadow

In fact, it can add a "faded" drop shadow to pretty much anything:

a slightly rounded tape node with faded drop shadow

The shadow fading is not continuous, like in the previously accepted answer. It fades in a number of discrete steps, but that number can be changed, see the documentation.

Here's the code for the examples:

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{shadows.blur}
\usetikzlibrary{shapes.symbols}

\begin{document}


\begin{center}
  \begin{tikzpicture}
    \node[draw=none,shade,
      top color=blue!40,
      bottom color=blue!5,
      rounded corners=6pt,
      blur shadow={shadow blur steps=5}
    ] {\sffamily\bfseries\large A pretty box};

    \node[tape,draw=none,shade,
      top color=blue!40,
      bottom color=blue!5,
      rounded corners=1pt,
      blur shadow={shadow blur steps=5,shadow blur extra rounding=1.3pt}
    ] at (5,0){\sffamily\bfseries\large Another pretty box};
  \end{tikzpicture}
\end{center}

\end{document}

Edit

Sometimes, PDF renderers will show a dark line in the center of the shadow. This is due to the way they handle anti-aliasing and clipping. To avoid this:

  1. Use pgf-blur v1.01, which tries hard to hide this artefact
  2. In Acrobat, turn off the "Page Display" preference "Enhance thin lines". These shadows consist of many thin lines, and they won't look good if Acrobat changes their width
  3. Don't use too many blur shadow steps. It looks best if you have about two pixels per step at viewing resolution.
share|improve this answer
    
@DaveJarvis yes, I know. Very annoying. In acrobat, it seems to be 1px wide, no matter how much you zoom in. So I think it might be a bug in how clipping is rendered. In xpdf it looks slightly better. –  mabartibin Apr 21 '12 at 18:36
    
Or let me correct this: at some magnifications, there's a 1px dark line, at others there aren't. My screen shots were taken at an unfortunate resolution. In normal usage, e.g. in a presentation, with subtle shadows (not demo-sized) you won't see a line... I think I'll uploade better screen shots! –  mabartibin Apr 21 '12 at 18:46
    
There, these are screen shots from Mac OS X preview. Still some dark lines, but a lot more subtle. –  mabartibin Apr 21 '12 at 19:05
    
Actually the lines have to do with the way anti-aliasing works together with clipping. Turning off "smooth line art" in Acrobat eliminates the problem completely. No idea how this might be fixed. –  mabartibin Apr 22 '12 at 17:28
add comment

The following isn't entirely correct (it doesn't take rounded corners into account), but should suffice for most applications. Note that if you want to replace the shading by fading (i.e. use actual transparency), you will probably have to add clipping to the circles (so that they don't overlap with the rectangles). Also note that the effect seems to be rendered slightly incorrectly in Evince (and maybe some other pdf viewers too; the image is from the Linux version of Acrobat Reader).

\documentclass{article}    
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

% some parameters for customization
\def\shadowshift{5pt,-10pt}
\def\shadowradius{10pt}

% this draws a shadow under a rectangle node
\newcommand\drawshadow[1]{
    \begin{pgfonlayer}{shadow}
        \shade[white,inner color=black,outer color=white] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
        \shade[white,inner color=black,outer color=white] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
        \shade[white,inner color=black,outer color=white] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) circle (\shadowradius);
        \shade[white,inner color=black,outer color=white] ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,-\shadowradius/2)$) circle (\shadowradius);
        \shade[top color=black,bottom color=white] ($(#1.south west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
        \shade[left color=black,right color=white] ($(#1.south east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
        \shade[bottom color=black,top color=white] ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$);
        \shade[white,right color=black,left color=white] ($(#1.south west)+(\shadowshift)+(-\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north west)+(\shadowshift)+(\shadowradius/2,-\shadowradius/2)$);
        \filldraw ($(#1.south west)+(\shadowshift)+(\shadowradius/2,\shadowradius/2)$) rectangle ($(#1.north east)+(\shadowshift)-(\shadowradius/2,\shadowradius/2)$);
    \end{pgfonlayer}
}

% create a shadow layer, so that we don't need to worry about overdrawing other things
\pgfdeclarelayer{shadow} 
\pgfsetlayers{shadow,main}

\begin{tikzpicture}
    \node [fill=blue,rectangle,rounded corners,minimum height=2cm,minimum width=2cm] (box) {};
    \drawshadow{box}
\end{tikzpicture}  
\end{document}

result

share|improve this answer
    
Good try ! with OS X, I have some small lines around the shadows and around the rectangle inside the shadows. The result is correct with Adobe Reader. –  Alain Matthes Feb 19 '11 at 7:47
    
A very close emulation. Thank you! –  Dave Jarvis Feb 19 '11 at 8:54
    
@Altermundus: I have the same with Evince. The white lines inside can be removed by making the inner rectangle a bit larger, the black lines at the outside by overdrawing with white lines (this is the reason for the \filldraw, btw). –  Caramdir Feb 19 '11 at 16:54
    
I have edited to replace \filldraw and \fill commands with \shade , one may also use impressive for better quality output of a presentation. –  g24l Apr 7 '12 at 14:29
add comment

You forgot a lot of things

  1. You need to define layers (from the last link but it's very tricky but good from Mark Wibrow)

    \makeatletter
    \let\tikz@preaction@layer=\pgfutil@empty     
    \tikzset{preaction layer/.store in=\tikz@preaction@layer} 
    \makeatother
    
    \pgfdeclarelayer{shadow} 
    \pgfsetlayers{shadow,main}
    
  2. Now you can define use shadow

    \tikzstyle{use shadow} = [
        copy shadow={%
          preaction layer=shadow,
          fill=gray!25,
          draw=none,
          shadow xshift=1em,
          shadow yshift=-1em
       }]   
    
  3. next you need to define `epibox

    \tikzstyle{epibox} = [
      draw=epigraphbordercolour,
      shade,
      top color=epigraphfillcolour!40,
      bottom color=epigraphfillcolour!5,
      %drop shadow=dropshadowcolour,
      use shadow,
      very thick,
      rectangle,
      rounded corners,
      inner sep=10pt,
      inner ysep=15pt
    ]
    

shadow box

with

\tikzstyle{use shadow} = [
      preaction layer=shadow,
      fill=gray!25,
      draw=none,
      shadow xshift=1em,
      shadow yshift=-1em
    ] 

you get : box2

I don't know exactly what you want, perhaps it's a mix of the two codes.

I think it's preferable now to use \tikset{use shadow/.style =...}}

share|improve this answer
    
@Dave: Sorry there was a typo in my code but maybe you saw it : " before the last brace. I modified the code. I use pgf 2.1 and the code works fine. You have not told me what is preaction layer. I never see this code. –  Alain Matthes Feb 17 '11 at 22:26
    
@Dave: you have pgf 2.1 or 2.0 ? –  Alain Matthes Feb 17 '11 at 22:30
    
@Dave: Sorry but I don't see preaction layerin the link. –  Alain Matthes Feb 17 '11 at 22:52
    
@Altermundus: I managed to get your example to work; I made a mistake. A few issues. (1) It is more complicated than what I already had (that was working). (2) I can do a simple drop-shadow, no problem. (3) The issue is getting the drop-shadow to fade. I have updated the question to show an example of a fading drop-shadow. Thanks again! –  Dave Jarvis Feb 18 '11 at 0:06
    
@Dave: I modify my code because now I understand what is layer shadow. –  Alain Matthes Feb 18 '11 at 6:33
show 3 more comments

Sorry but my english language is poor, now you question is more easy to understand !

\documentclass{article}  
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{shadows,fadings}

\begin{document}  
 \begin{tikzpicture} 
   \draw [help lines] (0,0) grid (3,2); 
   \filldraw [drop shadow={top color=black,
              bottom color=white,
              shadow xshift=1em,
              shadow yshift=-1em,
              rounded corners },
              rounded corners,
              top color= blue, bottom color=white]
(0,0) rectangle (6,3);

\end{tikzpicture} 
\end{document} 

drop shadow rectangular bow with fading

share|improve this answer
    
@Dave: the problem is the effect you want don't exist in TikZ with rectangular shape. From the pgfmanual : The shadows in this section should normally be added only to paths that have a special shape. They will look strange with other shapes.. The only shape is the circlar shape. Radial effect is possible. I think it's difficult to get this effect with TikZ. –  Alain Matthes Feb 18 '11 at 11:24
    
@Dave: Finally the answer for your question is No with TikZ! I think the only possibility if you know how to program with postcript, is to read the section : General (Functional) Shadings in the pgfmanual and after to use a macro like \pgfdeclarefunctionalshading. –  Alain Matthes Feb 18 '11 at 12:47
add comment

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.