我遇到了一个奇怪的错误,Latex 不会连续计算图形。只有当标题位于图形上方并且图形包含子图时,才会出现此错误。子图的数量无关紧要,只要至少包含一个,就会算作两个图形。请在下面找到一个可重现的示例,其中我展示了所有这些情况。
\documentclass[a4paper,11pt,parskip,oneside,leqno]{scrartcl}
\usepackage[a4paper,left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\caption{this is number 1}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{here I have two subfigures with captions}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{second subfigure. I leave out the images for simplicity. This figure is now counted as two and Latex continues with figure 3:}
\end{subfigure}
\end{figure}
\begin{figure}
\caption{this should be figure 2. Here I have no subfigures and this figure is therefore only counted as one}
\centering
\end{figure}
\begin{figure}
\caption{as you can see here. This should be number 3 but we only stepped up one number from the last one so thats ok}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{this one works because the figure above does not use subfigures}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{but after this one, it would continue with number 6 because I'm using subfigures again}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{the number of subfigures does not seem to matter}
\end{subfigure}
\end{figure}
\begin{figure}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{as you can see here}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{again a figure with two subfigures to show that:}
\end{subfigure}
\caption{If I put the caption BELOW the figure, the problem does not appear}
\end{figure}
\begin{figure}
\caption{as you can see here}
\centering
\end{figure}
\end{document}
我想要有带有子图的图形,但我希望在图形顶部有标题,并且我希望 Latex 从 1 计数到 N 而不遗漏数字 ;-) 如能提供任何帮助我将不胜感激!
答案1
如果将标题放在图形内容上方,则应使用文档类选项告知 KOMA-Script captions=figureheading
,例如:
\documentclass[a4paper,11pt,parskip,oneside,leqno,captions=figureheading]{scrartcl}
...
当前版本的 caption/subcaption 包(以及 subfig 包)也使用此设置来确定环境内是否已开始新的图形figure
。(KOMA-Script 的默认设置是captions= figuresignature
。)
也可以看看:https://tex.stackexchange.com/a/304842/43317
顺便说一句:即将推出的 3.4 版标题包将采用不同的方法,因此即使captions=figureheading
不使用,此示例也应该给出正确的编号。(但标题下方的间距仍然不正确,因此captions=figureheading
无论如何使用都是一个好主意。)
答案2
使用floatrow
包,你可以通过以下方式修复这个问题
\floatsetup{capposition=top}
如果你需要在单个图形下方放置标题,则可以使用
\thisfloatsetup{capposition=below}
就在那个图形之前改变位置。
\documentclass[a4paper,11pt,parskip,oneside,leqno]{scrartcl}
\usepackage[a4paper,left=3cm,right=3cm,top=3cm,bottom=3cm]{geometry}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{floatrow}
\floatsetup{capposition=top}
\begin{document}
\begin{figure}
\caption{this is number 1}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{here I have two subfigures with captions}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{second subfigure. }
\end{subfigure}
\end{figure}
\begin{figure}
\caption{this should be figure 2. Here I have no subfigures and this figure is therefore only counted as one}
\centering
\end{figure}
\begin{figure}
\caption{as you can see here. This should be number 3 but we only stepped up one number from the last one so thats ok}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{this one works because the figure above does not use subfigures}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{many subfigures}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{the number of subfigures does not seem to matter}
\end{subfigure}
\end{figure}
\thisfloatsetup{capposition=below}
\begin{figure}
\centering
\begin{subfigure}{0.8\textwidth}
\caption{as you can see here}
\end{subfigure}
\begin{subfigure}{0.8\textwidth}
\caption{again a figure with two subfigures to show that:}
\end{subfigure}
\caption{If I put the caption BELOW the figure, the problem does not appear}
\end{figure}
\begin{figure}
\caption{as you can see here}
\centering
\end{figure}
\end{document}