Create a box with the caption “Box”?

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."?

• You should take a look at the tcolorbox package. – Joseph Jan 28 '18 at 1:42

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}


You can use tcolorbox do suit your needs (check the documentation for further customizations):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\newtcolorbox[auto counter,list inside=mybox]{mybox}[2][]{%
title={Box~\thetcbcounter:~#2},
#1,
halign title=center,
sharp corners,
fonttitle=\bfseries\sffamily\large,coltitle=black,titlerule=0pt,
colbacktitle=white,
colback=white,
}

\begin{document}

\tcblistof[\section*]{mybox}{List of boxes}

\begin{mybox}{An mybox}
That's it.
\end{mybox}

\end{document}