10

I'm attempting to make a drop shadow environment using mdframed and tikz. So far, I have (perhaps naively) tried

\newmdenv[tikzsetting={fill=green!20,drop shadow}]{myshadowbox}

I know that shadow-boxes can be made using fancybox and ntheorem with PSTricks, but I'm particularly interested in seeing a solution using mdframed and tikz.

The MWE below produces a framed environment, and with the rounded corners you can see a shadow has been drawn (in the bottom right corner, look carefully!), but I can't seem to move it- I've tried passing options to drop shadow such as shadow xshift=-5ex but with no success.

So, how can I add and customize a drop shadow when using a newmdenv?

screenshot

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}
\usetikzlibrary{shadows}

\newmdenv[tikzsetting={fill=green!20,drop shadow},
                roundcorner=10pt ]{myshadowbox}

\begin{document}

\begin{myshadowbox}
\lipsum[2]
\end{myshadowbox}

\end{document}
5
  • The shadow is there, just hard to see. I was sure the solution was to add shadow={shadow xshift=1.0ex, shadow yshift=-0.2em} to make the shadow more obvious but that does not appear to be sufficient. If you include opacity=1 with the shadow options that makes it more easier to see that it is there. Commented Feb 2, 2012 at 17:07
  • This seems produce a shadow but I feel you should be able to do better: \newmdenv[ tikzsetting={ fill=green!20, drop shadow={ shadow xshift=1.0ex, shadow yshift=-0.5em, fill=black!50, opacity=1, every shadow } }, roundcorner=10pt, outerlinewidth=3.0pt ]{myshadowbox} Commented Feb 2, 2012 at 17:16
  • @PeterGrill Agreed! Yes, you'll see in my screen shot, the shadow is there ,but it's not very pronounced :)
    – cmhughes
    Commented Feb 2, 2012 at 17:23
  • @cmhughes: I use the function clip to get the correct width of the frame. This was the easiest way to handle three lines. I provided the command \mdfcreateextratikz (not documented yet) which can be redefined inside the key settings. At the moment I can create any example. Tomorrow I have LateX to build such one. Commented Feb 2, 2012 at 21:53
  • @MarcoDaniel Ok, great! Thanks for the explanation! Glad I didn't miss anything in the documentation (which is excellent) :) Thanks for such a great package
    – cmhughes
    Commented Feb 2, 2012 at 22:16

1 Answer 1

12

Completely EDIT 2012-03-04:

I uploaded the new version 1.3 to CTAN. At the moment the files are available at github.

This version provides a key named shadow. This allows to draw a shadow. The shadow can be manipulated by the new keys shadowsize and shadowcolor

If you use framemethod=tikz it is important to load the TikZ library shadows.

mdframed can do the job but I don't want to load any libraries.

For the methods TikZ and PSTricks I defined a style mdfshadow by tikzset / newpsstyle. For more settings manipulate this key.

Based of the new modification I created the following example:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}
\usetikzlibrary{shadows}
\newmdenv[tikzsetting={fill=green!20},
          roundcorner=10pt,shadow=true]{myshadowbox}

\begin{document}

\begin{myshadowbox}
\lipsum[2]
\end{myshadowbox}
\lipsum[3]
\begin{myshadowbox}
\lipsum
\end{myshadowbox}
\end{document}

The result is: enter image description here

An other example is provided in file mdframed-example-pstricks.pdf which uses pstricks and frametitle:

\documentclass{article}
\usepackage{xcolor}
\usepackage[framemethod=pstricks]{mdframed}
\usepackage{lipsum}

\newmdenv[%
          shadow=true,
          shadowsize=11pt,
          linewidth=8pt,
          frametitlerule=true,
          roundcorner=10pt,
          ]{myshadowbox}

\begin{document}
\begin{myshadowbox}[frametitle={Der Beweis}]
\lipsum[2]
\end{myshadowbox}
\end{document}

8
  • Brilliant! This works really well! I'll leave it the question active for a few more hours, and will accept later on :) What's the best way to know when you have updated the package on ctan? Thanks again, and thanks for such a great, user-friendly package :)
    – cmhughes
    Commented Feb 3, 2012 at 18:40
  • I just tried it with a page break- it looses the shadow. I actually kind of like that feature though- did you intend it?
    – cmhughes
    Commented Feb 4, 2012 at 0:48
  • @cmhughes: Please see my edit Commented Feb 4, 2012 at 10:32
  • 1
    I guess \usetikzlibrary{shadows} is supposed to be there just once, not twice? Commented Feb 4, 2012 at 13:07
  • This is great, thanks so much :) Is the new version available on ctan as well? I've never worked with github before.
    – cmhughes
    Commented Feb 4, 2012 at 16:20

You must log in to answer this question.

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