I defined a new environemnt examples for a book I am writing. I would like examples to be with a framed grey box, and use the following construct

\begin{mdframed}[linewidth=2, leftmargin=0, rightmargin=0, backgroundcolor=gray, linecolor=black, splittopskip=\topskip, skipbelow=\baselineskip, skipabove=\baselineskip]
\par\noindent\sqrblt\underline{\textbf{Example \theexamples. #1}}
\cftsetindents{examples}{0em}{2em} % for example numbers which are greater than 9
% Solution
\newcommand{\sol}{\begin{center}\underline{{\bf Solution:}}\end{center}}
% End of Example
\noindent \hbox{~~}\hfill \hbox{~~} \sqrblt

If I activate the mdframed, I get "not in outer par mode". If I comment the mdframed part, all is well

  • 7
    Welcome to TeX.sx! Please post a minimal working example of your code illustrating the problem. – Gonzalo Medina Oct 1 '11 at 21:00
  • If I try your commands, I get what seems to be expected. What's the real error you get? The title says "too many floats", the questions refers to "not in outer par mode" – egreg Oct 1 '11 at 22:23

Here is a solution which works.

Your feedback is welcome.

\newcommand*\listexamples{List of Examples}



    \begin{mdframed}[style=example,frametitle={\sqrblt Example \theexamples.~#1}]



\begin{examplesenv}{Example one}
\bex{Example two}


In a comment zampano wrote he insert a floating environment. This can't work. The explanation if given in the UK List of TeX Frequently Asked Questions

This is of course a contradiction: figure and table are designed to float, and will always have the potential to appear away from where you asked for them. Therefore you have to find a means of getting the caption and other effects without allowing the figure or table to float.

To use captions in this contents I prefer the method captionof (provided by the KOMA-script or by the packages caption or capt-of)


enter image description here

  • Sure, it works, but the moment you insert inside the example a figure (\begin{figure} \includegraphics etc...) it fails with not in outer mode immediately – zampano Oct 3 '11 at 12:45
  • 1
    @zampano: This is an information which you forgot to present. You can't insert float-objects. If you want to use the caption you can use the center-environment in combination with captionof. – Marco Daniel Oct 3 '11 at 13:05

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.