tabularray icon indicating copy to clipboard operation
tabularray copied to clipboard

Replace stretch with row heights for perfect vertical centering

Open lvjr opened this issue 3 years ago • 1 comments

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:

  1. It changes the styles of tables by adding (invisible) contents to it, which is a little weird and confuses many users.

  2. It adds extra vertical space around lists in cells (see issue #99).

  3. 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}

image

lvjr avatar Feb 03 '22 01:02 lvjr

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.

marvlg avatar Feb 12 '22 07:02 marvlg

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.

lvjr avatar Aug 22 '22 07:08 lvjr