ltablex + \caption[]{...} = 错误或缺陷?

ltablex + \caption[]{...} = 错误或缺陷?

我正在使用 koma-script 中的文档类 scrbook 编写论文,并想使用包 ltablex(= longtable + tabularx)来设置具有自动分页符计算的长表。

现在,我面临两个问题:

  1. 为什么标题比\linewidth(请参阅下面的最小文档)长一点?
  2. \caption[short]{long caption}为什么当我使用ltxtable时会出现 latex 错误?

非常感谢您的帮助!

% Please find below a minimal latex document, that shows the problem
%
\RequirePackage[l2tabu,orthodox]{nag}
\documentclass[pagesize=pdftex,ngerman,english,paper=a5,fontsize=10pt,%
               DIV=calc,BCOR=4mm,twoside,headinclude,footinclude,open=right,%
               parskip=half,numbers=noenddot,headings=small]{scrbook}

% Geometry
\usepackage[showframe]{geometry} % showframes for debugging reasons

% Input and font encoding, Babel
\usepackage{cmap}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman,english]{babel}
\usepackage{lmodern,textcomp}

% Tables
\usepackage[NewCommands]{ragged2e}
\usepackage{array}
\usepackage{tabularx,longtable,ltablex}
\usepackage{booktabs}

% Misc. packages
\usepackage[pdftex,final]{graphicx}
\usepackage{amsmath,bm}
\usepackage[babel,final]{microtype}
\usepackage{fixltx2e,ellipsis}
\usepackage{subfigure}
\usepackage{acronym}

% Hyperref
\usepackage[pdftex=true,pdfpagemode=UseNone,pdfpagelayout=TwoPageRight,%
            pdfcenterwindow=true,pdffitwindow=true,colorlinks=true]{hyperref}

% Note: Not all of the above packages are used in this minimal example. They
%       are included for debug reasosn, because they are used in the final
%       document.

% ----------------------------------------------------------------------------

\begin{document}
%\listoftables

\chapter{First Chapter}
\begin{tabularx}{\linewidth}{XXXX}

%This is the caption of the table...
\caption{Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.} \\ % This works.

%\caption[Lorem ipsum]{Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.} \\ % This doesn't works!


%This is the header for the first page of the table...
  \toprule
  \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} \\
  \midrule
\endfirsthead

%This is the header for the remaining page(s) of the table...
  \multicolumn{4}{l}{{\tablename} \thetable{}: \ldots Continued from previous page} \\
  \toprule
  \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} \\
  \midrule
\endhead

%This is the footer for all pages except the last page of the table...
  \midrule
  \multicolumn{4}{r}{Continued on next page\ldots} \\
  \midrule
\endfoot

%This is the footer for the last page of the table...
  \bottomrule
\endlastfoot

%Now the data...
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
\end{tabularx}

\end{document}

答案1

回答 1:这似乎是 longtable 包的一个问题:

\documentclass{scrbook}

% Geometry
\usepackage[showframe]{geometry} % showframes for debugging reasons

% Tables
\usepackage{longtable,booktabs}

\begin{document}
%\listoftables

\chapter{First Chapter}
\begin{longtable}{llll}

%This is the caption of the table...
\caption{Lorem ipsum dolor sit amet, consetetur sadipscing eltr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.} \\

%This is the header for the first page of the table...
  \toprule
  \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} \\
  \midrule
\endhead

%This is the footer for all pages except the last page of the table...
  \midrule
  \multicolumn{4}{r}{Continued on next page\ldots} \\
  \midrule
\endfoot

%This is the footer for the last page of the table...
  \bottomrule
\endlastfoot

%Now the data...
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
\end{longtable}

\end{document}

本周末将做进一步检查...

\caption{...}附录:这是因为和之间有额外的空间\\。 longtable 不会忽略它(设计缺陷),因此您必须将其删除才能获得正确的对齐。

答案 2:ltablex 包重新定义\caption的方式不支持使用可选参数。所以这是 ltablex 中的一个错误。

\def\caption{\\}附录:可以通过在 ltablex.sty 中替换来修复此错误\renewcommand\caption[1][]{\\}。要么将 ltablex.sty 复制到 myltablex.sty,然后在 myltablex.sty 中进行更改,要么在文档的序言中使用这个非常脏的补丁:

\makeatletter
\begingroup
\long\def\x#1\TX@verb#2\edef#3\endhead#4\@nil{%
  \endgroup
  \def\TX@endtabularx{%
    #1\TX@verb
    \def\@elt####1{\global\value{####1}\the\value{####1}\relax}%
    \edef#3\endhead
    \renewcommand\caption[1][]{\\}%
    #4}%
}
\expandafter\x\TX@endtabularx\@nil
\makeatother

(我相信 TeX 向导可以推进这一点。)

相关内容