8

I would like to draw a box like this:

enter image description here

I'm especially interested in both

  1. how to draw a shadow that comes out from the sides only (not also top or bottom) and
  2. how to draw two shadows, the bigger left-right shadow and the smaller outline border one.

I've tried many approaches but it seems I'm completely off track here since I can't even draw the left-right bigger shadow, so I would appreciate if someone could explain me where to start here.

Clarifications. I think the picture is compose by 4 parts:

1) the background (uninteresting here)

2) the white rectangle

3) the rectangle borders-edges (what I previously referred as the smaller shadow) with a ridge like effect

4) the left and right shadows

I'm trying to draw parts 3 and 4.

knut
  • 123
  • The smaller outline border shadow? Where? (Do you mean the slightly darker edges on the rectangle?) I can only see the one at the left and right. – Qrrbrbirlbel Oct 27 '13 at 16:07
  • @Qrrbrbirlbel I added a small clarification, BTW it's like you said, I was referring to the edges. – knut Oct 27 '13 at 16:42

3 Answers3

8

Some ideas, lots of hardcoded magic numbers (found by trial and error):

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{backgrounds, calc, shadows, shadows.blur}

\newcommand\addcurlyshadow[2][]{
    % #1: Optional aditional tikz options
    % #2: Name of the node to "decorate"
    \begin{pgfonlayer}{background}
        \path[
           rounded corners=1pt,
           blur shadow={shadow xshift=0pt,
           shadow yshift=-0.3pt,
           shadow blur steps=6,
           shadow blur radius=.6pt}, #1]
            ($(#2.north west)+( 0.3pt,0)$) --
            ($(#2.south west)+( 0.3pt,0)$) --
            ($(#2.south east)+(-0.3pt,0)$) --
            ($(#2.north east)+(-0.3pt,0)$) --
        cycle;
        \path[rounded corners,
           blur shadow={shadow xshift=0pt,
           shadow yshift=0pt,
           shadow blur steps=8,
           shadow blur radius=2pt}, #1]
            ($(#2.north west)+(-1pt,-2pt)$) --
            ($(#2.south west)+(-1pt, 2pt)$) --
            ($(#2.south east)+( 1pt, 2pt)$) --
            ($(#2.north east)+( 1pt,-2pt)$) --
            cycle;
    \end{pgfonlayer}
}

\begin{document}
\begin{tikzpicture}
    \begin{pgfonlayer}{background}
    \fill[black!20] (-3,-1) rectangle (3,1);
    \end{pgfonlayer}
    \node[fill=white, rectangle, minimum width=3cm, minimum height=1cm]
       (example) {Test};
    \addcurlyshadow{example}
\end{tikzpicture}
\end{document}

Result:

Result

JLDiaz
  • 55,732
5

An idea that needs xscale around and yscale around. Better results can probably achieved with a custom fading that works similar to circle with fuzzy edge XX percent (see circular shadow and circular glow) but for rectangles.

Code

\documentclass[tikz,border={3pt 0pt 3pt 0pt}]{standalone}
\usetikzlibrary{shadows,chains}
\makeatletter
\tikzset{
  xscale around/.code=%
    \tikz@addtransform{\def\tikz@aroundaction{\pgftransformxscale}\tikz@doaround{#1}},
  yscale around/.code=%
    \tikz@addtransform{\def\tikz@aroundaction{\pgftransformyscale}\tikz@doaround{#1}},
  shadow xscale/.initial=1, shadow yscale/.initial=1,
  shadow scale/.style={shadow xscale={#1}, shadow yscale={#1}},
  general shadow/.style={
    preaction={#1,
      transform canvas={
        xscale around=%
          \pgfkeysvalueof{/tikz/shadow xscale}:(current path bounding box.center),
        yscale around=%
          \pgfkeysvalueof{/tikz/shadow yscale}:(current path bounding box.center),
        shift=%
          {(\pgfkeysvalueof{/tikz/shadow xshift},\pgfkeysvalueof{/tikz/shadow yshift})}
      }}},
  my shadow/.style={general shadow={
      shadow xscale=1.1, shadow yscale=.9, opacity=.75, top color=gray!10,
      bottom color=gray!10, middle color=gray!50, every shadow, #1}}}
\makeatletter
\begin{document}
\begin{tikzpicture}[start chain=ch0 going below, node distance=.2cm,
                    nodes={draw, fill=white, my shadow, on chain=ch0}]
\node                     {Effect 8};
\node[minimum height=+2cm]{Effect 9};
\node[minimum width =+2cm]{Effect 10};
\end{tikzpicture}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
  • 1
    this works "in principle", but the result is very far from the original picture. I was looking to fully reproduce it. – knut Oct 29 '13 at 12:51
3

Still far away from expected results but here it is another approximation with tcolorbox

\documentclass[border=5mm]{standalone}
\usepackage[most]{tcolorbox}

\begin{document}

\tcbset{width=.5\linewidth, height=3cm, valign=center, center upper, sharp corners, enhanced, frame hidden, fontupper=\sffamily\Huge,colback=white,
fuzzy halo=.1pt with black!35,
overlay unbroken={
\shade[left color=black!30] ([yshift=-3mm]frame.north east) 
sin +(1mm,-1.5mm) cos +(1mm,-1.5mm)--
([xshift=2mm,yshift=6mm]frame.south east)
sin +(-1mm,-1.5mm)  cos +(-1mm,-1.5mm);
\shade[right color=black!30, left color=white] ([yshift=-3mm]frame.north west) 
sin +(-1mm,-1.5mm) cos +(-1mm,-1.5mm)--
([xshift=-2mm,yshift=6mm]frame.south west)
sin +(1mm,-1.5mm)  cos +(1mm,-1.5mm);
}}

\begin{tcolorbox}
Effect 8
\end{tcolorbox}

\end{document}

enter image description here

Ignasi
  • 136,588