我想知道是否有可能在图中只围绕标题而不是整个图形放置一个框。
\documentclass[12pt,letter]{article}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}
\includegraphics[width=6in]{foo.ps}
\caption{I sure hope I can be boxed separate from the picture...}
%some command that can put a box around the caption
\end{figure}
\end{document}
编辑我在命令[width=6in]
上添加了\includegraphics
。这是我所包含的图形的必要部分。
答案1
进行以下调整将\@makecaption
图形标题放置在可调整标题宽度的框内:
\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\makeatletter
\long\def\@makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\@tempboxa{\fbox{#1: #2}}%
\ifdim \wd\@tempboxa >\hsize
\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{#1: #2}}\par
\else
\global \@minipagefalse
\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
\makeatother
\begin{document}
\begin{figure}
\centering
\includegraphics[width=100pt]{example-image}
\caption{I sure hope I can be boxed separate from the picture\ldots}
\caption{I sure hope I can be boxed separate from the picture.
I sure hope I can be boxed separate from the picture.
I sure hope I can be boxed separate from the picture.}
\end{figure}
\end{document}
的定义\@makecaption
取自(并修改自)article.cls
。
caption
还允许设置标题样式。因此,如果您对固定宽度的标题感兴趣,可以使用类似以下内容:
\documentclass{article}
\usepackage{caption,graphicx}% http://ctan.org/pkg/{caption,graphicx}
\DeclareCaptionFormat{plain}{%
\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{\centering #1#2#3}}}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=100pt]{example-image}
\caption{I sure hope I can be boxed separate from the picture\ldots}
\caption{I sure hope I can be boxed separate from the picture.
I sure hope I can be boxed separate from the picture.
I sure hope I can be boxed separate from the picture.}
\end{figure}
\end{document}
样式设置为,\centering #1#2#3
其中#1
引用标题标签、#2
标题标签分隔符和#3
标题文本。请参阅章节4 自身增强功能(第 24 页)caption
包装文档。