14

What I was wondering is, if I can have a glow effect for a box I am drawing with TikZ. Neither search here nor the (excellent) TikZ manual returned any results. There is a circular glow option, but I don't think that helps in my case, or does it!?

Any input is appreciated :).

Edit: I figured that these blurred shadows seem to be a fairly special PDF feature which is supported by few PDF viewers only (actually Acrobat Reader 9 for Linux was the only one that worked for me).

Acrobat Reader Evince pdf.js (size of the blue box is the same)

8
  • I think the circular glow is exactly what you want. It's just a matter of defining the correct color for it. Perhaps you would need to apply some fading, but otherwise it seems good. Jan 30, 2012 at 16:25
  • 1
    I see some glows in How can we display fireworks?
    – Werner
    Jan 30, 2012 at 16:42
  • @Werner: Yes, but they are all circular glows. This question is about having a glow around a box [rectangle]. Jan 30, 2012 at 17:46
  • This is seemingly only possible if you know PostScript coding (which I don't) then you can use \pgfdeclarefunctionalshading. I tried a little but I can't modify the colors (e.g. stuck at yellow).
    – percusse
    Jan 31, 2012 at 2:20
  • Don;t be fooled by the name circular glow. It works just as well on a rectangle: \tikz\node[circular glow={fill=red}, fill=blue] {x}; works fine. Jan 31, 2012 at 8:47

2 Answers 2

12

This MWE is probably closer to your question:

    \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\def\shadowradius{3pt}
%
\newcommand\drawshadowbis[1]{
    \begin{pgfonlayer}{shadow}
        \fill[inner color=red,outer color=red!10!white] ($(#1.south west)$) circle (\shadowradius);
        \fill[inner color=red,outer color=red!10!white] ($(#1.north west)$) circle (\shadowradius);
        \fill[inner color=red,outer color=red!10!white] ($(#1.south east)$) circle (\shadowradius);
        \fill[inner color=red,outer color=red!10!white] ($(#1.north east)$) circle (\shadowradius);
        \fill[ top color=red, bottom color=red!10!white] ($(#1.south west)+((0,-\shadowradius)$) rectangle ($(#1.south east)$);
        \fill[left color=red,right color=red!10!white] ($(#1.south east)$) rectangle ($(#1.north east)+((\shadowradius,0)$);
        \fill[bottom color=red,top color=red!10!white] ($(#1.north west)$) rectangle ($(#1.north east)+((0,\shadowradius)$);
        \fill[right color=red,left color=red!10!white] ($(#1.south west)$) rectangle ($(#1.north west)+(-\shadowradius,0)$);
\end{pgfonlayer}
}
%
\pgfdeclarelayer{shadow} 
\pgfsetlayers{shadow,main}
\begin{tikzpicture}
   \node [fill=blue,rectangle,rounded corners=0pt,draw=blue, ultra thick, text=white] (box) {Test!!!};
   \drawshadowbis{box}
\end{tikzpicture}
\end{document} 

enter image description here

0
19

By modifying the Caramdir's code in this thread: Faded drop-shadow using tikz-based rounded rectangle?, I got this:

enter image description here

Here my MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\def\shadowradius{3pt}
%
\newcommand\drawshadowbis[1]{
    \begin{pgfonlayer}{shadow}
        \fill[inner color=blue,outer color=blue!10!black] ($(#1.south west)$) circle (\shadowradius);
        \fill[inner color=blue,outer color=blue!10!black] ($(#1.north west)$) circle (\shadowradius);
        \fill[inner color=blue,outer color=blue!10!black] ($(#1.south east)$) circle (\shadowradius);
        \fill[inner color=blue,outer color=blue!10!black] ($(#1.north east)$) circle (\shadowradius);
        \fill[ top color=blue, bottom color=blue!10!black] ($(#1.south west)+((0,-\shadowradius)$) rectangle ($(#1.south east)$);
        \fill[left color=blue,right color=blue!10!black] ($(#1.south east)$) rectangle ($(#1.north east)+((\shadowradius,0)$);
        \fill[bottom color=blue,top color=blue!10!black] ($(#1.north west)$) rectangle ($(#1.north east)+((0,\shadowradius)$);
        \fill[right color=blue,left color=blue!10!black] ($(#1.south west)$) rectangle ($(#1.north west)+(-\shadowradius,0)$);
\end{pgfonlayer}
}
%
\pgfdeclarelayer{shadow} 
\pgfsetlayers{shadow,main}
\begin{tikzpicture}
   \node [fill=blue,rectangle,rounded corners=0pt,draw=blue, ultra thick, text=white] (box) {Test!!!};
   \drawshadowbis{box}
\end{tikzpicture}
\end{document} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .