# Indented box that split in multiple pages

I am doing a document with exercises and corrections. I would like the corrections to be easily remarkable so that no student read it by accident and get its exercise spoiled. I have written an environment for that, the problem is that it doesn't split in multiple pages :/

\newenvironment{solution}%
{\par\rule{1ex}{1ex}
\hspace{\stretch{1}}
\textbf{Solution}
\hspace{\stretch{1}}
\rule{1ex}{1ex}\par%
\hspace{2ex}% indent everything by 2ex
%\begin{myindentpar}{7ex}
%\quote \quote
\begin{minipage}{0.95\linewidth}% stop just before the right squares
\begin{framed}}% put a black frame
%\begin{longtable}{|p{1.1\linewidth}|}
%\hline}
{\end{framed}\end{minipage}
%{\\\hline\end{longtable}
%\end{myindentpar}
%\endquote \endquote
\par
\rule{1ex}{1ex}\hspace{\stretch{1}}
\hspace{\stretch{1}}\rule{1ex}{1ex}\par}


I have left on purpose my commented tries in case it would inspire you.

If you find a solution that changes the design a bit, I'm still very interested :)

• I removed boxes because page-breaking seems to be relevant and only five tags per question are allowed. – lockstep Apr 6 '13 at 10:35
• Why do you put the environment framed inside a minipage? framed can split the contents, minipage not. BTW: it's easier to help you if you provide a complete minimal working example. – Marco Daniel Apr 6 '13 at 10:39
• I used minipage so that \hspace{2ex} indented the whole thing. I know it's a very ugly solution. Anyway Gonzalo Medina definitely solved it :P – Benoît Legat Apr 12 '13 at 17:00

The problem in your code is that you enclosed your mdframed inside a minipage, and minipages don't admit page breaks. My guess is that you used the minipage to locate the tiny squares on the corners of the frame; this, however, is not necessary and you can locate them using singleextra, firstextra, without ruining the possibility of page breaks inside the environment.

A little example in which I defined two styles: the first one, without squares and the second one, using the squares (I wasn't sure about the exact length you wished to use, but you can easily make the necessary adjustments):

\documentclass{article}
\usepackage[a5paper]{geometry}% just for the example
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikzpagenodes}
\usepackage{lipsum}% just to generate text for the example
\usetikzlibrary{calc}

\mdfdefinestyle{mystyle}{%
leftmargin=2ex,
innertopmargin=2\baselineskip,
skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
skipbelow={\dimexpr0.5\baselineskip+\topskip\relax},
firstextra={%
\path let \p1=(P), \p2=(O)
in node[font=\bfseries] at ([yshift=-2ex]0.5*\x1-\x2,\y1) {Solution};
}
}
\mdfdefinestyle{mysquare}{%
leftmargin=0pt,
rightmargin={\dimexpr4pt+2ex\relax},
innertopmargin=2\baselineskip,
skipabove={\dimexpr0.5\baselineskip+\topskip\relax},
skipbelow={\dimexpr0.5\baselineskip+\topskip\relax},
singleextra={%
\path let \p1=(P), \p2=(O)
in node[font=\bfseries] at ([yshift=-2ex]0.5*\x1-\x2,\y1) {Solution};
\fill[black] ([xshift=2pt,yshift=2pt]P) rectangle ++(1ex,1ex);
\fill[black] ([xshift=-2pt,yshift=-2pt]O) rectangle ++(-1ex,-1ex);
\fill[black] ([xshift=-2pt,yshift=2pt]O|-P) rectangle ++(-1ex,1ex);
\fill[black] ([xshift=2pt,yshift=-2pt]O-|P) rectangle ++(1ex,-1ex);
},
firstextra={%
\path let \p1=(P), \p2=(O)
in node[font=\bfseries] at ([yshift=-2ex]0.5*\x1-\x2,\y1) {Solution};
\fill[fill=black] ([xshift=2pt,yshift=2pt]P) rectangle ++(1ex,1ex);
\fill[black] ([xshift=-2pt,yshift=2pt]O|-P) rectangle ++(-1ex,1ex);
},
secondextra={%
\fill[fill=black] ([xshift=2pt,yshift=-2pt]O-|P) rectangle ++(1ex,-1ex);
\fill[black] ([xshift=-2pt,yshift=-2pt]O) rectangle ++(-1ex,-1ex);
}
}
\newmdenv[style=mystyle]{solution}
\newmdenv[style=mysquare]{ssolution}

\begin{document}

\lipsum[1]
\begin{solution}
\lipsum[2-3]
\end{solution}
\lipsum[2]
\begin{ssolution}
\lipsum[1-2]
\end{ssolution}
\lipsum[2]

\end{document}


• Wonderful solution !!! Even though I don't understand the goal of the firstextra and the secondextra. Why do I get the same effect by commenting them ? – Benoît Legat Apr 12 '13 at 16:46
• @BenoîtLegat I'm glad I could help. Regarding firstextra, secondextra, when the frames don't have page breaks, there's no difference; however, using the ssolution environment (the one with the little black squares), if the text has a page break, commenting out firstextrawill eliminate the squares from the first part of the frame (the one before the page break), and suppressing secondextra will eliminate the squares at the end of the environment. – Gonzalo Medina Apr 12 '13 at 16:56
• And removing singleextra will eliminate the squares when it fits within a single page. Sweet :) – Benoît Legat Apr 12 '13 at 17:03