我正在尝试将包含四个子图的大型图形放入我的文档中。整个图形接近分页符,因此我决定通过 拆分图形\ContinuedFloat
。以防万一,可以将图形的后半部分移到下一页。
大图与子图的标题用作标题并放置在顶部。子图的标题位于底部,以及下一个较小的图。到目前为止,效果很好。
但数字很乱。交叉引用显示,子图的编号为“2a”而不是“1a”,依此类推。下图的编号为“3”而不是“2”。图列表显示的前两个子图的页码是错误的。
这表明当前的情况:
\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[list=true,listformat=simple]{subcaption}
\captionsetup{font=small,labelfont=bf,singlelinecheck=false,within=none}
\usepackage[demo]{graphicx}
\usepackage{cleveref}
\newcommand{\see}[1]{\cref{#1}, \cpageref{#1}}
\newcommand{\sees}[2]{\crefrange{#1}{#2}, \cpagerefrange{#1}{#2}}
\begin{document}
There ist a huge amount of text, but I omitted it, because I was too lazy to type so many sentences.\par
There is some text and more text.\par
\begin{figure}[h]
\caption[short heading for the figure with subfigures]{Something like a heading for this figure containing subfigures}
\label{fig:1}
\vspace{1eM}
\subcaptionbox[short caption, first subfigure]{long caption, first subfigure\label{fig:1A}}{\includegraphics[height=7cm]{ExampleA.jpg}}
\hfill
\subcaptionbox[short caption, second subfigure]{long caption, second subfigure\label{fig:1B}}{\includegraphics[height=7cm]{ExampleB.jpg}}
\end{figure}
\begin{figure}[h]
\ContinuedFloat
\subcaptionbox[short caption, third subfigure]{long caption, third subfigure\label{fig:1C}}{\includegraphics[height=7cm]{ExampleC.jpg}}
\hfill
\subcaptionbox[short caption, fourth subfigure]{long caption, fourth subfigure\label{fig:1D}}{\includegraphics[height=7cm]{ExampleD.jpg}}
\end{figure}
Here is some text in between all these figures.
\begin{figure}[h]
\includegraphics[width=7cm]{Example2.jpg}
\caption{a figure with a wrong number}
\label{fig:2}
\end{figure}
At the end there are some cross-references to these pictures. Since they are floating, it is not really at the end, but that is tolerable for now.\\
\see{fig:1}\\
\see{fig:1A}\\
\see{fig:1D}\\
\see{fig:2}\\
\sees{fig:1A}{fig:1D}\\
\sees{fig:1}{fig:2}\\
\listoffigures
\end{document}
我尝试通过\phantomcaption
重新定义第一个标题的位置来管理它。但由于我完全不知道背景中发生了什么,我无法自己弄清楚。我真的很感激一些帮助......
答案1
使用 KOMA-Script 类\captionabove
在组内使用并删除\vspace{1em}
:
\begingroup
\captionabove
[short heading for the figure with subfigures]
{Something like a heading for this figure containing subfigures}%
\label{fig:1}%
\endgroup
代码:
\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[list=true,listformat=simple]{subcaption}
\captionsetup{font=small,labelfont=bf,singlelinecheck=false,within=none}
\usepackage[demo]{graphicx}
\usepackage{cleveref}
\newcommand{\see}[1]{\cref{#1}, \cpageref{#1}}
\newcommand{\sees}[2]{\crefrange{#1}{#2}, \cpagerefrange{#1}{#2}}
\begin{document}
There ist a huge amount of text, but I omitted it, because I was too lazy to type so many sentences.\par
There is some text and more text.\par
\begin{figure}[ht]
\begingroup
\captionabove
[short heading for the figure with subfigures]
{Something like a heading for this figure containing subfigures}%
\label{fig:1}%
\endgroup
\subcaptionbox
[short caption, first subfigure]
{long caption, first subfigure\label{fig:1A}}
{\includegraphics[height=7cm]{ExampleA.jpg}}
\hfill
\subcaptionbox
[short caption, second subfigure]
{long caption, second subfigure\label{fig:1B}}
{\includegraphics[height=7cm]{ExampleB.jpg}}
\end{figure}
\begin{figure}[ht]
\ContinuedFloat
\subcaptionbox
[short caption, third subfigure]
{long caption, third subfigure\label{fig:1C}}
{\includegraphics[height=7cm]{ExampleC.jpg}}
\hfill
\subcaptionbox
[short caption, fourth subfigure]
{long caption, fourth subfigure\label{fig:1D}}
{\includegraphics[height=7cm]{ExampleD.jpg}}
\end{figure}
Here is some text in between all these figures.
\begin{figure}[ht]
\includegraphics[width=7cm]{Example2.jpg}
\caption{a figure with a wrong number}
\label{fig:2}
\end{figure}
At the end there are some cross-references to these pictures. Since they are floating, it is not really at the end, but that is tolerable for now.\\
\see{fig:1}\\
\see{fig:1A}\\
\see{fig:1D}\\
\see{fig:2}\\
\sees{fig:1A}{fig:1D}\\
\sees{fig:1}{fig:2}
\listoffigures
\end{document}
附录 2016-04-24(由 Axel Sommerfeldt 编写)
额外解释一下为什么使用\captionabove
可以解决这个问题:
计数器通常在 处递增\caption
(而不是 处\begin{figure}
)。虽然这个简单的规则仅适用于通常的标题,但如果有子标题,则会使所有这些变得更加复杂,因为一个图形中可以有零到 N 个标题,并且\subcaptionbox
(或subfigure
环境)必须知道它属于哪个\caption
。否则,\ref
子标题会产生错误的结果,并且图形列表中的列表条目也会不正确。因此,当有子标题时,figure
(或table
)计数器有时会在标题处递增,有时会在子标题处递增。为了正确增加计数器,figure
子标题必须知道它是属于它前面的主标题,还是属于它后面的主标题。
关于您的情况:\caption
通常意味着\captionbelow
在文档中使用 KOMA-Script 类,因此第一个\subcaptionbox
会额外增加图形计数器,假设它属于\caption
其后的(未来)。因此,将通过使用\captionabove
代替\caption
(或\captionbelow
)来修复此问题:这样\subcaptionbox
就知道它属于\caption
其前面的(过去)排版,这样它就不会再增加计数器了figure
。
答案2
为了快速修复,您可以在第一个浮点数中调用\addtocounter{figure}{-1}
后立即使用\caption
它来获得正确的编号。无论如何,我建议您将其包装到某个宏中。这样做,您可以一次控制此修复的每次发生。在我的解决方案中,我调用了这个宏\StartSubcaptionsFloat
:
\newcommand{\StartSubcaptionsFloat}{\vspace{1em}\addtocounter{figure}{-1}}
如上所述,你可以使用它来标记子图的开始,例如
\begin{figure}
\caption[short heading for the figure with subfigures]
{Something like a heading for this figure containing subfigures}
\StartSubcaptionsFloat
\subcaptionbox[short caption, first subfigure]
{long caption, first subfigure\label{fig:1A}}
{\includegraphics[height=7cm]{ExampleA.jpg}}
\hfill
\subcaptionbox[short caption, second subfigure]
{long caption, second subfigure\label{fig:1B}}
{\includegraphics[height=7cm]{ExampleB.jpg}}
\label{fig:1}
\end{figure}
如果您稍后想要禁用修复,您可以重新定义\StartSubcaptionsFloat
为简单的\vspace
调整,即
\newcommand{\StartSubcaptionsFloat}{\vspace{1em}}
可能你更好的选择是要么改变类,因为问题与 KOMA 类有关,要么\caption
在浮动结束时发出。我强烈建议采用最后一个选项,即说
\begin{figure}
\subcaptionbox[short caption, first subfigure]
{long caption, first subfigure\label{fig:1A}}
{\includegraphics[height=7cm]{ExampleA.jpg}}
\hfill
\subcaptionbox[short caption, second subfigure]
{long caption, second subfigure\label{fig:1B}}
{\includegraphics[height=7cm]{ExampleB.jpg}}
\caption[short heading for the figure with subfigures]
{Something like a heading for this figure containing subfigures}
\label{fig:1}
\end{figure}
因为 1)您将标题放在图像下方的单个浮点数中(因此这是一个一致性的问题),2)您不应该在截止日期附近更改类别,3)这绝对是最干净的解决方案。
附录
请参阅@esdd 的回答,了解 KOMA 内的干净解决方案。