## Background

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

## Problem

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

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


## Question

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

-
@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
@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

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

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{shapes.symbols}

\begin{document}

\begin{center}
\begin{tikzpicture}
top color=blue!40,
bottom color=blue!5,
rounded corners=6pt,
] {\sffamily\bfseries\large A pretty box};

top color=blue!40,
bottom color=blue!5,
rounded corners=1pt,
] 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.
-
@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

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

% this draws a shadow under a rectangle node
\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

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


-
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
@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

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

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (3,2);
bottom color=white,
rounded corners },
rounded corners,
top color= blue, bottom color=white]
(0,0) rectangle (6,3);

\end{tikzpicture}
\end{document}


-
@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

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


2. Now you can define use shadow

\tikzstyle{use shadow} = [
fill=gray!25,
draw=none,
}]

3. next you need to define epibox

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


with

\tikzstyle{use shadow} = [
fill=gray!25,
draw=none,
]


you get :

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 =...}}

-
@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 layer`in the link. – Alain Matthes Feb 17 '11 at 22:52
@Dave: I modify my code because now I understand what is layer shadow. – Alain Matthes Feb 18 '11 at 6:33
@Altermundus: I've fixed your code blocks. In lists, you need to indent by 8 spaces! – Hendrik Vogt Feb 18 '11 at 7:00