lvjr / tabularray

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

Interaction between different row/column types #411

Open muzimuzhi opened 1 year ago

muzimuzhi commented 1 year ago

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

```tex \documentclass{article} \usepackage{tabularray} \SetTblrInner{hlines, vlines, columns={co=1}} \def\testTblrColspec#1{ \hspace*{-2em}\texttt{\UseName{tl_if_empty:nTF}{#1}{}{#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](https://github.com/lvjr/tabularray/assets/6376638/ad350bf9-2d54-432d-82de-2f3c9ea25453)

lvjr commented 1 year ago

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 commented 1 year ago

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.

muzimuzhi commented 1 year ago

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.