# Implementing “aside” environment for explaining details of calculation

I would like to have parts of the text set in smaller time with different indentation, and separated from the rest of the text visually (e.g. by horizontal rules). I would like to use this to set off less important parts of the text where some additional explanations are given (e.g. state a theorem, then give the proof in smaller type for those interested).

I copied a definition from another (old) document, but unfortunately it has some issues. Please help fix these problems.

An example is provided below. Uncommenting the problem parts will trigger the error (see the comments).

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{framed} % For the "details" environment

% just a horizontal rule for the "details" environment
\newcommand{\optionrule}{\noindent\rule{1.0\textwidth}{0.75pt}}

% the "details" environment declaration.
\newenvironment{aside}{%
\def\FrameCommand{\hspace{2em}}
{\newline\optionrule\endMakeFramed}

\begin{document}
\begin{aside}
asd
%\begin{figure}
% (some figure)
% adding this figure causes a Floats lost'' error.
%\end{figure}
asd
% an empty line here causes a There's no line to end here error''
\end{aside}
\end{document}

-

With the help of the mdframed package you can easily create and customize environments like the one you need.

The environments defined with mdframed don't admit floats (the same situation as with the environments from the framed package), but you don't need floats inside one of those environments. With the help of the \captionof command from the caption package you can have captions for images or tables.

A little example (of course, make the necessary modifications to suit your needs); I slightly modified the original design posted, making the environment centered so that the rules hang over both ends by the same amount (following barbara beeton's remark):

\documentclass[a4paper]{article}
\usepackage{mdframed}
\usepackage{caption}
\usepackage{lipsum}% just to generate some filler text

\newenvironment{aside}
{\begin{mdframed}[style=0,%
leftline=false,rightline=false,leftmargin=2em,rightmargin=2em,%
innerleftmargin=0pt,innerrightmargin=0pt,linewidth=0.75pt,%
skipabove=7pt,skipbelow=7pt]\small}
{\end{mdframed}}

\begin{document}

\lipsum[1]
\begin{aside}
\lipsum[1]
\begin{center}
\rule{4cm}{2cm}
\captionof{figure}{A test figure}
\label{fig:test}
\end{center}
\end{aside}

\end{document}


If you want to continue using framed and preserve the original layout then, by removing \newline from the definition of aside, you can prevent the error produced by leaving an empty line before closing the environment. You could use instead something like this:

\usepackage{framed}

\newcommand{\optionrule}{\noindent\rule{1.0\textwidth}{0.75pt}}

\newenvironment{aside}
{\def\FrameCommand{\hspace{2em}}
{\par\vskip-\smallskipamount\optionrule\endMakeFramed}


To be able to have footnotes, you can use the \footnotemark, \footnotetext mechanism:

\begin{aside}
\lipsum*[1] Text\footnotemark
\begin{center}
\rule{4cm}{2cm}
\captionof{figure}{A test figure}
\label{fig:test}
\end{center}
\end{aside}
\footnotetext{A test footnote}

-
i'm not familiar with mdframed, but the text would look nicer if it were centered so that the rules hang over both ends by the same amount. –  barbara beeton Jun 22 '11 at 21:47
@barbara beeton: I agree. My example just imitates the original layout of the environment designed by the OP, but I will add the modified version you suggest. –  Gonzalo Medina Jun 22 '11 at 22:21
Thanks for the centred version! –  Szabolcs Jun 23 '11 at 8:56
@Gonzalo, one issue here is that if the figure is too big, it just won't show up. E.g. I have a 12cm PDF figure, but it will only show up if I use \includegraphics[width=8.5cm]{filename}. Any size larger than 8.5 cm will fail (with no error), even though the width of the aside environment is considerably larger than 8.5 cm. Do you have any idea why? –  Szabolcs Jun 23 '11 at 8:58
@Szabolcs: I did some tests and I couldn't reproduce the odd behaviour mentioned. I suggest you to open a new follow up question (linking to this one), with this new issue and including a minimal working example illustrating the problem. Don't forget to mark my answer here as accepted, if you consider that it solved your original problem. –  Gonzalo Medina Jun 23 '11 at 20:11