[Tex/LaTex] Faded drop-shadow using tikz-based rounded rectangle

boxesrounded-cornersshadowstikz-pgf

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?

Best Answer

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.
Related Question