tabularray icon indicating copy to clipboard operation
tabularray copied to clipboard

Interaction between different row/column types

Open muzimuzhi opened this issue 2 years ago • 3 comments

The problem of how different row/column types should interact with each other is raised, for example when columns is set by \SetTblrInner and colspec fed to tblr environment. See https://tex.stackexchange.com/q/686262 and also #408.

Quoting my own tex-sx answer,

Unfortunately, because column types like l and c only set halign (to l and c, respectively) and don't reset co to its initial value 0 (which is altered by previous columns={co=1}), after setting columns={co=1}, a table with colspec={|l|X[r]|c|} will work like

colspec={|Q[l,co=1]|Q[r,co=1]|Q[c,co=1]|}

while what user may expect is

colspec={|Q[l,co=0]|Q[r,co=1]|Q[c,co=0]|}

If it's by design that column types changing horizontal alignment (l, c, r, and j) and the type changing column coefficient (X) function orthogonally, then I think at least those h-align columns types could take an optional argument as well.

https://github.com/lvjr/tabularray/blob/690e67ee175ff7601d0144c84f9a7e9c67573e0b/tabularray.sty#L2518-L2521 https://github.com/lvjr/tabularray/blob/690e67ee175ff7601d0144c84f9a7e9c67573e0b/tabularray.sty#L2537

Example, simplified from my tex-sx answer

\documentclass{article}
\usepackage{tabularray}

\SetTblrInner{hlines, vlines, columns={co=1}}

\def\testTblrColspec#1{
  \hspace*{-2em}\texttt{\UseName{tl_if_empty:nTF}{#1}{<empty>}{#1}}
  \par\medskip
  \begin{tblr}{#1}
   Head1 & Head2 & Head3\\
   Row21 & Row22 & Row23 \\
   Row31 & Row32 & Row33 \\
   Row41 & Row42 & Row43 \\
  \end{tblr}
  \par\medskip
}

\setlength{\parindent}{0mm}

\begin{document}
\testTblrColspec{}
\testTblrColspec{colspec={l X[r] c}}
\testTblrColspec{colspec={Q[l,co=0] X[r] Q[c,co=0]}}
\end{document}

image

muzimuzhi avatar Jun 02 '23 23:06 muzimuzhi

I think this is not a strong reason for making a breaking change. Any user can define a new L/C/R column type which takes an optional argument.

lvjr avatar Jun 05 '23 02:06 lvjr

The most important thing is how to clear existing values of keys in tabularray:

https://github.com/lvjr/tabularray/wiki/KeyValue

But I haven't checked all the keys yet.

lvjr avatar Jun 05 '23 02:06 lvjr

Providing an init-like meta key for each key-val module?

Edit: Ah I got your point about "clearing existing values of keys in tabularray". It either needs to adjust the initial value to a normal value user could pass on, or handler a special value (like none or empty value).

BTW I think it's more like an extension, rather than breaking change. It will turn currently invalid input like c[co=0] to valid.

muzimuzhi avatar Jun 05 '23 04:06 muzimuzhi