问题如何创建一个像浮点数一样带有标题和标签的框?完美地解释了我需要什么,除了一件事;他们使用自定义标题“InfoBox”。我如何使用标题“Box”并避免错误“Command \Box already defined。”?
答案1
您提到的答案使用了未记录的命令。最好明确声明新的浮点类型。
\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}
答案2
您可以使用tcolorbox
以满足您的需求(查看文档以了解进一步的定制):
\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,
drop fuzzy shadow
}
\begin{document}
\tcblistof[\section*]{mybox}{List of boxes}
\begin{mybox}{An mybox}
That's it.
\end{mybox}
\end{document}