1

I'm having a bit of trouble with the mdframed environment. I'm using it to enclose Examples in my text in a light gray background box (and control spacing around the text). When the frame splits over a page, it leaves less padding between the top of the box on the next page and the first line of text on the new page; I'd like to increase that amount of space. See the screenshot below.

Is there any way to do this? If an alternative setup is needed, I'm open to such solutions.

My example environment is declared thusly:

\usepackage{mdframed}
\newenvironment{example}[1]
{\begin{mdframed}[backgroundcolor=vlightgray,linecolor=vlightgray,innerleftmargin=1em,innerrightmargin=1em,innertopmargin=1em,innerbottommargin=1em,skipabove=1em]
    \textbf{Example \arabic{chapter}.\arabic{exampleNum}} #1

    \vspace{1em}
    \noindent \ignorespaces}%
{\end{mdframed} \vspace{0.25em}}

enter image description here

Here is a MWE; the spacing problem is demonstrated at the top of the second page.

\documentclass[12pt,openright,twoside]{book}

\usepackage{lipsum}

\usepackage{xcolor}
\definecolor{vlightgray}{gray}{0.925}

\newcounter{exampleNum}
\setcounter{exampleNum}{1}

\usepackage{mdframed}
\newenvironment{example}[1]
{\begin{mdframed}[backgroundcolor=vlightgray,linecolor=vlightgray,innerleftmargin=1em,innerrightmargin=1em,innertopmargin=1em,innerbottommargin=1em,skipabove=1em]
        \textbf{Example \arabic{chapter}-\arabic{exampleNum}} \normalsize #1

        \vspace{1em}
        \stepcounter{exampleNum}
        \noindent \ignorespaces}%
    {\end{mdframed} \vspace{0.25em}}

\begin{document}
    \lipsum[1-3]

    \begin{example}{Consider this the prompt for the problem. Find $a$.}
        \lipsum[1-2]
    \end{example}
\end{document}
  • Could you post a small compilable code demonstrating the problem? – Bernard Jan 26 at 21:06
  • 2
    It looks like you've got two separate accounts, which means you cannot edit your original post or leave comments. The Stack Exchange staff can merge them together for you. – Mensch Jan 26 at 23:18
  • @Bernard A MWE has been added. – flevinBombastus Jan 27 at 1:56
1

The tool for this is the parameter``splittopskip`, which defaults to 0pt (§ 6.9, p.9 of the docume,tation):

\documentclass[12pt,openright,twoside]{book}

\usepackage{lipsum}

\usepackage{xcolor}
\definecolor{vlightgray}{gray}{0.925}

\newcounter{exampleNum}
\setcounter{exampleNum}{1}

\usepackage{mdframed}
\newenvironment{example}[1]
{\begin{mdframed}[backgroundcolor=vlightgray,linecolor=vlightgray,innerleftmargin=1em,innerrightmargin=1em,innertopmargin=1em,innerbottommargin=1em,skipabove=1em, splittopskip=\baselineskip]
        \textbf{Example \arabic{chapter}-\arabic{exampleNum}} \normalsize #1

        \vspace{1em}
        \stepcounter{exampleNum}
        \noindent \ignorespaces}%
    {\end{mdframed} \vspace{0.25em}}

\begin{document}

    \lipsum[1-3]

    \begin{example}{Consider this the prompt for the problem. Find $a$.}
        \lipsum[1-2]
    \end{example}

\end{document} 

enter image description here

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.