3

I want to create a digression using mdframed. I want it to have rounded corners, so I load it with option [framemethod=tikz]. Because of this, the problem arises that the standard framebox I use for my tikzpictures is also put around the mdframed-box, resulting in a really ugly double-frame. I tried the advice I got in this question, but I couldn´t pass the TikZ-key to mdframed.

MWE-pic

What I ultimately want to achieve is a frame with rounded corners and grey background. Here is my MWE:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage[framemethod=tikz]{mdframed}
\tikzset{every picture/.style={framed,background rectangle/.style={draw=black!80,rounded corners=.5ex}}}

\begin{document}
\begin{mdframed}[backgroundcolor=black!10!white]
Plain text.
Or something else.
\end{mdframed}
\end{document}

How can I prevent the outer frame?

4

Since you want to disable the every picture style for mdframe, you can use:

\AtBeginEnvironment{mdframed}{%
    \tikzset{every picture/.style={}}%
}

and then use \mdfsetup{} to apply the roundcorner to the mdframe:

\mdfsetup{roundcorner=.5ex}

This way the tikzpicture environment still gets the desired frame, and the mdframe does not get affected:

enter image description here

Code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{backgrounds}
\usepackage[framemethod=tikz]{mdframed}

\tikzset{every picture/.style={framed,background rectangle/.style={draw=red!80,rounded corners=.5ex, inner sep=0pt}}}%

\AtBeginEnvironment{mdframed}{%
    \tikzset{every picture/.style={}}%
}
\mdfsetup{roundcorner=.5ex}

\begin{document}
\noindent
\begin{tikzpicture}
    \draw [fill=yellow] (0,0) rectangle (2,3);
\end{tikzpicture}

\begin{mdframed}[backgroundcolor=black!10!white]
Plain text.
Or something else.
\end{mdframed}
\end{document}
  • Thanks for the fast answer. However, this results in the frame being a little to wide... Also, the backgroundcolor only fills to the inner frame. – Paul Paulsen Jun 22 '14 at 18:36
  • @Paul: Please update the question with a MWE the shows the background fill problem. Also, is the purpose of the tikzset{every picture...} for the mdframed` or is it also for other pictures as well? – Peter Grill Jun 22 '14 at 18:40
  • Updated the question, sorry I didn´t include it in the first place. The purpose of the tikz-frame-option is solely for other pictures, not for the mdframed stuff. It would be okay for me to deactivate it globally for mdframed, but I want to keep it for my other pictures. – Paul Paulsen Jun 22 '14 at 18:43
  • @Paul: Ok, have revised answer. – Peter Grill Jun 22 '14 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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