Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Does anyone know if it is possible to create a "lifted corner" or curved drop shadow effect for a text box?

Something similar to this drop shadow effect

share|improve this question
    
Related: tex.stackexchange.com/q/150580/1952 –  Ignasi May 26 at 16:23
    
@Ignasi You are right! I had voted for your answer half a year ago but forgot about it ... I like the lifted shadow feature and added it to version 3.05 of tcolorbox now. –  Thomas F. Sturm May 28 at 14:52

2 Answers 2

up vote 14 down vote accepted

Here's another approach using tcolorbox with version 3.05 (2014/05/28) or newer. The lifted shadow of the old answer below has become an integrated feature (with different implementation) and is available by the option drop lifted shadow, drop small lifted shadow, or drop large lifted shadow:

\documentclass{article}

\usepackage[many]{tcolorbox}
\usepackage{lipsum}

\begin{document}

\tcbox[enhanced,size=fbox,arc=0pt,outer arc=0pt,colback=blue!5!white,
  before=\centering,colframe=blue!15!white,drop small lifted shadow]
  {A small box with a small shadow}

\bigskip

\begin{tcolorbox}[enhanced,colback=white,colframe=black!50!white,boxrule=1pt,
  arc=0pt,outer arc=0pt,drop lifted shadow]
\lipsum[2]
\end{tcolorbox}

\bigskip

\begin{tcolorbox}[enhanced,colback=yellow!5!white,colframe=black!50!yellow,boxrule=1pt,
  drop lifted shadow]
\lipsum[2]
\end{tcolorbox}

\bigskip

\begin{tcolorbox}[enhanced,colback=red!5!white,colframe=black!50!red,boxrule=1pt,
  arc=0pt,outer arc=0pt,drop large lifted shadow]
\lipsum[2]
\end{tcolorbox}

\end{document}

enter image description here

Old version of the answer (valid for tcolorbox older than version 3.05):

The following code adds some new shadow features drop lifted shadow and drop heavy lifted shadow to tcolorbox.

\documentclass{article}

\usepackage[many]{tcolorbox}% until version 3.04
\usepackage{lipsum}

\makeatletter

\def\tcb@shadow@lifted#1#2#3#4{%
  \path[fill,rounded corners=\tcb@outer@arc,#4]
       ([xshift=#1+#3,yshift=#2+#3]frame.south west)
    .. controls ([yshift=\dimexpr#3]frame.south) ..
       ([xshift=-#1-#3,yshift=#2+#3]frame.south east)
    -- ([xshift=-#1-#3,yshift=#2-#3]frame.north east)
    -- ([xshift=#1+#3,yshift=#2-#3]frame.north west)
    -- cycle;
}

\tcbset{
  lifted shadow/.style args={#1#2#3#4}{shad@w app={%
    \begin{scope}[#4]%
      \tcb@shadow@lifted{#1}{#2}{\dimexpr-4\dimexpr#3}{opacity=0.01}%
      \tcb@shadow@lifted{#1}{#2}{\dimexpr-3\dimexpr#3}{opacity=0.02}%
      \tcb@shadow@lifted{#1}{#2}{\dimexpr-2\dimexpr#3}{opacity=0.04}%
      \tcb@shadow@lifted{#1}{#2}{\dimexpr-#3}{opacity=0.07}%
      \tcb@shadow@lifted{#1}{#2}{0pt}{opacity=0.11}%
      \tcb@shadow@lifted{#1}{#2}{\dimexpr+#3}{opacity=0.11}%
      \tcb@shadow@lifted{#1}{#2}{\dimexpr+2\dimexpr#3}{opacity=0.07}%
      \tcb@shadow@lifted{#1}{#2}{\dimexpr+3\dimexpr#3}{opacity=0.04}%
      \tcb@shadow@lifted{#1}{#2}{\dimexpr+4\dimexpr#3}{opacity=0.02}%
      \tcb@shadow@lifted{#1}{#2}{\dimexpr+5\dimexpr#3}{opacity=0.01}%
  \end{scope}}},%
  drop lifted shadow/.style={lifted shadow={1.5mm}{-1.5mm}{0.12mm}{#1}},
  drop lifted shadow/.default={black!50!white},%
  drop heavy lifted shadow/.style={lifted shadow={2mm}{-3mm}{0.16mm}{#1}},
  drop heavy lifted shadow/.default={black!50!white},%
}

\makeatother

\begin{document}

\begin{tcolorbox}[enhanced,colback=white,colframe=black!50!white,boxrule=1pt,
  arc=0pt,outer arc=0pt,drop lifted shadow]
\lipsum[2]
\end{tcolorbox}

\bigskip

\begin{tcolorbox}[enhanced,colback=yellow!5!white,colframe=black!50!yellow,boxrule=1pt,
  drop lifted shadow]
\lipsum[2]
\end{tcolorbox}

\bigskip

\begin{tcolorbox}[enhanced,colback=red!5!white,colframe=black!50!red,boxrule=1pt,
  arc=0pt,outer arc=0pt,drop heavy lifted shadow]
\lipsum[2]
\end{tcolorbox}

\end{document}

enter image description here

share|improve this answer
    
This seems like a nice option as well although having a lot of trouble getting it to compile using TeXLive (MacTeX). On first attempt, got error re. 'many' not valid option for tcolorbox so updated from 2012 to 2013. Now getting issue with the following error which I don't have much of a clue on: "Undefined control sequence. \pgfmath@dimen@ ...men@@ #1=0.0pt\relax \pgfmath@ l.43 \end{tcolorbox}" –  user52465 May 26 at 17:42
1  
@user52465 see How do I update my TeX distribution? –  cmhughes May 27 at 3:08
    
@user52465 The tcolorbox version of TeXLive 2013 is too old. You can get the recent version from CTAN by mirrors.ctan.org/install/macros/latex/contrib/tcolorbox.tds.zip For the further steps, see the link cmhughes has provided. –  Thomas F. Sturm May 27 at 5:25
    
Thanks Thomas. I updated all of the reported out of date packages which fixed the problem. –  user52465 May 28 at 1:05
    
great that it seems fixed. in the future to get an up-to-date version oftexlive, I suggest using homebrew + casks: github.com/meduz/dotfiles/blob/master/init/… –  meduz May 28 at 7:22

The following approach is a compromise between simple interface and code complexity. The result looks good imho.

\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[blur shadow={shadow xshift=0pt, shadow yshift=0pt, shadow blur steps=6}, #1]
        ($(#2.north west)+(.3ex,-.5ex)$)
        -- ($(#2.south west)+(.5ex,-.7ex)$)
        .. controls ($(#2.south)!.3!(#2.south west)$) .. (#2.south)
        .. controls ($(#2.south)!.3!(#2.south east)$) .. ($(#2.south east)+(-.5ex,-.7ex)$)
        -- ($(#2.north east)+(-.3ex, -.5ex)$)
        -- cycle;
    \end{pgfonlayer}
}

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

Results in:

Result

share|improve this answer
    
That's perfect! Thanks. –  user52465 May 26 at 14:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.