2

So, this example was bugging me:

\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}

The 'Last table' was getting numbered 1.4 even though it should have been numbered 1.3. On a whim, I moved the \caption of the huge table right before the \end{table} command, and suddenly I got 'Table 1.3. Last table'.

My question is: why?

more minimal example (for comment below)

\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}

marked as duplicate by egreg tables Sep 16 '15 at 10:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • why the commented (pdf)lscape? that should not be necessary, also why \bf ? – David Carlisle Sep 16 '15 at 9:56
  • I switch between lscape and pdflscape and produce a pdf for screen and one for printing. I found out that the landscaped pages produced with pdflscape sometimes get printed upside down by some pdf readers. As I don't know what the printing services are using, I didn't want to take any chances. I forgot to remove the two lines in the MWE. Re \bf, I used www.tablesgenerator.com/latex_tables to generate the tables quickly and haven't touched up yet. They work for now, I'll leave that for when I'll go through the source with a fine comb. – Morpheu5 Sep 16 '15 at 10:07
  • I added a more minimal example with unrelated packages removed. It looks like an interaction between scrbook and subcaption, it doesn't happen if you use book instead. I don't know the koma classes that well, don't they have sub caption features without loading subcaption package? – David Carlisle Sep 16 '15 at 10:07
  • I don't know the koma classes very much as well, so I figured I'd use them for the layout, and do everything else with packages for which I can find examples online quickly. – Morpheu5 Sep 16 '15 at 10:09
  • 1
    I'm nit sure that is a good approach, one of the main ideas behind classes like memorir and koma is that they build in much more functionality, that means that you don't need to load so many add-on packages, but that you are more likely to get clashes if you do load packages that are designed to patch the standard classes to ad features that have already been added. – David Carlisle Sep 16 '15 at 10:11
0

This is already answered here: Caption above subtables with subcaption package breaks numbering of following table

Some additional background: Nobody prevents you from placing more-than-one \caption inside a table. So the subcaption package is taking the position of the caption into respect. In your case, you wrote (with KOMA-Script option captions=tablesignature active):

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

What happens here: \caption will increase the table counter. Afterwards \subcaptionbox sees that there was a \caption right in front of it and assumes that you are starting a second pair of content+caption in the table environment since you have told KOMA-Script that the caption is always typeset after the content. So it increases the table counter. In fact you have two pairs of content+caption in this particular table: Empty content + caption, and \subcaptionbox content without extra caption. If a \caption would follow this would not increase the table counter again since the very first \subcaptionbox has already done this. Try it out for yourself:

\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}

BTW: For debugging counter problems with sub-captions it's always a good idea to put the actual figure/table number into the sub-numbering as well:

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

This way you can clearly see which command actually increases the figure resp. table counter. (If you are done with debugging simply comment these two lines out.)

  • I suspected something like that, I just thought that captions and subcaptions worked on different counters. However, I don't see where I said captions=tablesignature, is it a default? – Morpheu5 Sep 16 '15 at 13:54
  • 1
    Yes, captions=tablesignature is the default, see section 3.20 of the KOMA-Script documentation. And yes, captions and subcaptions work on different counters, but they are connected to each other, just like section and subsection: The subsection counter output contains the section counter (for example "3.2" where "3" is the section and "2" the subsection counter), and it gets reset when a new section starts. Same with the table and subtable counter, the only difference is that the subtable counter output does not contain the table counter by default (but you can change that). – Axel Sommerfeldt Sep 16 '15 at 14:33
  • ...furtheremore the connection between table and subtable counter is important for hyperref anchors/links (since the links should jump to the correct table when clicked). And it is important for the "List of Tables" if the sub-tables are included in the list as well. So you see, the sub-table needs to know the corresponding table counter, even if the \caption which increments the table counter comes after the sub-caption. (This is a little bit tricky since \caption and not table will increase the table counter.) – Axel Sommerfeldt Sep 16 '15 at 14:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.