长表标题因增加 \arraystretch(行距)而移动?

长表标题因增加 \arraystretch(行距)而移动?

增加长表(多页表)的行距\arraystretch(默认值为 1)会导致标题意外地垂直向下移动。这可以通过翻阅编译后的 PDF 中的页面来看到。常规(非长表)表格不会出现此问题。下面是一个最小示例。

如何才能让长表和常规表的单元格(不包括表头)的行距更大?我尝试将其放置\renewcommand{\arraystretch}{VALUE}在长表(或表格)环境中,但 PDF 根本无法编译。

图片:

Longtable,arraystretch 1.0:按预期工作 Longtable,arraysretch 4.0:意外结果,标题向下移动 常规表格,arraystretch 4.0:按预期工作

最小示例:也可以看看https://www.overleaf.com/read/nrhbmgkbwsvh

我想为《天文学与天体物理学》(A&A)杂志撰写一篇文章。所需aa.cls文件可通过A&A LaTeX 宏包

\documentclass{aa}

\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{graphicx} % extended variant of graphics package, loaded by default in A&A demo article
\usepackage{txfonts} % use nice TX fonts, loaded by default in A&A demo article

% disable hyperref warning 'Suppressing link with empty target';
% see https://tex.stackexchange.com/a/345918/113493
\makeatletter
\renewcommand*\aa@pageof{, page \thepage{} of \pageref*{LastPage}}
\makeatother

\begin{document}

\maketitle

\newpage

% Longtable, arraystretch 1.0: works as expected, no issues

\longtab[1]{
\begin{longtable}{c c c}
\caption{Longtable, arraystretch 1.0: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.} \\
\hline
\hline
Col1 & Col2 & Col3 \\
\hline
\endfirsthead
\caption{continued.} \\
\hline
\hline
Col1 & Col2 & Col3 \\
\hline
\endhead
\hline
\hline
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
\hline
\end{longtable}
}

\newpage

% Longtable, arraystretch 4.0: unexpected result, caption is shifted downwards

\longtab[2]{
\renewcommand{\arraystretch}{4.0}
\begin{longtable}{c c c}
\caption{Longtable, arraystretch 4.0: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.} \\
\hline
\hline
Col1 & Col2 & Col3 \\
\hline
\endfirsthead
\caption{continued.} \\
\hline
\hline
Col1 & Col2 & Col3 \\
\hline
\endhead
\hline
\hline
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
\hline
\end{longtable}
\renewcommand{\arraystretch}{1.0}
}

\newpage

% Regular table, arraystretch 4.0: works as expected, no issues

\begin{table*}
\renewcommand{\arraystretch}{4.0}
\caption{Regular table, arraystretch 4.0: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.}
\centering
\begin{tabular}{c c c}
\hline
\hline
Col1 & Col2 & Col3 \\
\hline
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
\hline
\end{tabular}
\renewcommand{\arraystretch}{1.0}
\end{table*}

\end{document}

答案1

这并不奇怪,因为longtable,标题被排版为表格中的一行,因此\arraystretch也适用于它。

一个可能的解决方案是将标题向上移动,以\vspace补偿\arraystretch,这被实现为“支柱”。

\makeatletter
\def\LT@caption{%
  \noalign\bgroup
  \vspace{\dimexpr\ht\strutbox-\ht\@arstrutbox}% <<<<<<<<<<<<
    \@ifnextchar[{\egroup\LT@c@ption\@firstofone}\LT@capti@n}
\makeatother

顺便说一句,我无法在您的环境中测试它,因为(显然)我无法编辑您的文档。如果我复制了您的项目,由于某种我无法找出的原因,longtable文档中不会出现 s。如果我在自己的计算机上制作本地副本,它会崩溃,因为它显然与TeXlive 2022nameref不兼容。aa.cls

因此我使用类测试了我的改编版本的解决方案article

相关内容