如果在 longtable 环境中使用,\thetable 将返回一个偏离 1 的值

如果在 longtable 环境中使用,\thetable 将返回一个偏离 1 的值

我注意到该\thetable命令返回了错误的环境数字longtable。我在表格标题中包含了短语“上一页继续”,并在其前面添加了\tablename\ \thetable\ \textemdash\。在编译文档时,我看到表 1 在第二页上被称为表 2。单面表格不会发生这种情况,如我的 MWE 中所示。我可以轻松解决这个问题并减少多面表格中的计数器,但我认为这不是最好的主意。找到导致此行为的错误会更好。

有什么想法吗?

平均能量损失

\documentclass{article}
\usepackage{longtable, tabu, booktabs, caption, parskip}

\begin{document}

\begin{table}[h]
    \caption{A floating table}
    \label{tab:floating-table}
    \begin{tabu} to \linewidth {*4{X}}
        \toprule
            Foo
                & Bar
                & Bacon
                & Eggs\\
        \midrule
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
        \bottomrule
    \end{tabu}
\end{table}

That was table \thetable.


\captionof{table}{A non-floating table}
\label{tab:non-floating-table}
\begin{tabu} to \linewidth {*4{X}}
    \toprule
        Foo
            & Bar
            & Bacon
            & Eggs\\
    \midrule
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
    \bottomrule
\end{tabu}\\\\

That was table \thetable.

\captionof{table}{A non-floating longtable}
\label{tab:foobar}
\begin{longtabu} to \linewidth {*4{X}}
    \toprule
        Foo
            & Bar
            & Bacon
            & Eggs\\
        \midrule
        \endfirsthead

        \multicolumn{4}{l}{{\tablename\ \thetable\ \textemdash\ Continued from the previous page}} \\
        \toprule
        Foo
            & Bar
            & Bacon
            & Eggs\\
        \midrule
        \endhead

    \midrule

        \multicolumn{4}{r}{{Continued on the next page}} \\
        \endfoot
        \endlastfoot

        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\

    \bottomrule
\end{longtabu}

That was table \thetable.

\end{document} 

答案1

如果使用\caption而不是\captionof长表,计数器将按预期工作:

在此处输入图片描述

\documentclass{article}
\usepackage{longtable, tabu, booktabs, caption, parskip}

\begin{document}

\begin{table}[h]
    \caption{A floating table}
    \label{tab:floating-table}
    \begin{tabu} to \linewidth {*4{X}}
        \toprule
            Foo
                & Bar
                & Bacon
                & Eggs\\
        \midrule
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
            foo & bar & bacon & eggs\\
        \bottomrule
    \end{tabu}
\end{table}

That was table \thetable.


\captionof{table}{A non-floating table}
\label{tab:non-floating-table}
\begin{tabu} to \linewidth {*4{X}}
    \toprule
        Foo
            & Bar
            & Bacon
            & Eggs\\
    \midrule
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
    \bottomrule
\end{tabu}\\\\

That was table \thetable.


\label{tab:foobar}
\begin{longtabu} to \linewidth {*4{X}}
\caption{A non-floating longtable}\\
    \toprule
        Foo
            & Bar
            & Bacon
            & Eggs\\
        \midrule
        \endfirsthead

        \caption{A non-floating longtable - continued}\\
        \toprule
        Foo
            & Bar
            & Bacon
            & Eggs\\
        \midrule
        \endhead

    \midrule

        \multicolumn{4}{r}{{Continued on the next page}} \\
        \endfoot
        \endlastfoot

        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\
        foo & bar & bacon & eggs\\

    \bottomrule
\end{longtabu}

That was table \thetable.

\end{document} 

相关内容