我观察到,当前版本的字幕包width=0.9\linewidth
对或反应不正确width=0.9\columnwidth
。以下是 MWE:
\documentclass{scrartcl}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage[width = .9\linewidth, font = small, labelfont = bf]{caption}
\begin{document}
\blindtext
\begin{figure}[htbp]
\centering
\includegraphics[width=0.9\columnwidth]{example-image-a}
\caption{This is a long figure caption, to show the problem with the width option and variable length like columnwidth and linewidth}
\label{figlabel}
\end{figure}
\blindtext
\end{document}
目前,我使用 选项minmargin = 0.05\linewidth
而不是width=...
。
答案1
caption 包选项width
会立即计算标题的宽度。因此,写入时的\captionsetup{width=.9\linewidth}
结果取决于\linewidth
此时的值,并且在文档期间不会发生变化。
(正如 John Kormylo 已经评论过的, \linewidth 在序言中尚未正确设置。)
但是,我们可以使用calcwidth
它.9\linewidth
在每次需要标题宽度时重新计算:
\documentclass{scrartcl}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage[calcwidth = .9\linewidth, font = small, labelfont = bf]{caption}
\begin{document}
\blindtext
\begin{figure}[htbp]
\centering
\includegraphics[width=0.9\columnwidth]{example-image-a}
\caption{This is a long figure caption, to show the problem with the width option and variable length like columnwidth and linewidth}
\label{figlabel}
\end{figure}
\blindtext
\end{document}
如果目标是使标题宽度适合图形宽度,则可以改用\captionbox
:
\documentclass{scrartcl}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage[font = small, labelfont = bf]{caption}
\begin{document}
\blindtext
\begin{figure}[htbp]
\centering
\captionbox
{This is a long figure caption, to show the problem with the width option and variable length like columnwidth and linewidth\label{figlabel}}
{\includegraphics[width=0.9\columnwidth]{example-image-a}}
\end{figure}
\blindtext
\end{document}
calcwidth
并\captionbox
在软件包版本 3.2(2011/07/30)中引入caption
,但遗憾的是它们尚未在文档中提及,仅在变更日志 [¹] 中提及。(目前我正在更新文档,但进展缓慢。)
要了解其\captionbox
工作原理,请查看subcaption
文档。\subcaptionbox
在那里描述,并且\subcaptionbox
其行为与非常相似\captionbox
,第一个用于排版子图形和子表的内容,第二个用于排版图形和表格的内容。
[1]http://mirror.ctan.org/macros/latex/contrib/caption/CHANGELOG
答案2
caption
包和之间似乎存在冲突koomascript
,它有自己的格式化标题的工具。如果您希望标题宽度等于图形宽度,则可以使用 的measuredfigure
环境threeparttable
:
\documentclass{scrartcl}
\usepackage{lipsum}
\usepackage{graphicx}
\setkomafont{caption}{\small}
\setkomafont{captionlabel}{\bfseries}
\usepackage{threeparttable}
\begin{document}
\lipsum[2]
\begin{figure}[htbp]
\centering
\includegraphics[width=0.9\columnwidth]{example-image-a}
\caption{This is a long figure caption, to show the problem with the width option and variable length like columnwidth and linewidth}
\label{figlabel}
\end{figure}
\lipsum[3]
\newpage
\lipsum[2]
\begin{figure}[!htbp]
\centering
\begin{measuredfigure}
\includegraphics[width=0.9\columnwidth]{example-image-a}
\caption{This is a long figure caption, to show the problem with the width option and variable length like columnwidth and linewidth}
\label{figlabel}
\end{measuredfigure}
\end{figure}
\lipsum[3]
\end{document}