\caption 的位置计数器增加两次

\caption 的位置计数器增加两次

所以,这个例子让我很烦恼:

\documentclass[12pt,a4paper,twoside,DIV=9,BCOR=2cm,openright,parskip=never]{scrbook}
% \documentclass{article}
% \usepackage{floatrow}
\usepackage{subcaption}
% \setcapindent{0pt}
\usepackage{booktabs}

\usepackage{afterpage}
% \usepackage{pdflscape}    % FOR DISPLAY
\usepackage{lscape}     % FOR PRINTING

\usepackage{blindtext}

\begin{document}

\chapter{First chapter}

\blindtext

\begin{table}
    \centering
    \begin{tabular}{@{}cc@{}}
        \toprule
        10 & 20 \\ \midrule
        30 & 40 \\
        50 & 60 \\ \bottomrule
    \end{tabular}
    \caption{First table.}
\end{table}

\blindtext

\begin{landscape}
    \begin{table}[p]
        \centering
        \caption{Summary of the answers to the demographics questionnaires}\label{tab:st3:demographics}

        \subcaptionbox{A1: Have you studied music?}{
            \begin{tabular}{@{}rccc}
                \toprule
                & {\bf\small no}
                & {\bf\small informally}
                & {\bf\small formally} \\ \midrule
                {\bf\small beginners}       & {\bf 7} & 5 &       2  \\
                {\bf\small non-beginners}   &      0  & 1 & {\bf  9}  \\
                {\bf\small total}           &      7  & 6 & {\bf 11} \\ \bottomrule
            \end{tabular}
        }\qquad
        \subcaptionbox{A2: Do you play a musical instrument?}{
            \begin{tabular}{ccc}
                \toprule
                {\bf\small no}
                & {\bf\small one}
                & {\bf\small more} \\ \midrule
                {\bf 10} & 3 &      1  \\
                      0  & 2 & {\bf 8} \\
                {\bf 10} & 5 &      9  \\ \bottomrule
            \end{tabular}
        }\qquad
        \subcaptionbox{A3: Have you ever composed original music?}{
            \begin{tabular}{ccc}
                \toprule
                  \textbf{\small never}
                & \textbf{\small occasionally}
                & \textbf{\small often} \\ \midrule
                {\bf 11} & 3 &      0  \\
                {\bf  4} & 2 & {\bf 4} \\
                {\bf 15} & 5 &      4  \\ \bottomrule
            \end{tabular}
        }

        \vspace{\baselineskip}

        \subcaptionbox{A2.1: How would you rate your skills on your best instrument?}{
            \begin{tabular}{@{}rccccc}
                \toprule
                & {\bf\small 1} & {\bf\small 2} & {\bf\small 3} & {\bf\small 4} & {\bf\small 5} \\ \midrule
                {\bf\small beginners}     & {\bf 4} & 1 &      1  & 0 & 0 \\
                {\bf\small non-beginners} &      1  & 2 & {\bf 6} & 0 & 1 \\
                {\bf\small total}         &      5  & 3 & {\bf 7} & 0 & 1 \\ \bottomrule
            \end{tabular}
        }\qquad
        \subcaptionbox{A3.1: How confident are you in your ability to compose original music?}{
            \begin{tabular}{ccccc}
                \toprule
                {\bf\small 1}  & {\bf\small 2} & {\bf\small 3} & {\bf\small 4} & {\bf\small 5} \\ \midrule
                {\bf  8} & 5 & 1 & 0 & 0 \\
                {\bf  3} & 2 & 2 & 2 & 1 \\
                {\bf 11} & 7 & 3 & 2 & 1 \\ \bottomrule
            \end{tabular}
        }
    \end{table}
\end{landscape}

\blindtext

\begin{table}
    \centering
    \begin{tabular}{@{}cc@{}}
        \toprule
        70 & 80 \\ \midrule
        90 & 100 \\
        110 & 120 \\ \bottomrule
    \end{tabular}
    \caption{Last table.}
\end{table}

\blindtext

\end{document}

“最后一张桌子”的编号应该是 1.3,但实际上它的编号是 1.4。我一时兴起,在命令\caption之前移动了这张大桌子\end{table},然后突然就得到了“桌子 1.3。最后一张桌子”。

我的问题是:为什么?

更简单的例子(用于下面的评论)

\documentclass{scrbook}

\usepackage{subcaption}

\begin{document}

\chapter{First chapter}

x

\begin{table}
    \centering
t1
    \caption{First table.}
\end{table}

x
\begin{table}[p]
\caption{zz}
\subcaptionbox{A1}{???}
\end{table}

x

\begin{table}
    \centering
t last
    \caption{Last table.}
\end{table}

\end{document}

答案1

这里已经回答了这个问题:子表上方的标题与子标题包中断了下表的编号

\caption一些额外的背景知识:没有人阻止您在 中放置多个table。因此,subcaption包会考虑标题的位置。在您的例子中,您写道(启用 KOMA-Script 选项captions=tablesignature):

\caption{zz}
\subcaptionbox{A1}{???}

这里发生了什么:\caption将增加table计数器。之后看到它前面\subcaptionbox有一个,并假设您正在环境中启动第二对内容+标题,因为您已经告诉 KOMA-Script 标题始终是排版的\captiontable内容。因此它会增加table计数器。实际上,在这个例子中,您有两对内容+标题table:空内容+标题,以及\subcaptionbox没有额外标题的内容。如果 a\caption遵循此操作,则不会table再次增加计数器,因为第一个\subcaptionbox已经这样做了。自己尝试一下:

\documentclass{scrbook}

\usepackage{subcaption}

\begin{document}

\chapter{First chapter}

x

\begin{table}
    \centering
t1
    \caption{First table.}
\end{table}

x
\begin{table}[p]
\caption{zz}
\subcaptionbox{A1}{???}
\caption{zz} % This caption added, note that it does *not* increase the table counter
\end{table}

x

\begin{table}
    \centering
t last
    \caption{Last table.}
\end{table}

\end{document}

顺便说一句:为了调试子标题的计数器问题,最好将实际的图形/表格编号也放入子编号中:

\renewcommand\thesubfigure{\thefigure\alph{subfigure}}
\renewcommand\thesubtable{\thetable\alph{subtable}}

这样,您就可以清楚地看到哪个命令实际上增加了数字和表格计数器。(如果您已完成调试,只需将这两行注释掉即可。)

相关内容