Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 6 down vote accepted

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}
share|improve this answer
1  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.