diff --git a/manual/manual-3.tex b/manual/manual-3.tex index 2044b53..dc7be7a 100644 --- a/manual/manual-3.tex +++ b/manual/manual-3.tex @@ -46,6 +46,7 @@ \section{Inner specifications} \K{leftsep} & set horizontal space to the left of every column & \V{6pt} \\ \K{rightsep} & set horizontal space to the right of every column & \V{6pt} \\ \K{colsep} & set horizontal space to both sides of every column & \V{6pt} \\ + \K{spread} & extendable column spread algorithm: \V{default}, \V{coeff}, or \V{none} & \V{default} \\ \K{hspan} & horizontal span algorithm: \V{default}, \V{even}, or \V{minimal} & \V{default} \\ \K{vspan} & vertical span algorithm: \V{default} or \V{even} & \V{default} \\ %\K{verb} & you need this key to use verb commands & \None \\ @@ -166,6 +167,48 @@ \subsection{Hspan and vspan algorithms} \end{tblr} \end{demohigh} +\subsection{Spread algorithms for extendable columns} + +The algorithm specified by the \K{spread} key applies only +if all of the following are true: +\begin{itemize} + \item There is at least one extendable column (\V{X} column). + \item All extendable columns have negative coefficients. + \item The total natural width of \emph{all} columns + (including column separations and vlines) is less than the specified + width of the table (or \CC{\linewidth} if no \K{width} is specified). +\end{itemize} + +With \KV{spread=default}, the remaining width is distributed +among the extendable columns according to their natural widths: +\begin{demohigh} +\SetTblrInner{hlines, vlines, spread=default} +\begin{tblr}{colspec={*{3}{X[-1]}}} + Short & Medium-sized & Long extendable column test 123 +\end{tblr} +\end{demohigh} + +With \KV{spread=coeff}, the remaining width is distributed +among the extendable columns according to their coefficients: +\begin{demohigh} +\SetTblrInner{hlines, vlines, spread=coeff} +\begin{tblr}{colspec={*{3}{X[-1]}}} + Short & Medium-sized & Long extendable column test 123 +\end{tblr} +\begin{tblr}{colspec={X[-1]X[-1]X[-2]}} + Short & Medium-sized & Long extendable column test 123 +\end{tblr} +\end{demohigh} + +With \KV{spread=none}, the width of the table is reduced +to match the natural column widths: +\begin{demohigh} +\SetTblrInner{hlines, vlines, spread=none} +\begin{tblr}{colspec={*{3}{X[-1]}}} + Short & Medium-sized & Long extendable column test 123 +\end{tblr} +\end{demohigh} + \subsection{Set baseline for the table} With \K{baseline} key, you can set baseline for the table. diff --git a/tabularray.sty b/tabularray.sty index 41c2854..ad5094f 100644 --- a/tabularray.sty +++ b/tabularray.sty @@ -4005,6 +4005,7 @@ hspan .code:n = \__tblr_keys_gput:nn { hspan } {#1}, vspan .code:n = \__tblr_keys_gput:nn { vspan } {#1}, stretch .code:n = \__tblr_keys_gput:nn { stretch } {#1}, + spread .code:n = \__tblr_keys_gput:nn { spread } {#1}, columns .code:n = \__tblr_set_every_column_aux:n {#1}, rows .code:n = \__tblr_set_every_row_aux:n {#1}, cells .code:n = \__tblr_set_every_cell_aux:n {#1}, @@ -4969,6 +4970,7 @@ \dim_new:N \l__tblr_column_target_dim \prop_new:N \l__tblr_column_coefficient_prop +\prop_new:N \l__tblr_column_n_coefficient_prop \prop_new:N \l__tblr_column_natural_width_prop \prop_new:N \l__tblr_column_computed_width_prop @@ -4999,6 +5001,7 @@ { \dim_set_eq:NN \l__tblr_column_target_dim \linewidth } { \dim_set:Nn \l__tblr_column_target_dim { \l_tmpa_tl } } \prop_clear:N \l__tblr_column_coefficient_prop + \prop_clear:N \l__tblr_column_n_coefficient_prop \prop_clear:N \l__tblr_column_natural_width_prop \prop_clear:N \l__tblr_column_computed_width_prop \int_step_variable:nNn { \c@colcount } \l__tblr_j_tl @@ -5061,7 +5064,12 @@ { \dim_compare_p:nNn { \l__tblr_column_target_dim } > { \l__tblr_hfuzz_dim } } { \prop_if_empty:NTF \l__tblr_column_coefficient_prop - { \__tblr_adjust_extendable_column_width_negative: } + { + \str_if_eq:enTF + { \__tblr_prop_item:ne { inner } { spread } } { none } + { \dim_zero:N \l__tblr_column_target_dim } + { \__tblr_adjust_extendable_column_width_negative: } + } { \__tblr_adjust_extendable_column_width_once: } } \prop_map_inline:Nn \l__tblr_column_computed_width_prop @@ -5112,6 +5120,7 @@ \dim_add:Nn \l__tblr_column_target_dim { \l__tblr_a_tl + \l__tblr_c_tl - \l__tblr_b_tl } \prop_remove:Nn \l__tblr_column_coefficient_prop { ##1 } + \prop_put:Nne \l__tblr_column_n_coefficient_prop { ##1 } { ##2 } } { \__tblr_add_dimen_value:Nnn @@ -5123,6 +5132,15 @@ } \cs_new_protected:Npn \__tblr_adjust_extendable_column_width_negative: + { + \str_if_eq:enTF + { \__tblr_prop_item:ne { inner } { spread } } { coeff } + { \__tblr_adjust_extendable_column_width_coeff: } + { \__tblr_adjust_extendable_column_width_natural: } + \LogTblrTracing { target } + } + +\cs_new_protected:Npn \__tblr_adjust_extendable_column_width_natural: { \dim_zero:N \l_tmpa_dim \prop_map_inline:Nn \l__tblr_column_natural_width_prop @@ -5136,7 +5154,25 @@ \__tblr_add_dimen_value:Nnn \l__tblr_column_computed_width_prop { ##1 } { \l_tmpb_tl } } - \LogTblrTracing { target } + } + +\cs_new_protected:Npn \__tblr_adjust_extendable_column_width_coeff: + { + \dim_zero:N \l_tmpa_dim + \prop_map_inline:Nn \l__tblr_column_n_coefficient_prop + { + \dim_add:Nn \l_tmpa_dim { \dim_abs:n { ##2 pt } } + } + \tl_set:Ne \l__tblr_w_tl + { \dim_ratio:nn { \l__tblr_column_target_dim } { \l_tmpa_dim } } + \dim_zero:N \l__tblr_column_target_dim + \prop_map_inline:Nn \l__tblr_column_n_coefficient_prop + { + \tl_set:Ne \l__tblr_a_tl + { \dim_eval:n { \dim_abs:n { ##2 pt } * \l__tblr_w_tl } } + \__tblr_add_dimen_value:Nnn + \l__tblr_column_computed_width_prop { ##1 } { \l__tblr_a_tl } + } } %%% -------------------------------------------------------- diff --git a/tabularray.tex b/tabularray.tex index e5aa9d4..94bb1a2 100644 --- a/tabularray.tex +++ b/tabularray.tex @@ -1440,6 +1440,7 @@ \section{Inner specifications} \K{leftsep} & set horizontal space to the left of every column & \V{6pt} \\ \K{rightsep} & set horizontal space to the right of every column & \V{6pt} \\ \K{colsep} & set horizontal space to both sides of every column & \V{6pt} \\ + \K{spread} & extendable column spread algorithm: \V{default}, \V{coeff}, or \V{none} & \V{default} \\ \K{hspan} & horizontal span algorithm: \V{default}, \V{even}, or \V{minimal} & \V{default} \\ \K{vspan} & vertical span algorithm: \V{default} or \V{even} & \V{default} \\ %\K{verb} & you need this key to use verb commands & \None \\ @@ -1560,6 +1561,48 @@ \subsection{Hspan and vspan algorithms} \end{tblr} \end{demohigh} +\subsection{Spread algorithms for extendable columns} + +The algorithm specified by the \K{spread} key applies only +if all of the following are true: +\begin{itemize} + \item There is at least one extendable column (\V{X} column). + \item All extendable columns have negative coefficients. + \item The total natural width of \emph{all} columns + (including column separations and vlines) is less than the specified + width of the table (or \CC{\linewidth} if no \K{width} is specified). +\end{itemize} + +With \KV{spread=default}, the remaining width is distributed +among the extendable columns according to their natural widths: +\begin{demohigh} +\SetTblrInner{hlines, vlines, spread=default} +\begin{tblr}{colspec={*{3}{X[-1]}}} + Short & Medium-sized & Long extendable column test 123 +\end{tblr} +\end{demohigh} + +With \KV{spread=coeff}, the remaining width is distributed +among the extendable columns according to their coefficients: +\begin{demohigh} +\SetTblrInner{hlines, vlines, spread=coeff} +\begin{tblr}{colspec={*{3}{X[-1]}}} + Short & Medium-sized & Long extendable column test 123 +\end{tblr} +\begin{tblr}{colspec={X[-1]X[-1]X[-2]}} + Short & Medium-sized & Long extendable column test 123 +\end{tblr} +\end{demohigh} + +With \KV{spread=none}, the width of the table is reduced +to match the natural column widths: +\begin{demohigh} +\SetTblrInner{hlines, vlines, spread=none} +\begin{tblr}{colspec={*{3}{X[-1]}}} + Short & Medium-sized & Long extendable column test 123 +\end{tblr} +\end{demohigh} + \subsection{Set baseline for the table} With \K{baseline} key, you can set baseline for the table.