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.

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}
share|improve this question
    
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. –  Peter Grill Feb 2 '12 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} –  Peter Grill Feb 2 '12 at 17:16
    
@PeterGrill Agreed! Yes, you'll see in my screen shot, the shadow is there ,but it's not very pronounced :) –  cmhughes Feb 2 '12 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. –  Marco Daniel Feb 2 '12 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 Feb 2 '12 at 22:16
add comment

1 Answer

up vote 11 down vote accepted

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}

share|improve this answer
    
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 Feb 3 '12 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 Feb 4 '12 at 0:48
    
@cmhughes: Please see my edit –  Marco Daniel Feb 4 '12 at 10:32
1  
I guess \usetikzlibrary{shadows} is supposed to be there just once, not twice? –  Tom Bombadil Feb 4 '12 at 13:07
    
@TomBombadil: Indeed. Thanks. –  Marco Daniel Feb 4 '12 at 13:09
show 4 more comments

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.