# Minipages across page breaks

I have defined a command that uses the minipage environment to format an "example" question within my document.

\newcounter{Example}
\newcommand{\example}[3]{%
\refstepcounter{Example}
\fbox{%
\begin{minipage}{\textwidth}
\subsubsection{Example \theExample:\textsf{\ #1}}
{\leftskip 1em \rightskip 1em
#2

}

\vskip 0.5em

\colorbox{lightergray}{%
\begin{minipage}[c]{0.98\textwidth}
#3
\end{minipage}%
}
%end subsubsection{Example}
\end{minipage}
}%
}


(This code creates a command \example{<title>}{<question>}{<answer>}).

To produce this:

However I need this to be able to split across multiple page breaks. At the moment the following is produced at a page break:

This is not desirable. I know this is because of the minipage environment. Is there a way that I can produce this same output whilst allowing page breaks? (Ideally I would like no border at the bottom of the first page and no top border on the new page.)

I am compiling with TeX4ht so require either common packages or standard LaTeX/TeX.

I understand a type of list environment may be useful here but I'm unsure how to apply this to this specific case.

• Use the tcolorbox package. Jun 16 '15 at 16:36
• why the }{ % and } % forcing word spaces? Jun 16 '15 at 16:42
• @DavidCarlisle I'm not really sure. Why do people use those? I thought it was to stop LaTeX thinking there's a line break there. Jun 16 '15 at 16:53
• @HarrySmith a linebreak is a space so ...}% has no space after the } but you have ....} % which forces a space in that position, as you have space token before the % Jun 16 '15 at 17:11

Alternative: Use tcolorbox (Gonzalo Medina was proposing it while I wrote this answer ;-)) with the breakable option. There is a huge number of options for the shape, colours etc -- it's impossible to show them all here in a small example.

\documentclass{article}

\PassOptionsToPackage{svgnames}{xcolor}
\usepackage[most]{tcolorbox}

\usepackage{blindtext}

\newtcbtheorem[auto counter]{example}{My Example}{arc=0pt, auto outer arc, breakable,left=2pt,right=2pt,colback=LightBlue,colbacktitle=LightBlue,coltitle=black,title after break={Continued from Example \thetcbcounter},titlerule=0pt}{examples}

\begin{document}

In \ref{examples:brontosaurs}, we will see that...

\begin{example}{Theory on Brontosaurs}{brontosaurs}
\blindtext[20]
\end{example}

\end{document}


• I've looked at the tcolorbox package but found that TeX4ht had problems compiling it. I'm trying to stick to either very common packages or standard LaTeX/TeX because I need both .pdf documents and .html files. Jun 16 '15 at 16:51
• @HarrySmith: You did not mention tex4ht at all in your post. Well, I posted a possible solution before tex4ht was mentioned, I won't delete it
– user31729
Jun 16 '15 at 16:53
• @HarrySmith -- please add your TeX4ht/ .html requirement to the statement of your question. Jun 16 '15 at 16:53
• Updated. I will certainly use this package for future documents, though! Jun 16 '15 at 16:55