longtable 和 tabulary 中的几个标题问题

longtable 和 tabulary 中的几个标题问题

我正在尝试排版一些多页表格,每页都有表格注释和重复的标题。我发现问题,它将longtable环境与结合起来tabulary。这非常好,因为这样我就不需要自己处理列宽了,而是可以使用LRJC的选项之一tabulary来帮我处理。

在接下来的 MWE 中,几乎一切都运行良好,但也存在一些字幕问题。

\documentclass{scrartcl}

\usepackage[hypcap=true]{caption}
    \captionsetup{labelfont=bf, justification=justified, singlelinecheck=false, format=plain}

\usepackage{tabulary, booktabs, longtable, ltcaption}
\usepackage[referable]{threeparttablex}

%% define a new envrionment which marries longtable with tabulary
\makeatletter
\def\ltabulary{%
\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
% from https://tex.stackexchange.com/questions/78075/multi-page-with-tabulary (see there for usage)


\begin{document}

\begin{table}
    \caption{Nice long caption directly above the start of the table with lots of...}
\begin{threeparttable}
    \begin{tabulary}{\textwidth}{LlLLL}
        \toprule
        top cell one with title & top cell two with title & longtop with note & top cell four with title & top cell five with title\\
        \midrule
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        \bottomrule
    \end{tabulary}
    \begin{tablenotes}\footnotesize
        \note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
    \end{tablenotes}
\end{threeparttable}
\end{table}


\begin{ThreePartTable}
    \begin{TableNotes}\footnotesize
        \note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
    \end{TableNotes}
%   \setlength\LTleft{0pt}
%   \setlength\LTright{0pt}
    \captionof{table}{Example of long table over multiple pages}
    \begin{ltabulary}{rLlcccc}
        \toprule
        cell 1 & cell with linebreaks if it gets too wide and wider and wider and wider and wider & cell 3 & cell 4 & 5 & 6 & 7 \\
        \midrule
        \endfirsthead
        \toprule
        cell 1 & cell with linebreaks if it gets too wide & cell 3 & cell 4 & 5 & 6 & 7 \\
        \midrule
        \endhead
        \endfoot
        \bottomrule
        \insertTableNotes
        \endlastfoot
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
    \end{ltabulary}
\end{ThreePartTable}


\begin{table}
    \caption{Nice long caption directly above the start of the table with lots of...}
\begin{threeparttable}
    \begin{tabulary}{\textwidth}{LlLLL}
        \toprule
        top cell one with title & top cell two with title & longtop with note & top cell four with title & top cell five with title\\
        \midrule
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        \bottomrule
    \end{tabulary}
    \begin{tablenotes}\footnotesize
        \note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
    \end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

上述代码编译得很好,但我必须使用\captionof会产生问题 2 到 4 的。如果我将其替换为\caption{Example of long table over multiple pages},我会得到问题 1 中的错误。

存在以下问题:

  1. 我无法使用该\caption{}命令。它给了我! LaTeX Error: \caption outside float。无论我是否使用该包,情况都是如此caption。此外,位置无关紧要。我可以把它放在环境内部ltabulary或外部,两次都会给我相同的错误。我怀疑,由于longtable使用它自己的 caption 命令并且它不包含在问题的定义中ltabulary,所以它不起作用。如果是这种情况,错误是有道理的,因为longtable没有在需要的浮点数内设置。我通过使用包中的命令\caption解决了这个问题,但这也带来了它自己的问题:\captionofcaption
  2. 与其他两个表格相比,标题和表格之间的间距太大。可以使用 来修复此问题\vspace{-12pt},但对每个表格都这样做会很繁琐。
  3. 后续表格的编号错误。MWE 中的第三个表格编号为 4,而不是 3。我怀疑这是 longtable 和 的问题\captionof,因为 longtable 为每个页面设置一个新表格,这会增加表格计数器。可以使用 来修复此问题\addtocounter{table}{-1},但这同样非常繁琐。
  4. 我无法重复每个页面的标题,因为环境\captionof内部ltabulary会给出错误:! Missing \endgroup inserted。我可以通过手动设置标题来解决这个问题,但这更加繁琐,因为如果我移动表格,我必须返回每个表格并调整编号。它也不应该重复每个页面的整个标题,而是添加类似于“表格 2(续)”的内容。

这里是否有一些向导可以将\caption命令添加到ltabulary定义中(这可能一次性解决上述所有问题),或者以其他方式修复它?

答案1

令我大吃一惊的是,我居然成功修补了环境代码,ltabulary以添加对该\caption命令的支持。修补后的代码取自ltxtable包装有很小的变化,仅包含 3 行。

下面的代码一次性解决了所有问题,正如问题中第一个问题所建议的那样。用这个代码替换 MWE 中的相应代码,将命令转换\captionof\caption命令并将其移动到环境中ltabulary

%% define a new envrionment which marries longtable with tabulary
% from http://tex.stackexchange.com/questions/78075/multi-page-with-tabulary (see there for usage)
% with modifications taken from the ltxtable package to make captions work
\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

为了完整起见,以下是更正后的 MWE:

\documentclass{scrartcl}

\usepackage[hypcap=true]{caption}
    \captionsetup{labelfont=bf, justification=justified, singlelinecheck=false, format=plain}

\usepackage{tabulary, booktabs, longtable, ltcaption, ltabptch}
\usepackage[referable]{threeparttablex}

%% define a new envrionment which marries longtable with tabulary
% from http://tex.stackexchange.com/questions/78075/multi-page-with-tabulary (see there for usage)
% with modifications taken from the ltxtable package to make captions work
\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}

\begin{table}
    \caption{Nice long caption directly above the start of the table with lots of...}
\begin{threeparttable}
    \begin{tabulary}{\textwidth}{LlLLL}
        \toprule
        top cell one with title & top cell two with title & longtop with note & top cell four with title & top cell five with title\\
        \midrule
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        \bottomrule
    \end{tabulary}
    \begin{tablenotes}\footnotesize
        \note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
    \end{tablenotes}
\end{threeparttable}
\end{table}


\begin{ThreePartTable}
    \begin{TableNotes}\footnotesize
        \note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
    \end{TableNotes}
%   \setlength\LTleft{0pt}
%   \setlength\LTright{0pt}
%   \captionof{table}{Example of long table over multiple pages}
    \begin{ltabulary}{rLlcccc}
        \caption{Example of long table over multiple pages}\\
        \toprule
        cell 1 & cell with linebreaks if it gets too wide and wider and wider and wider and wider & cell 3 & cell 4 & 5 & 6 & 7 \\
        \midrule
        \endfirsthead
        \caption[]{(continued)}\\
        \toprule
        cell 1 & cell with linebreaks if it gets too wide & cell 3 & cell 4 & 5 & 6 & 7 \\
        \midrule
        \endhead
        \endfoot
        \bottomrule
        \insertTableNotes
        \endlastfoot
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
    \end{ltabulary}
\end{ThreePartTable}


\begin{table}
    \caption{Nice long caption directly above the start of the table with lots of...}
\begin{threeparttable}
    \begin{tabulary}{\textwidth}{LlLLL}
        \toprule
        top cell one with title & top cell two with title & longtop with note & top cell four with title & top cell five with title\\
        \midrule
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        \bottomrule
    \end{tabulary}
    \begin{tablenotes}\footnotesize
        \note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
    \end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

以下是之前不起作用的结果摘录:

表 2 标题 表 2(续)标题 表 3 正确编号

如果我有勇气的话,我可能会将其转换成一个真正的包裹。

答案2

好吧,我读了你的 MWE 代码,前两行重复了一次,我从 MWE 中删除了它们,后来我复制了代码并在我的计算机上编译,没有错误。第一次只有第二个表格出现错误,显示脚注在非常窄的列中。但第二次看起来都很好。

我担心您报告的错误来自代码中的那些重复行,就我而言,这是我编译的代码:

\documentclass{scrartcl}

\usepackage[hypcap=true]{caption}
    \captionsetup{labelfont=bf, justification=justified, singlelinecheck=false, format=plain}

\usepackage{tabulary,booktabs,longtable,ltcaption}
\usepackage[referable]{threeparttablex}

%% define a new envrionment which marries longtable with tabulary
\makeatletter
\def\ltabulary{%
\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
% from http://tex.stackexchange.com/questions/78075/multi-page-with-tabulary (see there for usage)


\begin{document}

\begin{table}
    \caption{Nice long caption directly above the start of the table with lots of...}
\begin{threeparttable}
    \begin{tabulary}{\textwidth}{LlLLL}
        \toprule
        top cell one with title & top cell two with title & longtop with note & top cell four with title & top cell five with title\\
        \midrule
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        \bottomrule
    \end{tabulary}
    \begin{tablenotes}\footnotesize
        \note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
    \end{tablenotes}
\end{threeparttable}
\end{table}


\begin{ThreePartTable}
    \begin{TableNotes}\footnotesize
        \note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
    \end{TableNotes}
%   \setlength\LTleft{0pt}
%   \setlength\LTright{0pt}
    \captionof{table}{Example of long table over multiple pages}
    \begin{ltabulary}{rLlcccc}
        \toprule
        cell 1 & cell with linebreaks if it gets too wide and wider and wider and wider and wider & cell 3 & cell 4 & 5 & 6 & 7 \\
        \midrule
        \endfirsthead
        \toprule
        cell 1 & cell with linebreaks if it gets too wide & cell 3 & cell 4 & 5 & 6 & 7 \\
        \midrule
        \endhead
        \endfoot
        \bottomrule
        \insertTableNotes
        \endlastfoot
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
        1 & 2 & 3 & 4 & 5 & 6 & 7 \\
    \end{ltabulary}
\end{ThreePartTable}


\begin{table}
    \caption{Nice long caption directly above the start of the table with lots of...}
\begin{threeparttable}
    \begin{tabulary}{\textwidth}{LlLLL}
        \toprule
        top cell one with title & top cell two with title & longtop with note & top cell four with title & top cell five with title\\
        \midrule
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        cell & cell & big long cell stuff & cell & more cell\\
        \bottomrule
    \end{tabulary}
    \begin{tablenotes}\footnotesize
        \note This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines. This is a long explanation going over multiple lines.
    \end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

我使用Sublime Text 2LaTeXtools进行编译。我的机器使用Ubuntu 14.04SO,我使用TeXlive 2013。如果我打开终端并pdflatex直接使用,结果是相同的。

表格1 塔布拉 2 塔布拉 4

相关内容