我想为我的figures
和的标题添加边框/方框tables
,但又不想为图形/表格本身添加边框。我目前有办法,但方框占据了整个文本宽度,我找不到让它适合标题宽度的方法(由于包的原因,标题宽度是恒定的caption
)。
我怎样才能减小框架的宽度以使其适合标题?
梅威瑟:
\documentclass[12pt]{article}
\usepackage[demo]{graphicx}
\usepackage{framed}
\usepackage{caption}
\captionsetup{width=0.45\textwidth}
\begin{document}
\begin{figure}[ht!]
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\begin{framed}
\caption{
Here is a reasonably long caption that will be at least two lines, around which I would like a box
}
\label{some-image}
\end{framed}
\end{figure}
\end{document}
答案1
这使用该tcolorbox
包及其许多选项来生成一个框架标题,尽管在我看来这看起来有点奇怪。
\documentclass[12pt]{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{tcolorbox}
\captionsetup{width=0.45\textwidth}
\begin{document}
\begin{figure}[ht!]
\centering
\includegraphics[width=0.5\textwidth]{image.png}
\begin{tcolorbox}[left=0mm,right=0mm,width=0.5\textwidth,bottom=0mm,top=0mm,arc=0mm,auto outer arc]
\caption{%
Here is a reasonably long caption that will be at least two lines, around which I would like a box
}%
\label{some-image}%
\end{tcolorbox}
\end{figure}
\end{document}