[Tex/LaTex] Custom Box Environment

environmentsframed

I'm currently writing a report and I need to create a custom "Box" environment similar to that shown in the figure below. For the sake of objectivity the following requirements are the only ones I'm looking for:

  1. The contents are to be framed (which I guess it can be achieved using the framed package);
  2. It should have a Per Chapter counter (i.e. if currently at the Chapter 2, the third box should be numbered Box 2.3)
  3. The caption should be equal to the standard figure caption EXCEPT it should appear on top instead.

I would appreciate your help!

enter image description here

Best Answer

The package float more or less offers what you want, even a boxed style. It seems, however, that one has to define a new style boxedtop in order to have the caption appear on top of the box, like this:

\makeatletter
\newcommand\fs@boxedtop
  {\fs@boxed
   \def\@fs@mid{\vspace\abovecaptionskip\relax}%
   \let\@fs@iftopcapt\iftrue
  }
\makeatother

Here is an example.

\documentclass{book}
\usepackage{lipsum}
\usepackage{float}
\makeatletter
\newcommand\fs@boxedtop
  {\fs@boxed
   \def\@fs@mid{\vspace\abovecaptionskip\relax}%
   \let\@fs@iftopcapt\iftrue
  }
\makeatother
\floatstyle{boxedtop}
\floatname{framedbox}{Box}
\newfloat{framedbox}{tbp}{lob}[chapter]
\begin{document}
\chapter{First Chapter}
\lipsum[2]

\begin{framedbox}[htbp]
  \caption{The Newton-Raphson whatever}
  \begin{minipage}{0.95\textwidth}
    \begin{enumerate}
    \item \lipsum[2]
    \item \lipsum[2]
    \end{enumerate}
  \end{minipage}
\end{framedbox}

\lipsum[2]
\listof{framedbox}{List of Boxes}
\end{document}

enter image description here

Edit: If you don't want to have the caption title in boldface, change the definition of the style boxedtop to

\newcommand\fs@boxedtop
 {\fs@boxed
  \def\@fs@mid{\vspace\abovecaptionskip\relax}%
  \let\@fs@iftopcapt\iftrue
  \def\@fs@cfont{\rmfamily}%
 }

(Note the added last line.)