1

Increasing the line spacing of a longtable (multi-page table) by increasing \arraystretch (default 1) unexpectedly shifts the caption vertically downwards. This can be seen by flipping pages in the compiled PDF. The issue does not appear with regular (non-longtable) tables. Below is a minimal example.

How can I get a bigger line spacing only for the table cells (excluding the table header!), both for the longtable and the regular table? I tried placing the \renewcommand{\arraystretch}{VALUE} inside the longtable (or tabular) environment, but the PDF did not compile at all.

Images:

Longtable, arraystretch 1.0: works as expected Longtable, arraysretch 4.0: unexpected result, caption shifted downwards Regular table, arraystretch 4.0: works as expected

Minimal example: see also https://www.overleaf.com/read/nrhbmgkbwsvh

I want to write an article for the journal Astronomy & Astrophysics (A&A). The required aa.cls file can be downloaded via the A&A LaTeX macro package.

\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 Answer 1

3

This is not surprising, as with longtable, the caption is typeset as a row in the table, so the \arraystretch is also applied to it.

A possible solution could be to shift the caption upward with a \vspace that compensates for the \arraystretch, which is implemented as a "strut".

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

By the way, I couldn't test it in your environment, as (obviously) I can't edit your document. And if I make a copy of your project, for some reason that I can't find out, the longtables just don't appear in the document. And if I make a local copy on my own computer, it crashes as apparently nameref isn't compatible with aa.cls on TeXlive 2022.

So I tested my solution in an adapted version with class article.

3
  • 1
    I tested you code on another example and it worked fine. Commented Jun 29, 2022 at 14:03
  • I tested your answer in the Overleaf environment, and it works perfectly (with your code inserted in the preamble, before \begin{document}. Thanks a lot! I am not sure why having the caption be treated as a table row is an intended feature, but anyways. Is your code "workaround" the preferred/most "Latexesque" way to achieve the increased line-spacing for the longtable rows only? Commented Jun 30, 2022 at 7:33
  • My first idea was to temporarily reset the "array strut" during the processing of the caption, but it appears that the handling of this strut is so intimately tied to the processing of rows that it is difficult to get this working correctly. So I choose for the second best option. Commented Jul 1, 2022 at 8:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .