答案1
只是为了好玩:
\documentclass{article}
\usepackage{tcolorbox}
\makeatletter
\renewenvironment{figure}[1][tbp]{\@float{figure}[#1]\begin{tcolorbox}}{\end{tcolorbox}\end@float}
\makeatother
\begin{document}
\begin{figure}
Hello, world!
\end{figure}
\end{document}
如果我没记错的话,浮动包通常会将标题放在框下方而不是里面。\captionbelow
如果您想要的话,可以使用这个,并且\caption
放在里面。
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{blindtext}
\makeatletter
\newsavebox{\@belowbox}
\newcommand{\@captionbelow}[2][\empty]% #1 = short caption(optional), #2 = caption
{\global\setbox\@belowbox=\vbox{\setlength{\hsize}{\normalwidth}%
\ifx\empty#1\relax
\caption{#2}
\else
\caption[#1]{#2}
\fi}}
\renewenvironment{figure}[1][tbp]{\@float{figure}[#1]%
\edef\normalwidth{\the\linewidth}%
\let\captionbelow=\@captionbelow \begin{tcolorbox}}%
{\end{tcolorbox}\unvbox\@belowbox\end@float}
\makeatother
\begin{document}
\begin{figure}
Hello, world!
\captionbelow{\blindtext}
\end{figure}
\end{document}
由于没有人提供过严肃的解决方案,因此这里使用标准的解决方案\fbox
。顺便说一句,这个解决方案将使更\captionabove
容易实现。
\documentclass{article}
\usepackage{blindtext}
\makeatletter
\newsavebox{\@middlebox}
\newsavebox{\@belowbox}
\newcommand{\@captionbelow}[2][\empty]% #1 = short caption(optional), #2 = caption
{\global\setbox\@belowbox=\vbox{\setlength{\hsize}{\normalwidth}%
\ifx\empty#1\relax
\caption{#2}
\else
\caption[#1]{#2}
\fi}}
\renewenvironment{figure}[1][tbp]{\@float{figure}[#1]%
\edef\normalwidth{\the\linewidth}%
\edef\normalfboxsep{\the\fboxsep}%
\let\captionbelow=\@captionbelow
\setlength{\fboxsep}{1em}% set width of gap
\begin{lrbox}{\@middlebox}\minipage{\dimexpr \linewidth-2\fboxsep-2\fboxrule}
\setlength{\fboxsep}{\normalfboxsep}}% restore default value inside minipage
{\endminipage\end{lrbox}%
\fbox{\usebox\@middlebox}%
\unvbox\@belowbox\end@float}
\makeatother
\begin{document}
\begin{figure}
Hello, world!
\captionbelow{\blindtext}
\end{figure}
\end{document}