结合 ThreePartTable 和“ltabulary”时的表格编号

结合 ThreePartTable 和“ltabulary”时的表格编号

我正在尝试使用一个tabular具有功能tabulary但允许多个页表的环境(这种“catch-all”解决方案是必要的,因为由 latex 代码自动生成,所以结合这些包的功能的单一“表环境”是理想的)。

目前,表格编号不正确 - 每个表格的编号增加 2,因此例如前两个表格的编号为 0.1 和 0.3(而不是 0.2!)。

我尝试在下面提供一个最小示例,演示列宽调整(在表 1 中)和多页功能(在表 2 中),同时显示编号问题。这是我能制作的最简单可重现的示例。

作为参考,ltabulary环境取自以下来源:

代码:

\documentclass[oneside]{scrbook}

\usepackage{longtable}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage[referable]{threeparttablex}
\usepackage{caption}

% define ltabulary environment
\makeatletter
\newcommand*\TY@cap@gobble[2][]{\\}% from ltxtable (adjusted)
\def\ltabulary{%
    \def\caption{% from ltxtable (adjusted)
        \@ifstar\TY@cap@gobble\TY@cap@gobble}
    \def\endfirsthead{\\}%
    \def\endhead{\\}%
    \def\endfoot{\\}%
    \def\endlastfoot{\\}%
    \def\tabulary{%
        \def\TY@final{%
    \def\endfirsthead{\LT@end@hd@ft\LT@firsthead}%
    \def\endhead{\LT@end@hd@ft\LT@head}%
    \def\endfoot{\LT@end@hd@ft\LT@foot}%
    \def\endlastfoot{\LT@end@hd@ft\LT@lastfoot}%
    \longtable}%
        \let\endTY@final\endlongtable
        \TY@tabular}%
    \dimen@\columnwidth
    \advance\dimen@-\LTleft
    \advance\dimen@-\LTright
    \tabulary\dimen@}
\def\endltabulary{\endtabulary}
\makeatother

\begin{document}

\mainmatter

    \begin{ThreePartTable}
    \captionof{table}{Short table (with long columns)}
    \begin{ltabulary}{L L L L }
        \toprule
        H1 & H2 & H3 & H4\\
        \midrule
        \endfirsthead
        \toprule
        H1 & H2 & H3 & H4\\
        \midrule
        \endhead
        \endfoot
        \bottomrule
        \endlastfoot
        A & B & C & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu lorem et massa interdum commodo a et nisi. Suspendisse mauris velit, molestie et iaculis at, posuere vel dui. Aenean at ante lorem. Nullam porttitor vestibulum scelerisque. Maecenas et posuere nisi\\
    \end{ltabulary}
    \label{comparisons_table}
    \end{ThreePartTable}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu lorem et massa interdum commodo a et nisi. Suspendisse mauris velit, molestie et iaculis at, posuere vel dui. Aenean at ante lorem. Nullam porttitor vestibulum scelerisque. Maecenas et posuere nisi, id finibus metus. Vivamus vehicula viverra vestibulum. Morbi sed tellus at mi mollis rutrum quis ut est. Vivamus consequat consectetur purus, id pellentesque elit pretium et. Fusce luctus, nibh sit amet mollis volutpat, ex enim pretium ipsum, at pharetra justo erat ut dui. Interdum et malesuada fames ac ante ipsum primis in faucibus.


    \begin{ThreePartTable}
    \captionof{table}{Long table}
    \begin{ltabulary}{L L L L }
        \toprule
        H1 & H2 & H3 & H4\\
        \midrule
        \endfirsthead
        \toprule
        H1 & H2 & H3 & H4\\
        \midrule
        \endhead
        \endfoot
        \bottomrule
        \endlastfoot
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
        A & B & C & D\\
    \end{ltabulary}
    \label{comparisons_table}
    \end{ThreePartTable}

\end{document}

输出(第 1 页): 第 1 页输出

答案1

只需使用longtable的方法处理字幕就可以了:

表格一个接一个地出现......

\documentclass[oneside]{scrbook}

\usepackage{longtable}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage[referable]{threeparttablex}
\usepackage{caption}

% define ltabulary environment
\makeatletter
\newcommand*\TY@cap@gobble[2][]{\\}% from ltxtable (adjusted)
\def\ltabulary{%
    \def\caption{% from ltxtable (adjusted)
        \@ifstar\TY@cap@gobble\TY@cap@gobble}
    \def\endfirsthead{\\}%
    \def\endhead{\\}%
    \def\endfoot{\\}%
    \def\endlastfoot{\\}%
    \def\tabulary{%
        \def\TY@final{%
    \def\endfirsthead{\LT@end@hd@ft\LT@firsthead}%
    \def\endhead{\LT@end@hd@ft\LT@head}%
    \def\endfoot{\LT@end@hd@ft\LT@foot}%
    \def\endlastfoot{\LT@end@hd@ft\LT@lastfoot}%
    \longtable}%
        \let\endTY@final\endlongtable
        \TY@tabular}%
    \dimen@\columnwidth
    \advance\dimen@-\LTleft
    \advance\dimen@-\LTright
    \tabulary\dimen@}
\def\endltabulary{\endtabulary}
\makeatother

\begin{document}

\mainmatter

\begin{ThreePartTable}
  \begin{ltabulary}{L L L L }
  \caption{Short table (with long columns)\label{comparisons_table}}\\
    \toprule
    H1 & H2 & H3 & H4\\
    \midrule
    \endfirsthead
    \toprule
    H1 & H2 & H3 & H4\\
    \midrule
    \endhead
    \endfoot
    \bottomrule
    \endlastfoot
    A & B & C & Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu lorem et massa interdum commodo a et nisi. Suspendisse mauris velit, molestie et iaculis at, posuere vel dui. Aenean at ante lorem. Nullam porttitor vestibulum scelerisque. Maecenas et posuere nisi\\
  \end{ltabulary}
\end{ThreePartTable}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eu lorem et massa interdum commodo a et nisi. Suspendisse mauris velit, molestie et iaculis at, posuere vel dui. Aenean at ante lorem. Nullam porttitor vestibulum scelerisque. Maecenas et posuere nisi, id finibus metus. Vivamus vehicula viverra vestibulum. Morbi sed tellus at mi mollis rutrum quis ut est. Vivamus consequat consectetur purus, id pellentesque elit pretium et. Fusce luctus, nibh sit amet mollis volutpat, ex enim pretium ipsum, at pharetra justo erat ut dui. Interdum et malesuada fames ac ante ipsum primis in faucibus.


\begin{ThreePartTable}
  \begin{ltabulary}{L L L L }
    \caption{Long table\label{comparisons_table}}\\
    \toprule
    H1 & H2 & H3 & H4\\
    \midrule
    \endfirsthead
    \toprule
    H1 & H2 & H3 & H4\\
    \midrule
    \endhead
    \endfoot
    \bottomrule
    \endlastfoot
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
    A & B & C & D\\
  \end{ltabulary}

\end{ThreePartTable}

\end{document}

相关内容