5

I want to have a page-filling and -breaking longtable, so I decided to try xltabular. Unfortunately xltabular seems to screw up the booktabs rules in the normal tabular environments, see:

\documentclass{article}
\usepackage{booktabs, xltabular}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tabular}
\begin{document}
\begin{tabular}{ccc}
    \toprule
    col1 & col2 & col3 \\
    \midrule
    row 2: & more and moooooooooooore & test \\
    \bottomrule
\end{tabular}
\end{document}

xltabular breaking booktabs in normal tabular environment

Not loading xltabular resolves the issue.

Did I miss some package option or some incompatibilities? Is there a better package than xltabular which doesn't break booktabs?

(I am using TeXLive 2019 and compile with lualatex)


EDIT (by Skillmon)

I reduced the bug to the following MWE (which doesn't make much sense on its own), it looks like booktabs tries to be smart detecting something, but fails badly.

\documentclass{article}
\usepackage{longtable}
\let\xltabular\relax
\usepackage{booktabs}

\begin{document}
\begin{tabular}{ccc}
    \toprule
    col1 & col2 & col3 \\
    \midrule
    row 2: & more and moooooooooooore & test \\
    \bottomrule
\end{tabular}
\end{document}

It seems to suffice that longtable is loaded and \xltabular is defined (even if it's just \relax).

4
  • That's a very strange bug!
    – Skillmon
    Jan 4, 2020 at 18:57
  • 1
    I can confirm the bug. It is not there if you use longtable. I have updated version of MiKTeX.
    – Sveinung
    Jan 4, 2020 at 19:09
  • 1
    @Sveinung the bug is in the current version of booktabs lines 87 to 91.
    – Skillmon
    Jan 4, 2020 at 19:11
  • @Skillmon Thank you for informing me.
    – Sveinung
    Jan 4, 2020 at 19:27

1 Answer 1

7

This bug is confirmed in booktabs.sty version 1.6180339 from 2019/10/08, I don't know whether it is present in earlier versions.

I reported the bug to the maintainer of booktabs. In the meantime, it looks like it could suffice to do the following redefinition of \@BTrule in your preamble:

\documentclass{article}
\usepackage{xltabular}
\usepackage{booktabs}

\makeatletter
\def\@BTrule[#1]{%
  \ifx\longtable\undefined
    \let\@BTswitch\@BTnormal
  \else\ifx\hline\LT@hline
    \nobreak
    \let\@BTswitch\@BLTrule
  \else
     \let\@BTswitch\@BTnormal
  \fi\fi
  \global\@thisrulewidth=#1\relax
  \ifnum\@thisruleclass=\tw@\vskip\@aboverulesep\else
  \ifnum\@lastruleclass=\z@\vskip\@aboverulesep\else
  \ifnum\@lastruleclass=\@ne\vskip\doublerulesep\fi\fi\fi
  \@BTswitch}
\makeatother

\begin{document}
\begin{tabular}{ccc}
    \toprule
    col1 & col2 & col3 \\
    \midrule
    row 2: & more and moooooooooooore & test \\
    \bottomrule
\end{tabular}

\begin{xltabular}{0.7\linewidth}{cXc}
    \toprule
    col1 & col2 & col3 \\
    \midrule
    row 2: & more and moooooooooooore & test \\
    \bottomrule
\end{xltabular}
\end{document}

enter image description here

3
  • Thank you for your answer. Your solution saved my day :) Jan 8, 2020 at 11:43
  • I'd simply replace \ifx\xltabular\undefined with \ifcsname xltabular\endcsname
    – egreg
    Jan 8, 2020 at 15:33
  • @egreg that won't solve the bug. As soon as \xltabular has a hash-table entry, booktabs does no longer try to detect whether it is in a longtable-like environment or an ordinary tabular and just assumes it's always in a longtable-like environment. The test should never look whether \xltabular exists or not, but just on the meaning of \hline.
    – Skillmon
    Jan 8, 2020 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.