6

I want to use mdframed to add a frame around a text. But the vertical spacing is not as expected. I found the following help page: Vertical spacing problem related to the mdframed environment

The accepted answer was promising and I tested it myself, but I get a different result than the screenshot there suggests.

Here is the answer example:

\documentclass{article}
\usepackage[framemethod=1]{mdframed}

\begin{document}

\noindent Text
\begin{mdframed}
  Framed
\end{mdframed}
Text

\noindent Text
\begin{mdframed}[skipbelow=-0.5em]
  Framed
\end{mdframed}
Text

\end{document}

My result is: mdframed bug

I have mdframed version 1.9 installed which seems to be the newest version.

Can anybody can confirm this behaviour? Even better would be a fix for the problem.

EDIT:
After AboAmmar's answer. I noticed an even stranger but perhaps related behavior of mdframed. It allows to define a style and use it for a environment afterwards. The following example will use the skipabove, but the skipbelow seems to be ignored:

\documentclass{article}
\usepackage[framemethod=1]{mdframed}

\mdfdefinestyle{mystyle}{skipabove=2pt,skipbelow=-2pt}

\begin{document}

\noindent Text
\begin{mdframed}[style=mystyle]
Framed
\end{mdframed}
Text
\end{document}

Result: mdframed bug 2

The result is the same, if the skipbelow is defined directly after \begin{mdframed}. Only \mdfsetup{skipabove=2pt,skipbelow=-2pt} seem to change the space after the box, but I don't want to use the setting globally.

0

1 Answer 1

7

In the current version (see documentation of Version 1.9b), you can set the top and below skip values as:

\mdfsetup{skipabove=<value>,skipbelow=<another value>}

So, the above example can be adjusted as follows:

\documentclass{article}
\usepackage[framemethod=1]{mdframed}

\mdfsetup{skipabove=2pt,skipbelow=-2pt}

\begin{document}
\noindent Text
\begin{mdframed}
  Framed
\end{mdframed}
Text

\noindent Text
\begin{mdframed}
  Framed
\end{mdframed}
Text\\
Text
\end{document}

You can, of course, choose proper values for skipabove or skipbelow.

Here is the result now:

enter image description here

1
  • 2
    Firstly, thanks for your help. I knew this options but they also behave very strange. The documentation says default skipabove and skipbelow is 0pt. I would expect this means than no space is used and I also tried to set them manually to 0pt before, but it doesn't do what it should do. Your example also used a positive and a negative value, but the result is still not in the center. Commented Mar 25, 2015 at 21:17

You must log in to answer this question.

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