In a document, I need to provide some details about specific topics without disrupting the flow of the main document, so that the details may easily be omitted at first reading. To do so, I thought it would be convenient to write the corresponding paragraphs in a frame outside the body of the document. This can be done easily using, for instance, mdframed
, and I can wrap the commands defining the frame into a \newenvironment
.
However, I feel that the general layout of the document would be much nicer if the frames were allowed to float and could be numbered and referred to in the main body of the document exactly like figures are. Is there a simple way to create such a floating environment?
So far, the solution I have found is to hijack the figure
environment using a new counter, and to redefine the command \theHfigure
locally so that hyperlinks built by hyperref
point to the right location.
Here is an example:
\documentclass{article}
\usepackage{lipsum}
\usepackage[colorlinks=true]{hyperref}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{multicol}
\newcounter{framecnt}
\newenvironment{frameenv}[1]
{\begin{figure}[tb]
\refstepcounter{framecnt}
\renewcommand{\theHfigure}{cont.\arabic{framecnt}}
\begin{mdframed}[roundcorner=10pt,backgroundcolor=blue!10]
\textbf{\centerline{Frame \arabic{framecnt} --- #1}}
\smallskip
\begin{multicols*}{2}
}
{\end{multicols*}\end{mdframed}\end{figure}
}
\begin{document}
\lipsum
\begin{frameenv}{More details}\label{frame1}
\lipsum[1]
\end{frameenv}
See frame \ref{frame1} or figure \ref{fig1}.
\begin{figure}
\caption{A real figure}\label{fig1}
\end{figure}
\end{document}
and the output it generates:
Does a more "natural" solution exist?
float
package.