[Tex/LaTex] Create a box with the caption “Box”

boxescaptionsfloats

The question How to create a box with caption and label like a float? explains perfectly what I need except for one thing; they use the custom caption "InfoBox". How can I use the caption "Box" and avoid the error "Command \Box already defined."?

Best Answer

The answer you mention uses undocumented commands. Better to declare the new float type explicitly.

\documentclass{article}
\usepackage{caption,graphicx,newfloat}

\DeclareFloatingEnvironment[
  fileext=lob,
  listname={List of Boxes},
  name=Box,
  placement=htp,
]{BOX}

\begin{document}

\begin{BOX}[ht]
\centering

\fbox{\includegraphics[width=2in]{example-image-b}}

\caption{Here is my caption\label{box:b}}

\end{BOX}

In box \ref{box:b}...

\end{document}

enter image description here