lvjr / tabularray

Typeset tabulars and arrays with LaTeX3
https://ctan.org/pkg/tabularray
247 stars 22 forks source link

Changing `\abovetopsep` length name does not take any effect #437

Closed celdorwow closed 9 months ago

celdorwow commented 9 months ago

tabularray version:

package:     tabularray
revision:    66276
cat-version: 2023A

Hello,

booktabs defines \abovetopsep length, which is set to 0pt by default. Any non-zero value affects the space above the first rule. This is particularly useful to add some space between caption and the table without loading caption or issuing any extra macros such as \smallskip, or \vspace{...}, etc.

Setting \abovetopsep in tabularray does not take any effect. I understand I am supposed to use booktabs environment where spacing is indeed controlled by \aboverulesep and \belowrulesep. I have also tested \spacialrule{\heavyrulewidth}{6pt}{0pt} as the first rule and the spacing between caption and the table is not added.

Here's small demo:

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\setlength\abovetopsep{6pt}
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}

\begin{document}
\begin{table}[tbh]
  \caption{Test table}\label{tab:test}
  \centering
  \begin{tabular}{@{} *3{l} @{}}
  \toprule
  Column & Column & Column \\
  \midrule
  Test & Test & Test \\
  Test & Test & Test \\
  Test & Test & Test \\
  Test & Test & Test \\
  \bottomrule
\end{tabular}
\end{table}

\begin{table}[tbh]
  \caption{Test table}\label{tab:test}
  \centering
  \begin{booktabs}{
    width=\textwidth,
    colspec={@{} *3{Q[l]} @{}},
  }
  % \specialrule{\heavyrulewidth}{6pt}{0pt}
  \toprule
  Column & Column & Column \\
  \midrule
  Test & Test & Test \\
  Test & Test & Test \\
  Test & Test & Test \\
  Test & Test & Test \\
  \bottomrule
\end{booktabs}
\end{table}

\begin{table}[tbh]
  \caption{Test table}\label{tab:test}
  \centering
  \begin{tblr}{
    width=\textwidth,
    colspec={@{} *3{Q[l]} @{}},
    }
  \toprule
  Column & Column & Column \\
  \midrule
  Test & Test & Test \\
  Test & Test & Test \\
  Test & Test & Test \\
  Test & Test & Test \\
  \bottomrule
  \end{tblr}
\end{table}
\end{document}

tabularray-test

muzimuzhi commented 9 months ago

As (vaguely) documented in package manual (2023A, 2023-03-01), sec. 5.2 "Library booktabs", the booktabs library makes use of only two dimensions provided by booktabs package: \aboverulesep and \belowrulesep.

To control vertical spacing above and below a row (between row cells and hlines, if exist), tabularray provides hborder inner option and \hborder{<kv-list>} tabular command, see package manual, sec. 2.3 "Hborders and Vborders". But unfortunately, as hborder works for a row, currently in tabularray there's no direct correspondence of \abovetopsep and \belowbottomsep (which set spacing above the first hline position and below the last hline position, respectively) in booktabs package.

But in your case, to control the vertical spacing between caption and a booktabs-style tabular (right below the caption), you do have a solution. And in some sense, you need it. Here I recommend caption package. For more info, see https://texfaq.org/FAQ-destable.

Note without \captionsetup[table]{position=top}, a 10pt (default value of \abovecaptionskip) vertical spacing is always inserted before a caption, which becomes unwanted if tabular captions are above tabular, not below. That's way I said "you need it" before.

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}

\usepackage{caption}
% restore latex2e kernel spacing for all float types,
% see https://gitlab.com/axelsommerfeldt/caption/-/issues/71
\captionsetup{strut=off}
\captionsetup[table]{position=top, skip=6pt}

\begin{document}
\begin{table}[tbh]
  \centering
  \caption{Test \texttt{booktabs} table}

  \begin{booktabs}{
    width=\textwidth,
    colspec={@{} *3{Q[l]} @{}},
  }
    \toprule
    Column & Column & Column \\
    \midrule
    Test & Test & Test \\
    Test & Test & Test \\
    Test & Test & Test \\
    Test & Test & Test \\
    \bottomrule
  \end{booktabs}
\end{table}

\captionsetup[table]{skip=10pt}

\begin{table}[tbh]
  \centering
  \caption{Test \texttt{booktabs} table, larger skip below caption}

  \begin{booktabs}{
    width=\textwidth,
    colspec={@{} *3{Q[l]} @{}},
  }
    \toprule
    Column & Column & Column \\
    \midrule
    Test & Test & Test \\
    Test & Test & Test \\
    Test & Test & Test \\
    Test & Test & Test \\
    \bottomrule
  \end{booktabs}
\end{table}
\end{document}

image

PS: \begin{booktabs}{<inner-styles>} is equivalent to \begin{tblr}{rowsep=0pt, <inner-styles>} https://github.com/lvjr/tabularray/blob/690e67ee175ff7601d0144c84f9a7e9c67573e0b/tabularray.sty#L7125-L7128 PS 2: You can also have a look at tabularray's talltblr (\begin{tblr}[tall]{...}) and talltabs \begin{tblr}[tall]{rowsep=0pt, ...} tabular environments, which have header and footer components, hence can typeset a caption by themselves. But then you need to learn another way to "mimic \abovetopsep" and default behaviors in standard classes. See package manual, chap 4 "Use Long Tables" for more info.

celdorwow commented 9 months ago

First of all, thank you very much for all the help and the examples on possible solutions. I do realise it takes significant time to put so many details together.

I mentioned circumstances when no caption package is available, although I see this is supposed to be the approach to format captions. I also missed \belowbottomsep, the counterpart of \abovetopsep from booktabs--thanks for pointing this out :)

I would also like to clarify what I read:

\begin{booktabs}{<inner-styles>} is equivalent to \begin{tblr}{rowsep=0pt, <inner-styles>}

I must have missed something from your description. It seems changing \aboverulesep and \belowrulesep from booktabs only works in \begin{booktabs}...\end{booktabs} environment. If I use a regular tblr with rowsep=0pt, the rules do not gain spacing. Should I append something that is optional?

\documentclass{article}
\usepackage{tabularray}
\usepackage{kantlipsum}
\usepackage[skip=6pt,strut=off]{caption}

\UseTblrLibrary{booktabs}
\setlength\aboverulesep{3pt}
\setlength\belowrulesep{3pt}

\begin{document}
\kant[1][1]

\begin{table}[tbh]
  \caption{Test table}\label{tab:test}
  \centering
  \begin{tblr}{
    rowsep=0pt,
    width=\textwidth,
    colspec={@{} *3{Q[l]} @{}},
    }
    \toprule
    Column & Column & Column \\
    \midrule
    Test & Test & Test \\
    Test & Test & Test \\
    Test & Test & Test \\
    Test & Test & Test \\
    \bottomrule
  \end{tblr}
\end{table}

\begin{table}[tbh]
  \caption{Test table}\label{tab:test}
  \centering
  \begin{booktabs}{
    width=\textwidth,
    colspec={@{} *3{Q[l]} @{}},
    }
    \toprule
    Column & Column & Column \\
    \midrule
    Test & Test & Test \\
    Test & Test & Test \\
    Test & Test & Test \\
    Test & Test & Test \\
    \bottomrule
  \end{booktabs}
\end{table}

\kant[1][2-3]
\end{document}

Screenshot from 2023-09-19 12-08-38

As to talltblr, I did not really think of it. However, I find the manual section on longtblr/talltblr somehow confusing. I did read and try to digest the details, then understand all mechanics regarding styles etc. I think I understand a generic concept but then I usually seem to end up doing things not quite right, making a mess with style application, etc. All that most of times involves a lot of attempts by try-and-error, rarely searching for an ad-hoc solution on TeX.SE. I can arrive at the solution I want but I'd rather avoid talltblr if I don't need it.

Regardless the last critique :), I would still like to emphasise I am very grateful for the package. tblr is relatively easy to get and it's been life-saving on many occasions. Very appreciated :)

Thanks

muzimuzhi commented 9 months ago

It seems changing \aboverulesep and \belowrulesep from booktabs only works in \begin{booktabs}...\end{booktabs} environment.

You're right. \begin{booktabs}{<inner-styles>} is more than \begin{tblr}{rowsep=0pt, <inner-styles>}. After (re)checking implementation of booktabs library, I find that

celdorwow commented 9 months ago

Thanks again :) It is very helpful.

I am closing this topic. It is probably no longer an issue and it has been exhausted.