lvjr / tabularray

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

Allow U-Z row selectors in cell span arguments #417

Open philippewarren opened 12 months ago

philippewarren commented 12 months ago

Allowing U-Z special values as row selectors for cell span would be useful when you have a cell that sould expand when new rows are added to the table.

muzimuzhi commented 11 months ago

An attempt that adds two new span options to row=<selector> and to col=<selector>.

For a 4x5 tabular, the three (inner style) settings below are equivalent to each other:

Full example

```tex \documentclass[twocolumn]{article} \usepackage{tabularray} \usepackage{xcolor} \makeatletter \ExplSyntaxOn % can be replaced by two temp tl args % (I'm not familiar enough with tabularray implementation.) \tl_new:N \l__tblr_span_to_row_tl \tl_new:N \l__tblr_span_to_col_tl \keys_define:nn { tblr-cell-span } { % both are inclusive to~row .code:n = { \group_begin: \tl_set:Nx \l_tblr_childs_total_tl { \int_use:N \c@rowcount } \__tblr_child_name_to_index:nN {#1} \l__tblr_span_to_row_tl \use:e { \group_end: \int_compare:nNnF {\l__tblr_span_to_row_tl} < {\c@rownum} { \tl_set:Nn \exp_not:N \l__tblr_row_span_num_tl { \int_eval:n { \l__tblr_span_to_row_tl - \c@rownum + 1 } } } } }, to~col .code:n = { % is it safe to alter \l_tblr_childs_total_tl directly (not without an extra group)? \group_begin: \tl_set:Nx \l_tblr_childs_total_tl { \int_use:N \c@colcount } \__tblr_child_name_to_index:nN {#1} \l__tblr_span_to_col_tl \use:e { \group_end: \int_compare:nNnF {\l__tblr_span_to_col_tl} < {\c@colnum} { \tl_set:Nn \exp_not:N \l__tblr_col_span_num_tl { \int_eval:n { \l__tblr_span_to_col_tl - \c@colnum + 1 } } } } } } \ExplSyntaxOff \makeatother \SetTblrInner{ cells={preto={(\therownum, \thecolnum)}}, hline{1,Z}, vline{1,Z}, baseline=T } \begin{document} \newcommand\testSpan[3]{ \noindent\texttt{\detokenize{cell#1={#2}{...}}}\par \begin{tblr}{ cell#1={#2}{m,c,font=\large\bfseries} } #3 \end{tblr} \par\medskip } \testSpan{{2}{2}}{r=2, c=3} {& & & & \\ \\ \\ \\} % size is 4x5 \testSpan{{2}{2}}{to row=3, to col=4}{& & & & \\ \\ \\ \\} \testSpan{{2}{2}}{to row=Y, to col=Y}{& & & & \\ \\ \\ \\} \testSpan{{2}{2}}{to row=Y, to col=Y}{& & & & & \\ \\ \\ \\ \\} % 5x6 \newpage % degenerated cases \testSpan{{2}{3}}{to row=Z, to col=Z}{& & & \\ \\ \\} % 3x4 \testSpan{{2}{3}}{to row=Z, to col=Z}{& & \\ \\ \\} % 3x3 \testSpan{{2}{3}}{to row=Z, to col=Z}{& & & \\ \\} % 2x4 \testSpan{{2}{3}}{to row=Z, to col=Z}{& & \\ \\} % 2x3 \end{document} ```

image

Another option is to provide a new inner option span{<row range>}{<col range>}={<styles>}.

lvjr commented 11 months ago

If multiple-word key names are needed, I would prefer to use dash characters instead of space characters in the names (like nicematrix and siunitx).

philippewarren commented 11 months ago

Let me clarify: I was thinking about cell spans in the \SetCell command.

muzimuzhi commented 11 months ago

From its syntax\SetCell[<span>]{<styles>}, \SetCell[to row=<selector>, to col=<selector>]{<styles>} (or the to-row=..., to-col=... form) is supported in my (first) attempt in https://github.com/lvjr/tabularray/issues/417#issuecomment-1627829786.

philippewarren commented 11 months ago

From its syntax\SetCell[<span>]{<styles>}, \SetCell[to row=<selector>, to col=<selector>]{<styles>} (or the to-row=..., to-col=... form) is supported in my (first) attempt in #417 (comment).

Great! It was just to be sure since you were using a different syntax in your examples.

lvjr commented 11 months ago

I think there is no need to add to-row and to-col keys, because it is just a simple application of future keyvalue library (see https://github.com/lvjr/tabularray/issues/270).