Example: Transparent shadows

Published 2007-07-27 | Author: Dawid Weiss

An interesting technique for creating text boxes with soft semitransparent shadows. Can for instance be used to spice up a Beamer presentation. The shadows are created by drawing a series of rectangles with varying transparency.

Author:Dawid Weiss
Source:The Latex-beamer-users mailing list

Download as: [PDF] [TEX]

Transparent shadows

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

% Author: Dawid Weiss (http://www.dawidweiss.com/)

% Boxed environment with semi-transparent shadow.


    \addtolength{\boxw}{\boxroundness * 2}
    \addtolength{\boxh}{\boxroundness * 2}

    \foreach \x in {0,.05,...,1}
        \setlength{\tmpa}{\shadowsize * \real{\x}}
        \fill[xshift=\shadowsize - 1pt,yshift=-\shadowsize + 1pt,
                black,opacity=.04,rounded corners=\boxroundness]
            (\tmpa, \tmpa) rectangle +(\boxw - \tmpa - \tmpa,
                \boxh - \tmpa - \tmpa);

    \filldraw[fill=yellow!50, draw=black!50, rounded corners=\boxroundness]
        (0, 0) rectangle (\boxw, \boxh);
    \draw node[xshift=\boxroundness,yshift=\boxroundness,
        inner sep=0pt,outer sep=0pt,anchor=south west]
             (0,0) {\usebox{\shadowblockbox}};


% We prepare a transparent box first.
This is a block of text with a transparent

% Over existing text
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus in nunc
tincidunt sapien sodales tincidunt. Nulla posuere semper nunc. Duis lacinia
libero non arcu. Nam quis eros id tortor ultricies fermentum. Aenean vulputate
adipiscing nulla. Etiam fermentum elit ut est. Duis at est at enim imperdiet
vestibulum. In risus dui, malesuada eu, fermentum vel, adipiscing sodales, eros.
Praesent egestas. Aliquam auctor. Maecenas vulputate mollis est. Nam varius. Nam
%auctor fermentum tellus. Curabitur lacus sapien, scelerisque vulputate,
%consectetuer laoreet, fringilla laoreet, tellus. Duis dignissim est non mauris.
%Nam magna velit, pulvinar vel.


% Over a picture.

% Absolute positioning with textpos

And a small one on top of it.

Absolutely positioned box with a lot of text.
Absolutely positioned box with a lot of text.
Absolutely positioned box with a lot of text.
Absolutely positioned box with a lot of text.



  • #1 Kjell Magne Fauske, November 5, 2008 at 8:42 a.m.

    This example is tagged as deprecated because PGF >= 2.0 ships with a library for creating shadow effects. You can see a few example in the TikZ and PGF version 2.0 example.

Adding comments is currently not enabled.