使用 longtabu 对分页的表格进行不正确的编号

使用 longtabu 对分页的表格进行不正确的编号

使用时表格编号出现问题longtabu,我的表格会转到第二页。这个问题在我的口试中被外部考官发现了——真尴尬!

无论如何,这里有一个 MWE 可以说明这个问题。

我很确定这是\caption我为后续页眉输入的命令。我输入这个命令是为了获取表格拆分后的每个页面顶部的表格编号。

有没有更好的方法(正确的方法)来达到相同的结果?

\documentclass[a4paper,12pt]{report}
\usepackage[top=3cm, bottom=3cm, left=4cm, right=2cm]{geometry} % sets margins
\usepackage{multirow} % allows merging of rows in tables
\usepackage{bigdelim} % Big delimiters in tables
\usepackage[margin=10pt, labelfont=bf, format=hang, textfont={small,it}]{caption} % for more interesting captions
\usepackage{rotating} % Allows rotating of figures and tables.
\usepackage{multirow} % allows merging of rows in tables
\usepackage{bigdelim} % Big delimiters in tables
\usepackage{longtable} % longtable allows tables to be split across pages
\usepackage{tabu} % Updated table environment, replaces ltablex
\usepackage{booktabs} % For professional looking tables
\usepackage{lscape} % landscape package


% Commands for use in tables
\newcommand{\rr}{\raggedright} % Left justification
\newcommand{\tn}{\tabularnewline} % New line command for use with \rr


\begin{document}


\begin{landscape}
    \captionof{table}[Some data in a table where the numbering goes wrong.]{Some data in a table where the numbering goes wrong. }
    \begin{longtabu}{XXXXX}
        % First page header
        \toprule
        \rr \textbf{Data 1}   & \rr \textbf{Data 2} & \rr \textbf{Data 3} & \rr \textbf{Data 4} & \rr \textbf{Data 5} \tn
    \midrule
    \endfirsthead
    % Subsequent page header
    \caption{}[]\\
    \toprule
            \multicolumn{5}{r}{\small\sl \ldots continued from previous page} \\
        \rr \textbf{Data 1}   & \rr \textbf{Data 2} & \rr \textbf{Data 3} & \rr \textbf{Data 4} & \rr \textbf{Data 5} \tn
        \midrule
        \endhead
        % footer for all but last page of table
        \multicolumn{5}{r}{\small\sl continued on next page\ldots}\\
        \bottomrule
        \endfoot
        %footer for last page of table
        \bottomrule
        \endlastfoot        
    % Table data
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \\
      \midrule
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \\
      \midrule
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \\
      \midrule
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \\
      \midrule
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \
    \label{tab:numbers}
    \end{longtabu}
\end{landscape}

\end{document}

答案1

你想达到什么效果?你有

    \caption{}[]

即创建一个带有新数字的空标题,然后排版[]

完全不使用这个命令就可以解决问题,但如果您希望在后面的页面上出现非空标题,请根据您想要发生的情况使用\caption[xxx]{yyy}或。\caption*{...}

答案2

提问者的回答(从问题移出):

问题解决了(无论如何对于我的目的而言)。

\captionof{table}在环境之外使用命令longtabu似乎是问题所在。如果我只使用\caption{}在 longtabu 环境内使用,一切正常(请参阅下面的 MWE)。

我使用 一定有充分的理由。\captionof\caption我想不起来是什么……

\documentclass[a4paper,12pt]{report}
\usepackage[top=3cm, bottom=3cm, left=4cm, right=2cm]{geometry} % sets margins
\usepackage{multirow} % allows merging of rows in tables
\usepackage{bigdelim} % Big delimiters in tables
\usepackage[margin=10pt, labelfont=bf, format=hang, textfont={small,it}]{caption} % for more interesting captions
\usepackage{rotating} % Allows rotating of figures and tables.
\usepackage{multirow} % allows merging of rows in tables
\usepackage{bigdelim} % Big delimiters in tables
\usepackage{longtable} % longtable allows tables to be split across pages
\usepackage{tabu} % Updated table environment, replaces ltablex
\usepackage{booktabs} % For professional looking tables
\usepackage{lscape} % landscape package


% Commands for use in tables
\newcommand{\rr}{\raggedright} % Left justification
\newcommand{\tn}{\tabularnewline} % New line command for use with \rr


\begin{document}


\begin{landscape}
    \begin{longtabu}{XXXXX}
        % First page header
    % **** THIS HAS CHANGED ******
        \caption[Some data in a table where the numbering goes wrong.]{Some data in a table where the numbering goes wrong. }\\
        \toprule
        \rr \textbf{Data 1}   & \rr \textbf{Data 2} & \rr \textbf{Data 3} & \rr \textbf{Data 4} & \rr \textbf{Data 5} \tn
    \midrule
    \endfirsthead
    % Subsequent page header
    % **** THIS HAS CHANGED ******
        \caption{}\\
    \toprule
            \multicolumn{5}{r}{\small\sl \ldots continued from previous page} \\
        \rr \textbf{Data 1}   & \rr \textbf{Data 2} & \rr \textbf{Data 3} & \rr \textbf{Data 4} & \rr \textbf{Data 5} \tn
        \midrule
        \endhead
        % footer for all but last page of table
        \multicolumn{5}{r}{\small\sl continued on next page\ldots}\\
        \bottomrule
        \endfoot
        %footer for last page of table
        \bottomrule
        \endlastfoot        
    % Table data
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \\
      \midrule
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \\
      \midrule
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \\
      \midrule
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \\
      \midrule
1     & 1.1   & a     & 1     & 0.1 \\
      &       & b     & 2     & 0.2 \\
      & 1.2   & c     & 3     & 0.3 \\
      &       & d     & 4     & 0.4 \\
      & 1.3   & e     & 5     & 0.5 \\
      &       & f     & 6     & 0.6 \
    \label{tab:numbers}
    \end{longtabu}
\end{landscape}

\end{document}

相关内容