我正在使用基于 KOMA 脚本的双列布局,并使用包修改浮动标题caption
。不幸的是,在重新定义默认样式时,新选项将同时应用于列宽figure
和文本宽figure*
。这会导致标题并不总是具有预期的宽度:
\documentclass[a4paper,twocolumn,DIV=16]{scrartcl}
\usepackage{blindtext}
\usepackage[
justification=RaggedRight,
width=.9\columnwidth,
]{caption}
\begin{document}
\blindtext
\begin{figure}[htpb]
\rule{\columnwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is as intended.
}
\end{figure}
\blindtext
\clearpage
\begin{figure*}[htpb]
\rule{\textwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is too small.
}
\end{figure*}
\clearpage
\captionsetup{
justification=RaggedRight,
width=.9\textwidth,
}
\blindtext
\begin{figure}[htpb]
\rule{\columnwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is too large.
}
\end{figure}
\blindtext
\clearpage
\begin{figure*}[htpb]
\rule{\textwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is as intended.
}
\end{figure*}
\clearpage
\end{document}
我现在通过手动切换到通过\DeclareCaptionStyle{colfigure}{...}
列图定义的单独样式来规避这个问题\captionsetup{style=colfigure}
,但我不想手动执行此操作。有没有办法自动完成这个?
答案1
虽然该width=...
选项会立即将标题的宽度设置为固定量,但calcwidth=...
如果需要,则会在每次实际排版标题时评估该值。
因此,通常使用width=...
全局选项不是一个好主意;在单个图形或表格中使用它(本地)选项更有意义。
因此,请尝试类似以下的方法calcwidth=.9\linewidth
:
\documentclass[a4paper,twocolumn,DIV=16]{scrartcl}
\usepackage{blindtext}
\usepackage[
justification=RaggedRight,
calcwidth=.9\linewidth,
]{caption}
\begin{document}
\blindtext
\begin{figure}[htpb]
\rule{\columnwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is as intended.
}
\end{figure}
\blindtext
\clearpage
\begin{figure*}[htpb]
\rule{\textwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is as intended.
}
\end{figure*}
\end{document}
calcwidth=...
于 2011/07/30随软件包 v3.2 引入caption
,但仍未成为文档的一部分。(仅在文件中提及CHANGELOG
。)另请参阅:https://gitlab.com/axelsommerfeldt/caption/issues/1
计划于今年年底推出包含完整修订文档的新版本 v3.4。
答案2
这里有一个建议,至少需要 KOMA-Script 版本 3.25,并且无需包即可工作caption
。
\documentclass[a4paper,twocolumn,DIV=16]{scrartcl}[2018/03/30]% needs version 3.25 or newer
\usepackage{blindtext}
\setcaptionalignment{l}% needs version 3.25
\setcapdynwidth{.9\linewidth}% needs version 3.20
\begin{document}
\blindtext
\begin{figure}[htpb]
\rule{\columnwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is as intended.
}
\end{figure}
\blindtext
\clearpage
\begin{figure*}[htpb]
\rule{\textwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is too small.
}
\end{figure*}
\end{document}
结果:
或者使用包装ragged2e
和标题对齐L
:
\documentclass[a4paper,twocolumn,DIV=16]{scrartcl}[2018/03/30]% needs version 3.25 or newer
\usepackage{blindtext}
\usepackage{ragged2e}
\setcaptionalignment{L}% needs version 3.25
\setcapdynwidth{.9\linewidth}% needs version 3.20
\begin{document}
\blindtext
\begin{figure}[htpb]
\rule{\columnwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is as intended.
}
\end{figure}
\blindtext
\clearpage
\begin{figure*}[htpb]
\rule{\textwidth}{2cm}
\caption{A few words that consume more space than a single line.
The width of this caption is too small.
}
\end{figure*}
\end{document}
\documentclass{article} \begin{document} [ \left{ x\in\mathbf{R} \middle] 0<{|x|><\frac{5}{3} \right} ]
\结束{文档}
结果: