[Tex/LaTex] Changing frame size in mdframed

framedmdframedspacing

I am trying to place a box around a definition. Using the package mdframed, I have managed to do so. However, the box is too large, in particular too tall, and it is covering up text appearing above and below the definition. I am using

\newenvironment{bdefn}    
  {\begin{mdframed}\begin{defn}}    
  {\end{defn}\end{mdframed}}

to create the "boxed definition" environment, and then I am using

\begin{bdefn}    
(text)    
\end{bdefn}

for the definition itself.

I have tried to manually create a new mdframed style to use which has smaller margins, using something like

\mdfdefinestyle{style1}{leftmargin=1cm,rightmargin=1cm,skipbelow=1cm,skipabove=1cm}.

The command \mdfdefinestyle and this format are both taken from the documentation for mdframed. However, when I place this line into my document's preamble, I receive the error message

"Undefined control sequence: \mdfdefinestyle{stlye1}{..."

Can anyone tell me why the command \mdfdefinestyle is not being recognized? Or, can anyone suggest a different way to make an as-small-as-possible box around my definition?

Best Answer

You have to use the style like style=style1 (not just style1). Speaking further, you can use \surroundwithmdframed[<options>]{environment} to surround an existing environment with a mdframed frame. So to cover defn with frame, you need

\surroundwithmdframed[style=style1]{defn}

Here is a sample.

\documentclass{article}
\usepackage{amsthm}
\newtheorem{defn}{Definition}
\usepackage[framemethod=TikZ]{mdframed}
\mdfdefinestyle{style1}{leftmargin=1cm,rightmargin=1cm,skipbelow=1cm,skipabove=1cm,
   innertopmargin=0pt}
\surroundwithmdframed[style=style1]{defn}
\begin{document}
  \begin{defn}%
(text)
\end{defn}
\end{document}

enter image description here

Related Question