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?

1 Answer 1

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}
4
  • 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. Commented Jun 22, 2014 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? Commented Jun 22, 2014 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. Commented Jun 22, 2014 at 18:43
  • @Paul: Ok, have revised answer. Commented Jun 22, 2014 at 20:26

You must log in to answer this question.

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