tabularray
tabularray copied to clipboard
Replace stretch with row heights for perfect vertical centering
The stretch
option of tabularray
is an analogue of \arraystretch
parameter of tabular
environment. It gives every row a minimal height by adding struts to it. This option has several disavantages:
-
It changes the styles of tables by adding (invisible) contents to it, which is a little weird and confuses many users.
-
It adds extra vertical space around lists in cells (see issue #99).
-
It breaks vertical centering for cell text in a row (see the example below).
Now that it is easy to set minimal height for a row with ht
key in tabularray
, I am considering to change default setting from stretch=1
to rows = {ht=\baselineskip}
for tabularray
tables. The following example shows that it makes perfect output.
\documentclass[12pt]{article}
\usepackage{array}
\usepackage{tabularray}
\SetTblrInner{rowsep=0pt}
\begin{document}
\noindent
\textbf{tabular(now)}\hfill\hfill
\textbf{tabularray(now)}\hfill
\textbf{tabularray(future)}
\noindent
\begin{tabular}{|l|l|l|}
\hline
2021 & 2022 & 2023 \\
\hline
come & ace & moose \\
\hline
pop & yes & goose \\
\hline
\end{tabular}
\hfill
\begin{tblr}{|l|l|l|}
\hline
2021 & 2022 & 2023 \\
\hline
come & ace & moose \\
\hline
pop & yes & goose \\
\hline
\end{tblr}
\hfill
\begin{tblr}{
colspec=|l|l|l|,
stretch = 0,
rows = {ht=\baselineskip}
}
\hline
2021 & 2022 & 2023 \\
\hline
come & ace & moose \\
\hline
pop & yes & goose \\
\hline
\end{tblr}
\end{document}
Not so sure about this one. To me, the last row looks worse in the future version, because of the large depth of the characters. However, esspecially the first row with the years looks much better.
I can't really tell if \arraystretch
is just outdated or if there was some specific reason to implement it as is. Maybe it is worth looking in to that.
From a comment in #265, we can see rows = {ht=\baselineskip}
makes bad cells with multiple lines. So I decide not to make the change.