[Tex/LaTex] Implementing “aside” environment for explaining details of calculation

environmentserrorsmacros

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}}
  \MakeFramed {\advance\hsize-\width \small}\optionrule}
{\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}

Best Answer

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}}
   \MakeFramed {\advance\hsize-\width}\optionrule\small}
{\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}