1

I am using a longtable because my table exceeds one page. When I want to label the table, numbering starts with 2 (when the label is below the table). When I label the table on top of it, it starts with 1, but the next table continues with 3 instead of 2. When changing longtable to tabular, it works with no flaws.

See simplified code:

\documentclass{scrartcl}
\usepackage[english]{babel}
\usepackage{caption}
\usepackage{longtable}

\begin{document}
%   \captionof{table}{tab1
%   \label{Tab:tab0}}
    \begin{longtable}[h]{ll}
        a & b
    \end{longtable}
    \captionof{table}{tab1
    \label{Tab:tab1}}

    \begin{tabular}[h]{llllll}
    asdf & asdf & adf & Dasdfasdf & asdfasdfn & asdf
    \end{tabular}
    \captionof{table}{tab2
    \label{Tab:tab2}}

\end{document}

I know I might should use \begin{table}, but somehow I wrote the whole document without it and added labels in the end. Because I don't use \begin{table}, I am using the workaround \captionof which I found somewhere on the internet.

2
  • I assume "label the table" refers to adding a caption. You can directly use \caption inside of a longtable environment to do so. There is no need for \captionof here.
    – leandriis
    Jan 11 at 11:09
  • oh, simple as that :P thx a lot! :) Jan 11 at 12:01
1

Although a longtable does not float, you can nevertheless use the \caption command inside of a longtable environment and your tables will be numbered correctly:

\documentclass{scrartcl}
\usepackage[english]{babel}
\usepackage{caption}
\usepackage{longtable}

\begin{document}

    \begin{longtable}[h]{ll}
    \caption{tab1\label{Tab:tab0}}\\
        a & b
    \end{longtable}

    \begin{tabular}[h]{llllll}
    asdf & asdf & adf & Dasdfasdf & asdfasdfn & asdf
    \end{tabular}
    \captionof{table}{tab2
    \label{Tab:tab2}}

\end{document}

Since you can have multiple \caption commands inside of one longtable (One caption for the first page and a different one for all following pages), the table counter is not increased for each \caption command but once for the whole longtable environment. Thus, if you want a longtable without any caption, you must manually decrease the table counter by one, for example by using \addtocounter{table}{-1}.

1
  • sorry about that: not the best part of the longtable design Jan 11 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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