PGF/TikZ Manual

The TikZ and PGF Packages
Manual for version 3.1.9a

Libraries

70Shadows Library

  • TikZ Library shadows

  • \usetikzlibrary{shadows} % and plain
    \usetikzlibrary[shadows] % Cont

    This library defines styles that help adding a (partly) transparent shadow to a path or node.

70.1Overview

A shadow is usually a black or gray area that is drawn behind a path or a node, thereby adding visual depth to a picture. The shadows library defines options that make it easy to add shadows to paths. Internally, these options are based on using the preaction option to use a path twice: Once for drawing the shadow (slightly shifted) and once for actually using the path.

Note that you can only add shadows to paths, not to whole scopes.

In addition to the general shadow option, there exist special options like circular shadow. These can only (sensibly) be used with a special kind of path (for circular shadow, a circle) and, thus, they are not as general. The advantage is, however, that they are more visually pleasing since these shadows blend smoothly with the background. Note that these special shadows use fadings, which few printers will support.

70.2The General Shadow Option

The shadows are internally created by using a single option called general shadow. The different options like drop shadow or copy shadow only differ in the commands that they preset.

You will not need to use this option directly under normal circumstances.

  • /tikz/general shadow=shadow options (default empty)

  • This option should be given to a \path or a node. It has the following effect: Before the path is used normally, it is used once with the shadow options in force. Furthermore, when the path is “preused” in this way, it is shifted and scaled a little bit.

    In detail, the following happens: A preaction is used to paint the path in a special manner before it is actually painted. This “special” manner is as follows: The options in shadow options are used for painting this path. Typically, the shadow options will contain options like fill=black to create, say, a black shadow. Furthermore, after the shadow options have been set up, the following extra canvas transformations are applied to the path: It is scaled by shadow scale (with the origin of scaling at the path’s center) and it is shifted by shadow xshift and shadow yshift.

    Note that since scaling and shifting is done using canvas transformations, shadows are not taken into account when the picture’s bounding box is computed.

    (-tikz- diagram)

    \usetikzlibrary {shadows}
    \tikz [even odd rule]
    \draw [general shadow={fill=red}] (0,0) circle (.5) (0.5,0) circle (.5);
    • /tikz/shadow xshift=dimension (no default, initially 0pt)

    • Shadows are shifted horizontally by dimension.

      (-tikz- diagram)

      \usetikzlibrary {shadows}
      \tikz [even odd rule]
      \draw [general shadow={fill=red,shadow xshift=-5pt}]
      (0,0) circle (.5) (0.5,0) circle (.5);
    • /tikz/shadow yshift=dimension (no default, initially 0pt)

    • Shadows are shifted vertically by dimension.

70.3Shadows for Arbitrary Paths and Shapes
70.3.1Drop Shadows
70.3.2Copy Shadows

A copy shadow is not really a shadow. Rather, it looks like another copy of the path drawn behind the path and a little bit offset. This creates the visual impression of having multiple copies of the path/object present.

  • /tikz/copy shadow=shadow options (default empty)

  • This shadow installs the following default options:


    shadow scale=1, shadow xshift=.5ex, shadow yshift=-.5ex, every shadow

    Furthermore, the options fill=fill color and draw=draw color are also set, where the fill color and draw color are the fill and draw colors used for the main path.

    (-tikz- diagram)

    \usetikzlibrary {shadows,shapes.symbols}
    \begin{tikzpicture}
    \node [copy shadow,fill=blue!20,draw=blue,thick] {Hello World!};

    \node at (0,-1) [copy shadow={shadow xshift=1ex,shadow yshift=1ex},
    fill=blue!20,draw=blue,thick]
    {Hello World!};

    \node at (0,-2) [copy shadow={opacity=.5},tape,
    fill=blue!20,draw=blue,thick]
    {Hello World!};

    % We have to repeat the left color since shadings are not
    % automatically applied to shadows
    \node at (0,-3) [copy shadow={left color=blue!50},
    left color=blue!50,draw=blue,thick]
    {Hello World!};
    \end{tikzpicture}
70.4Shadows for Special Paths and Nodes

The shadows in this section should normally be added only to paths that have a special shape. They will look strange with other shapes.

  • /tikz/circular drop shadow=shadow options(no default)

  • This shadow works like a drop shadow, only it adds a circular fading to the shadow. This means that the shadow will fade out at the border. The following options are preset for this shadow:


    shadow scale=1.1, shadow xshift=.3ex, shadow yshift=-.3ex,
    fill=black, path fading={circle with fuzzy edge 15 percent},
    every shadow,

    (-tikz- diagram)

    \usetikzlibrary {shadows}
    \begin{tikzpicture}
    \foreach \i in {1,...,8}
    \node[circle,circular drop shadow,draw=blue,fill=blue!20,thick]
    at (\i*45:1) {Circle \i};
    \end{tikzpicture}