summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tabularray
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-10-02 03:03:32 +0000
committerNorbert Preining <norbert@preining.info>2021-10-02 03:03:32 +0000
commitac5a96ddb02c62d71eb214ed35e3be9a154d991f (patch)
treecdf35312568ce6b2b69e7374745ddafdd3e3c66b /macros/latex/contrib/tabularray
parent569e4d488d3398f8ed12807dd67e2b301b7447d5 (diff)
CTAN sync 202110020303
Diffstat (limited to 'macros/latex/contrib/tabularray')
-rw-r--r--macros/latex/contrib/tabularray/tabularray.pdfbin725112 -> 760493 bytes
-rw-r--r--macros/latex/contrib/tabularray/tabularray.sty247
-rw-r--r--macros/latex/contrib/tabularray/tabularray.tex204
3 files changed, 352 insertions, 99 deletions
diff --git a/macros/latex/contrib/tabularray/tabularray.pdf b/macros/latex/contrib/tabularray/tabularray.pdf
index 198b6fd211..450375620e 100644
--- a/macros/latex/contrib/tabularray/tabularray.pdf
+++ b/macros/latex/contrib/tabularray/tabularray.pdf
Binary files differ
diff --git a/macros/latex/contrib/tabularray/tabularray.sty b/macros/latex/contrib/tabularray/tabularray.sty
index 2e3fa4eb5d..db63c63a3c 100644
--- a/macros/latex/contrib/tabularray/tabularray.sty
+++ b/macros/latex/contrib/tabularray/tabularray.sty
@@ -12,7 +12,7 @@
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}
-\ProvidesExplPackage{tabularray}{2021-09-01}{2021N}
+\ProvidesExplPackage{tabularray}{2021-10-01}{2021P}
{Typeset tabulars and arrays with LaTeX3}
\RequirePackage{xparse}
@@ -52,6 +52,7 @@
\cs_generate_variant:Nn \tl_const:Nn { ce }
\cs_generate_variant:Nn \tl_log:n { x }
\cs_generate_variant:Nn \tl_gput_right:Nn { Nf }
+\cs_generate_variant:Nn \tl_put_left:Nn { Nv }
\prg_generate_conditional_variant:Nnn \clist_if_in:Nn { Nx } { TF }
\prg_generate_conditional_variant:Nnn \prop_if_in:Nn { c } { T }
\prg_generate_conditional_variant:Nnn \str_if_eq:nn { xn } { TF }
@@ -105,11 +106,13 @@
\cs_new_eq:NN \__tblr_halign_command_c: \centering
\cs_new_eq:NN \__tblr_halign_command_r: \raggedleft
-%% Some counters for row and column numbering
-\newcounter{rownum}
-\newcounter{colnum}
-\newcounter{rowcount}
-\newcounter{colcount}
+%% Some counters for row and column numbering.
+%% We may need to restore all LaTeX counters in measuring and building cells,
+%% so we must not define these counters with \newcounter command.
+\int_new:N \c@rownum
+\int_new:N \c@colnum
+\int_new:N \c@rowcount
+\int_new:N \c@colcount
%% Some dimensions for row and column spacing
\dim_new:N \abovesep
@@ -369,7 +372,10 @@
\__tblr_data_new_key:nnn { cell } { halign } { str }
\__tblr_data_new_key:nnn { cell } { valign } { str }
\__tblr_data_new_key:nnn { cell } { background } { str }
+\__tblr_data_new_key:nnn { cell } { foreground } { str }
\__tblr_data_new_key:nnn { cell } { font } { str }
+\__tblr_data_new_key:nnn { cell } { mode } { str }
+\__tblr_data_new_key:nnn { cell } { cmd } { str }
\__tblr_data_new_key:nnn { cell } { omit } { int }
\__tblr_data_new_key:nnn { cell } { @cell-width } { dim }
\__tblr_data_new_key:nnn { cell } { @cell-height } { dim }
@@ -1634,11 +1640,14 @@
f .meta:n = { valign = f },
wd .code:n = \__tblr_cell_gput:ne { width } {#1},
bg .code:n = \__tblr_cell_gput:ne { background } {#1},
+ fg .code:n = \__tblr_cell_gput:ne { foreground } {#1},
+ font .code:n = \__tblr_cell_gput:nn { font } { #1 \selectfont },
+ mode .code:n = \__tblr_cell_gput:nn { mode } {#1},
+ $ .meta:n = { mode = math },
+ $$ .meta:n = { mode = dmath },
+ cmd .code:n = \__tblr_cell_gput:nn { cmd } {#1},
preto .code:n = \__tblr_cell_preto_text:n {#1},
appto .code:n = \__tblr_cell_appto_text:n {#1},
- cmd .code:n = \__tblr_cell_process_text:n {#1},
- fg .code:n = \__tblr_cell_preto_text:n { \color{#1} },
- font .code:n = \__tblr_cell_gput:nn { font } { #1 \selectfont },
unknown .code:n = \__tblr_cell_unknown_key:V \l_keys_key_str,
}
@@ -1686,23 +1695,6 @@
}
\cs_generate_variant:Nn \__tblr_cell_appto_text:nnn { nen, enn, een }
-\cs_new_protected:Npn \__tblr_cell_process_text:n #1
- {
- \__tblr_cell_process_text:een
- { \int_use:N \c@rownum } { \int_use:N \c@colnum } {#1}
- }
-
-\cs_new_protected:Npn \__tblr_cell_process_text:nnn #1 #2 #3
- {
- \tl_set:Nx \l__tblr_cell_text_tl
- {
- { \__tblr_spec_item:nn { text } { [#1][#2] } }
- }
- \tl_put_left:Nn \l__tblr_cell_text_tl {#3}
- \__tblr_spec_gput:nnV { text } { [#1][#2] } \l__tblr_cell_text_tl
- }
-\cs_generate_variant:Nn \__tblr_cell_process_text:nnn { nen, enn, een }
-
\cs_new_protected:Npn \__tblr_cell_unknown_key:n #1
{
\regex_match:NnTF \c__tblr_is_color_key_regex {#1}
@@ -1911,13 +1903,16 @@
h .meta:n = { valign = h },
f .meta:n = { valign = f },
bg .code:n = \__tblr_column_gput_cell:nn { background } {#1},
- fg .code:n = \__tblr_preto_text_for_every_column_cell:n { \color{#1} },
+ fg .code:n = \__tblr_column_gput_cell:nn { foreground } {#1},
font .code:n = \__tblr_column_gput_cell:nn { font } { #1 \selectfont },
+ mode .code:n = \__tblr_column_gput_cell:nn { mode } {#1},
+ $ .meta:n = { mode = math },
+ $$ .meta:n = { mode = dmath },
+ cmd .code:n = \__tblr_column_gput_cell:nn { cmd } {#1},
wd .code:n = \__tblr_column_gput:ne { width } { \dim_eval:n {#1} },
co .code:n = \__tblr_column_gput:ne { coefficient } {#1},
preto .code:n = \__tblr_preto_text_for_every_column_cell:n {#1},
appto .code:n = \__tblr_appto_text_for_every_column_cell:n {#1},
- cmd .code:n = \__tblr_process_text_for_every_column_cell:n {#1},
leftsep .code:n = \__tblr_column_gput:ne { leftsep } { \dim_eval:n {#1} },
rightsep .code:n = \__tblr_column_gput:ne { rightsep } { \dim_eval:n {#1} },
colsep .meta:n = { leftsep = #1, rightsep = #1},
@@ -1969,14 +1964,6 @@
}
}
-\cs_new_protected:Npn \__tblr_process_text_for_every_column_cell:n #1
- {
- \int_step_inline:nn { \c@rowcount }
- {
- \__tblr_cell_process_text:nen {##1} { \int_use:N \c@colnum } {#1}
- }
- }
-
\regex_const:Nn \c__tblr_is_number_key_regex { ^[\+\-]? (\d+|\d*\.\d+)$ }
\cs_new_protected:Npn \__tblr_column_unknown_key:n #1
@@ -2071,13 +2058,16 @@
h .meta:n = { valign = h },
f .meta:n = { valign = f },
bg .code:n = \__tblr_row_gput_cell:nn { background } {#1},
- fg .code:n = \__tblr_preto_text_for_every_row_cell:n { \color{#1} },
+ fg .code:n = \__tblr_row_gput_cell:nn { foreground } {#1},
font .code:n = \__tblr_row_gput_cell:nn { font } { #1 \selectfont },
+ mode .code:n = \__tblr_row_gput_cell:nn { mode } {#1},
+ $ .meta:n = { mode = math },
+ $$ .meta:n = { mode = dmath },
+ cmd .code:n = \__tblr_row_gput_cell:nn { cmd } {#1},
ht .code:n = \__tblr_row_gput:ne { height } { \dim_eval:n {#1} },
co .code:n = \__tblr_row_gput:ne { coefficient } {#1},
preto .code:n = \__tblr_preto_text_for_every_row_cell:n {#1},
appto .code:n = \__tblr_appto_text_for_every_row_cell:n {#1},
- cmd .code:n = \__tblr_process_text_for_every_row_cell:n {#1},
abovesep .code:n = \__tblr_row_gput:ne { abovesep } { \dim_eval:n {#1} },
belowsep .code:n = \__tblr_row_gput:ne { belowsep } { \dim_eval:n {#1} },
rowsep .meta:n = { abovesep = #1, belowsep = #1},
@@ -2142,14 +2132,6 @@
}
}
-\cs_new_protected:Npn \__tblr_process_text_for_every_row_cell:n #1
- {
- \int_step_inline:nn { \c@colcount }
- {
- \__tblr_cell_process_text:enn { \int_use:N \c@rownum } {##1} {#1}
- }
- }
-
\cs_new_protected:Npn \__tblr_row_unknown_key:n #1
{
\regex_match:NnTF \c__tblr_is_number_key_regex {#1}
@@ -3397,7 +3379,9 @@
\cs_new_protected:Npn \__tblr_measure_cell_update_sizes:nnNNNN #1 #2 #3 #4 #5 #6
{
\__tblr_get_cell_alignments:nn {#1} {#2}
+ \__tblr_save_counters:n { trial }
\hbox_set:Nn \l_tmpa_box { \__tblr_get_cell_text:nn {#1} {#2} }
+ \__tblr_restore_counters:n { trial }
\__tblr_update_cell_size:nnNNNN {#1} {#2} #3 #4 #5 #6
\__tblr_update_row_size:nnNNN {#1} {#2} #4 #5 #6
\__tblr_update_col_size:nN {#2} #3
@@ -3416,13 +3400,45 @@
{ \__tblr_get_cell_text_real:nn { #1 } { #2 } }
}
+\tl_new:N \l__tblr_cell_fg_tl
+\tl_new:N \l__tblr_cell_cmd_tl
+\tl_new:N \l__tblr_cell_mode_tl
+\bool_new:N \l__tblr_cell_math_mode_bool
+\tl_const:Nn \l__tblr_cell_math_style_tl { \relax }
+\tl_const:Nn \l__tblr_cell_imath_style_tl { \textstyle }
+\tl_const:Nn \l__tblr_cell_dmath_style_tl { \displaystyle }
+
%% Get cell text, #1: row number, #2: column number
%% If the width of the cell is not set, split it with \\ and compute the width
%% Therefore we always get a vbox for any cell
\cs_new_protected:Npn \__tblr_get_cell_text_real:nn #1 #2
{
\group_begin:
- \tl_set:Nx \l__tblr_c_tl { \__tblr_spec_item:ne { text } {[#1][#2]} }
+ \tl_set:Nx \l__tblr_cell_cmd_tl
+ { \__tblr_data_item:neen { cell } {#1} {#2} { cmd } }
+ \tl_if_empty:NTF \l__tblr_cell_cmd_tl
+ { \tl_set:Nx \l__tblr_c_tl { \__tblr_spec_item:ne { text } {[#1][#2]} } }
+ {
+ \tl_set:Nx \l__tblr_c_tl { { \__tblr_spec_item:ne { text } {[#1][#2]} } }
+ \tl_put_left:NV \l__tblr_c_tl \l__tblr_cell_cmd_tl
+ }
+ \tl_set:Nx \l__tblr_cell_mode_tl
+ { \__tblr_data_item:neen { cell } {#1} {#2} { mode } }
+ \tl_if_empty:NT \l__tblr_cell_mode_tl
+ {
+ \bool_if:NTF \l__tblr_math_mode_bool
+ { \tl_set:Nn \l__tblr_cell_mode_tl { math } }
+ { \tl_set:Nn \l__tblr_cell_mode_tl { text } }
+ }
+ \tl_if_eq:NnTF \l__tblr_cell_mode_tl { text }
+ { \bool_set_false:N \l__tblr_cell_math_mode_bool }
+ {
+ \bool_set_true:N \l__tblr_cell_math_mode_bool
+ \tl_put_left:Nv \l__tblr_c_tl
+ { l__tblr_cell_ \l__tblr_cell_mode_tl _style_tl }
+ \tl_put_left:Nn \l__tblr_c_tl { $ }
+ \tl_put_right:Nn \l__tblr_c_tl { $ }
+ }
\tl_set:Nx \l__tblr_f_tl { \__tblr_data_item:neen { cell } {#1} {#2} { font } }
\tl_set:Nx \l__tblr_w_tl
{ \__tblr_data_item:neen { cell } {#1} {#2} { width } }
@@ -3437,15 +3453,17 @@
}
\dim_compare:nNnT { \l__tblr_w_tl } < { 0pt } % column width unset
{
- \bool_if:NTF \l__tblr_math_mode_bool
+ \bool_if:NTF \l__tblr_cell_math_mode_bool
{
- \hbox_set:Nn \l_tmpa_box { $\l__tblr_c_tl$ }
+ \hbox_set:Nn \l_tmpa_box { \l__tblr_c_tl }
\tl_set:Nx \l__tblr_w_tl { \box_wd:N \l_tmpa_box }
}
{
\__tblr_get_cell_size_with_box:
}
}
+ \tl_set:Nx \l__tblr_cell_fg_tl
+ { \__tblr_data_item:neen { cell } {#1} {#2} { foreground } }
\tl_put_left:NV \l__tblr_c_tl \l__tblr_f_tl
\__tblr_get_vcell_and_sizes:NN \l__tblr_c_tl \l__tblr_w_tl
\group_end:
@@ -3453,9 +3471,11 @@
\cs_new_protected:Npn \__tblr_get_cell_size_with_box:
{
+ \__tblr_save_counters:n { cell }
\tl_if_eq:NnTF \l__tblr_inner_spec_measure_tl { vbox }
{ \__tblr_get_cell_size_with_vbox: }
{ \__tblr_get_cell_size_with_hbox: }
+ \__tblr_restore_counters:n { cell }
}
%% Varwidth won't work as expected when \color command occurs in it,
@@ -3503,7 +3523,9 @@
\cs_new_protected:Npn \__tblr_get_vcell_and_sizes:NN #1 #2
{
\group_begin:
+ \__tblr_save_counters:n { cell }
\vbox_set_top:Nn \l_tmpa_box { \__tblr_make_vcell_text:NN #1 #2 }
+ \__tblr_restore_counters:n { cell }
\vbox_set:Nn \l_tmpb_box { \__tblr_make_vcell_text:NN #1 #2 }
\dim_gset:Nn \g__tblr_cell_wd_dim { \box_wd:N \l_tmpb_box }
\dim_gset:Nn \g__tblr_cell_ht_dim
@@ -3555,8 +3577,9 @@
\cs:w __tblr_halign_command_ \g__tblr_cell_halign_tl : \cs_end:
\mode_leave_vertical:
\box_use:N \l__tblr_strut_ht_box
- \bool_if:NTF \l__tblr_math_mode_bool
- { $#1$ }
+ \tl_if_empty:NF \l__tblr_cell_fg_tl { \exp_args:NV \color \l__tblr_cell_fg_tl }
+ \bool_if:NTF \l__tblr_cell_math_mode_bool
+ { #1 }
{ \__tblr_rescan_cell_tokens:N #1 }
\box_use:N \l__tblr_strut_dp_box
}
@@ -3571,6 +3594,8 @@
\tl_if_empty:NTF \l__tblr_inner_spec_verb_tl
{ #1 }
{
+ %% insert space characters after some control sequences first (issue #112)
+ \regex_replace_all:nnN { (\c{[A-Za-z]*}) ([A-Za-z]) } { \1 \ \2 } #1
\regex_replace_all:nnN { . } { \c{string} \0 } #1
\tl_set:Nx #1 { #1 \noexpand \empty }
\exp_args:NV \tex_scantokens:D #1
@@ -4644,7 +4669,7 @@
%% since we want a correct hangindent caption paragraph.
\DefTblrTemplate { caption-tag } { empty } { }
-\DefTblrTemplate { caption-tag } { normal } { Table \hspace{0.25em} \thetable }
+\DefTblrTemplate { caption-tag } { normal } { \tablename\hspace{0.25em}\thetable }
\SetTblrTemplate { caption-tag } { normal }
\DefTblrTemplate { caption-sep } { empty } { }
@@ -5386,11 +5411,7 @@
\vbox_set:Nn \l__tblr_table_box
{
\box_use:N \l__tblr_table_head_box
- \hrule height ~ 0pt
- \box_use:N \l__tblr_row_head_box
- \hrule height ~ 0pt
- \box_use:N \l__tblr_table_box
- \hrule height ~ 0pt
+ \__tblr_cover_two_vboxes:NN \l__tblr_row_head_box \l__tblr_table_box
\box_use:N \l__tblr_row_foot_box
\hrule height ~ 0pt
\box_use:N \l__tblr_table_foot_box
@@ -5399,6 +5420,22 @@
}
\cs_generate_variant:Nn \__tblr_build_page_table:nnn { nnx }
+%% To solve the problem of missing hlines of long tables in some PDF readers,
+%% We need to draw body rows before head rows (see issue #88).
+\cs_new_protected:Npn \__tblr_cover_two_vboxes:NN #1 #2
+ {
+ \dim_set:Nn \l_tmpa_dim { \box_ht:N #1 + \box_dp:N #1 }
+ \dim_set:Nn \l_tmpb_dim { \box_ht:N #2 + \box_dp:N #2 }
+ \skip_vertical:N \l_tmpa_dim
+ \hrule height ~ 0pt
+ \box_use:N #2
+ \skip_vertical:n { - \l_tmpa_dim - \l_tmpb_dim }
+ \hrule height ~ 0pt
+ \box_use:N #1
+ \skip_vertical:N \l_tmpb_dim
+ \hrule height ~ 0pt
+ }
+
\cs_new_protected:Npn \__tblr_halign_whole:Nn #1 #2
{
\noindent
@@ -6451,6 +6488,72 @@
\clist_map_inline:nn {#1} { \use:c { __tblr_use_lib_ ##1: } }
}
+%% Library amsmath and environments +array, +matrix, +cases, ...
+
+\NewTblrLibrary { amsmath }
+ {
+ \RequirePackage { amsmath, environ }
+ \NewTblrEnviron { +array }
+ \SetTblrInner[+array]{colsep = 5pt}
+ \NewEnviron { +matrix } [1] [] {
+ \begin{+array}[expand = \BODY]{
+ column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt},
+ cells = {c}, ##1
+ }
+ \BODY
+ \end{+array}
+ }
+ \NewEnviron { +bmatrix } [1] [] {
+ \left[\begin{+array}[expand = \BODY]{
+ column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt},
+ cells = {c}, ##1
+ }
+ \BODY
+ \end{+array}\right]
+ \ignorespacesafterend
+ }
+ \NewEnviron { +Bmatrix } [1] [] {
+ \left\lbrace\begin{+array}[expand = \BODY]{
+ column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt},
+ cells = {c}, ##1
+ }
+ \BODY
+ \end{+array}\right\rbrace
+ }
+ \NewEnviron { +pmatrix } [1] [] {
+ \left(\begin{+array}[expand = \BODY]{
+ column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt},
+ cells = {c}, ##1
+ }
+ \BODY
+ \end{+array}\right)
+ }
+ \NewEnviron { +vmatrix } [1] [] {
+ \left\lvert\begin{+array}[expand = \BODY]{
+ column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt},
+ cells = {c}, ##1
+ }
+ \BODY
+ \end{+array}\right\rvert
+ }
+ \NewEnviron { +Vmatrix } [1] [] {
+ \left\lVert\begin{+array}[expand = \BODY]{
+ column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt},
+ cells = {c}, ##1
+ }
+ \BODY
+ \end{+array}\right\rVert
+ }
+ \NewEnviron { +cases } [1] [] {
+ \left\lbrace\begin{+array}[expand = \BODY]{
+ column{1} = {leftsep = 0pt}, column{Z} = {rightsep = 0pt},
+ colspec = {ll}, stretch = 1.2, ##1
+ }
+ \BODY
+ \end{+array}\right.
+ }
+ }
+
%% Library booktabs and commands \toprule, \midrule, \bottomrule
\NewTblrLibrary { booktabs }
@@ -6507,6 +6610,32 @@
{ \SetVspace { abovespace+ = (##1) / 2, belowspace+ = (##1) / 2 } }
}
+%% Library counter for resetting all counters
+
+\tl_new:N \__tblr_saved_trial_counters_tl
+\tl_new:N \__tblr_saved_cell_counters_tl
+
+\cs_new_protected:Npn \__tblr_save_counters:n #1 { }
+\cs_new_protected:Npn \__tblr_restore_counters:n #1 { }
+
+%% We use code from tabularx package for resetting all LaTeX counters,
+%% where internal macro \cl@@ckpt looks like the following:
+%% \@elt{page} \@elt{equation} \@elt{enumi} \@elt{enumii} \@elt{enumiii} ...
+
+\NewTblrLibrary { counter }
+ {
+ \cs_set_protected:Npn \__tblr_save_counters:n ##1
+ {
+ \def \@elt ####1 { \global\value{####1} = \the\value{####1} \relax }
+ \tl_set:cx { __tblr_saved_ ##1 _counters_tl } { \cl@@ckpt }
+ \let \@elt = \relax
+ }
+ \cs_set_protected:Npn \__tblr_restore_counters:n ##1
+ {
+ \tl_use:c { __tblr_saved_ ##1 _counters_tl }
+ }
+ }
+
%% Library diagbox and command \diagbox
\NewTblrLibrary { diagbox }
@@ -6538,7 +6667,7 @@
\cs_new_protected:Npn \__tblr_lib_diagbox_math_or_text:n #1
{
- \bool_if:NTF \l__tblr_math_mode_bool {$#1$} {#1}
+ \bool_if:NTF \l__tblr_cell_math_mode_bool {$#1$} {#1}
}
\box_new:N \l__tblr_diag_box
@@ -6566,7 +6695,7 @@
\cs_new_protected:Npn \__tblr_siunitx_setcolumn:n ##1
{
\__tblr_column_gput_cell:nn { si } {##1}
- \__tblr_process_text_for_every_column_cell:n { \TblrNum }
+ \__tblr_column_gput_cell:nn { cmd } { \TblrNum }
}
\NewDocumentCommand \TblrNum { m }
{
diff --git a/macros/latex/contrib/tabularray/tabularray.tex b/macros/latex/contrib/tabularray/tabularray.tex
index 0d502f3bbc..bda64717b4 100644
--- a/macros/latex/contrib/tabularray/tabularray.tex
+++ b/macros/latex/contrib/tabularray/tabularray.tex
@@ -1,6 +1,9 @@
% -*- coding: utf-8 -*-
% !TEX program = lualatex
\documentclass[oneside]{book}
+\newcommand*{\myversion}{2021P}
+\newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi}
+
\usepackage[a4paper,margin=2.5cm]{geometry}
\usepackage{codehigh} % https://ctan.org/pkg/codehigh
@@ -11,7 +14,7 @@
\usepackage[firstpage=true]{background}
\backgroundsetup{contents={}}
-\UseTblrLibrary{booktabs,diagbox,siunitx,varwidth}
+\UseTblrLibrary{amsmath,booktabs,counter,diagbox,siunitx,varwidth}
\usepackage{hyperref}
\hypersetup{
@@ -58,10 +61,7 @@
\end{tcolorbox}
}
-\renewcommand*{\thefootnote}{*}
-
-\newcommand*{\myversion}{2021N}
-\newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi}
+%\renewcommand*{\thefootnote}{*}
\colorlet{highback}{azure9}
\CodeHigh{language=latex/table,style/main=highback,style/code=highback}
@@ -353,6 +353,9 @@ therefore it always avoids vertical overflow:
\end{tblr}
\end{demohigh}
+If you want to distribute extra vertical space evenly to two rows,
+you may use \verb!vspan! option described in Chapter \ref{chap:extra}.
+
\section{Multi Rows and Columns}
It was a hard job to typeset cells with multiple rows and multiple columns. For example:
@@ -607,6 +610,7 @@ All available keys for hlines and vlines are described in Table \ref{key:hline}
\underline{\K{fg}} & rule color name & \None \\
\K{leftpos} & crossing or trimming position at the left side & \V{1} \\
\K{rightpos} & crossing or trimming position at the right side & \V{1} \\
+ \K{endpos} & adjust leftpos/rightpos for only the leftmost/rightmost column & \V{false} \\
\K{abovespace} & set \V{belowsep} of previous row (see Table \ref{key:row}) & \V{2pt} \\
\K{belowspace} & set \V{abovesep} of current row (see Table \ref{key:row}) & \V{2pt} \\
\K{abovespace+} & increase \V{belowsep} of previous row & \None \\
@@ -657,14 +661,13 @@ Another pair of braces before will select segments in all hlines/vlines.
\begin{demohigh}
\begin{tblr}{
vlines = {1,3,5}{dashed},
- vlines = {2,4,6}{solid},
+ vlines = {2,4}{solid},
}
Alpha & Beta & Gamma & Delta \\
Epsilon & Zeta & Eta & Theta \\
Iota & Kappa & Lambda & Mu \\
Nu & Xi & Omicron & Pi \\
Rho & Sigma & Tau & Upsilon \\
- Phi & Chi & Psi & Omega \\
\end{tblr}
\end{demohigh}
@@ -682,7 +685,6 @@ Advanced users could read the source code for this.)
Iota & Kappa & Lambda & Mu \\
Nu & Xi & Omicron & Pi \\
Rho & Sigma & Tau & Upsilon \\
- Phi & Chi & Psi & Omega \\
\end{tblr}
\end{demohigh}
@@ -795,6 +797,22 @@ Here is an example for these four keys:
\end{tblr}
\end{demohigh}
+There is also an \verb!endpos! option for adjusting \verb!leftpos!/\verb!rightpos!
+for only the leftmost/rightmost column:
+
+\begin{demohigh}
+\begin{tblr}{
+ hline{1,4} = {1}{-}{},
+ hline{1,4} = {2}{-}{},
+ hline{2,3} = {leftpos = -1, rightpos = -1, endpos},
+ vline{1,4} = {abovepos = 1, belowpos = 1},
+}
+ Alpha & Beta & Gamma \\
+ Epsilon & Zeta & Eta \\
+ Iota & Kappa & Lambda \\
+\end{tblr}
+\end{demohigh}
+
\subsection{Hlines and Vlines in Old Interfaces}
The \verb!\hline! command has an optional argument which accepts key-value options.
@@ -882,7 +900,7 @@ All available keys for cells are described in Table \ref{key:cell} and Table \re
caption = {Keys for the Content of Cells},
label = {key:cell},
remark{Note} = {In most cases, you can omit the underlined key names and write only their values.}
-]{}
+]{verb}
Key & Description and Values & Initial Value \\
\underline{\K{halign}}
& horizontal alignment: \V{l} (left), \V{c} (center), \V{r} (right) or \V{j} (justify)
@@ -895,9 +913,12 @@ All available keys for cells are described in Table \ref{key:cell} and Table \re
\underline{\K{bg}} & background color name & \None \\
\K{fg} & foreground color name & \None \\
\K{font} & font commands & \None \\
+ \K{mode} & set cell mode: \V{math}, \V{imath}, \V{dmath} or \V{text} & \None \\
+ \verb!$! & same as \V{mode=math} & \None \\
+ \verb!$$! & same as \V{mode=dmath} & \None \\
+ \K{cmd} & execute command for the cell text & \None \\
\K{preto} & prepend text to the cell & \None \\
\K{appto} & append text to the cell & \None \\
- \K{cmd} & execute command for the cell text & \None \\
\end{spectblr}
\vspace{-2em}
\begin{spectblr}[
@@ -922,7 +943,16 @@ Option \verb!cells! is for setting all cells.
\end{tblr}
\end{demohigh}
-Option \verb!cell{i}{j}! is for setting some cells.
+Option \verb!cell{i}{j}! is for setting some cells,
+where \verb!i! stands for the row numbers and \verb!j! stands for the column numbers.
+\nopagebreak
+\begin{demohigh}
+\begin{tblr}{
+ cell{1}{2-4} = {cmd=\fbox}
+}
+ Alpha & Beta & Gamma & Delta
+\end{tblr}
+\end{demohigh}
\begin{demohigh}
\begin{tblr}{
@@ -1007,7 +1037,7 @@ All available keys for rows and columns are described in Table \ref{key:row} and
caption = {Keys for Rows},
label = {key:row},
remark{Note} = {In most cases, you can omit the underlined key names and write only their values.}
-]{}
+]{verb}
Key & Description and Values & Initial Value \\
\underline{\K{halign}}
& horizontal alignment: \V{l} (left), \V{c} (center), or \V{r} (right)
@@ -1020,6 +1050,10 @@ All available keys for rows and columns are described in Table \ref{key:row} and
\underline{\K{bg}} & background color name & \None \\
\K{fg} & foreground color name & \None \\
\K{font} & font commands & \None \\
+ \K{mode} & set mode for row cells: \V{math}, \V{imath}, \V{dmath} or \V{text} & \None \\
+ \verb!$! & same as \V{mode=math} & \None \\
+ \verb!$$! & same as \V{mode=dmath} & \None \\
+ \K{cmd} & execute command for every cell text & \None \\
\K{abovesep} & set vertical space above the row & \V{2pt} \\
\K{abovesep+} & increase vertical space above the row & \None \\
\K{belowsep} & set vertical space below the row & \V{2pt} \\
@@ -1028,14 +1062,13 @@ All available keys for rows and columns are described in Table \ref{key:row} and
\K{rowsep+} & increase vertical space above and below the row & \None \\
\K{preto} & prepend text to every cell (like \V{>} specifier in \K{rowspec}) & \None \\
\K{appto} & append text to every cell (like \V{<} specifier in \K{rowspec}) & \None \\
- \K{cmd} & execute command for every cell text & \None \\
\end{spectblr}
\vspace{-2em}
\begin{spectblr}[
caption = {Keys for Columns},
label = {key:column},
remark{Note} = {In most cases, you can omit the underlined key names and write only their values.}
-]{}
+]{verb}
Key & Description and Values & Initial Value \\
\underline{\K{halign}}
& horizontal alignment: \V{l} (left), \V{c} (center), or \V{r} (right)
@@ -1049,6 +1082,10 @@ All available keys for rows and columns are described in Table \ref{key:row} and
\underline{\K{bg}} & background color name & \None \\
\K{fg} & foreground color name & \None \\
\K{font} & font commands & \None \\
+ \K{mode} & set mode for column cells: \V{math}, \V{imath}, \V{dmath} or \V{text} & \None \\
+ \verb!$! & same as \V{mode=math} & \None \\
+ \verb!$$! & same as \V{mode=dmath} & \None \\
+ \K{cmd} & execute command for every cell text & \None \\
\K{leftsep} & set horizontal space to the left of the column & \V{6pt} \\
\K{leftsep+} & increase horizontal space to the left of the column & \None \\
\K{rightsep} & set horizontal space to the right of the column & \V{6pt} \\
@@ -1057,7 +1094,6 @@ All available keys for rows and columns are described in Table \ref{key:row} and
\K{colsep+} & increase horizontal space to both sides of the column & \None \\
\K{preto} & prepend text to every cell (like \V{>} specifier in \K{colspec}) & \None \\
\K{appto} & append text to every cell (like \V{<} specifier in \K{colspec}) & \None \\
- \K{cmd} & execute command for every cell text & \None \\
\end{spectblr}
\subsection{Rows and Columns in New Interfaces}
@@ -1093,7 +1129,7 @@ Options \verb!row{i}! and \verb!column{j}! are for setting some rows and columns
\end{tblr}
\end{demohigh}
-The following example demonstrates the usages of \verb!bg!, \verb!fg! and \verb!font! keys.
+The following example demonstrates the usages of \verb!bg!, \verb!fg! and \verb!font! keys:
\nopagebreak
\begin{demohigh}
\begin{tblr}{
@@ -1108,8 +1144,23 @@ The following example demonstrates the usages of \verb!bg!, \verb!fg! and \verb!
\end{tblr}
\end{demohigh}
+The following example demonstrates the usages of \verb!mode! key:
+\nopagebreak
+\begin{demohigh}
+$\begin{tblr}{
+ column{1} = {mode=text},
+ column{3} = {mode=dmath},
+}
+\hline
+ Alpha & \frac12 & \frac12 \\
+ Epsilon & \frac34 & \frac34 \\
+ Iota & \frac56 & \frac56 \\
+\hline
+\end{tblr}$
+\end{demohigh}
+
The following example demonstrates the usages of
-\verb!abovesep!, \verb!belowsep!, \verb!leftsep!, \verb!rightsep! keys.
+\verb!abovesep!, \verb!belowsep!, \verb!leftsep!, \verb!rightsep! keys:
%\nopagebreak
\begin{demohigh}
\begin{tblr}{
@@ -1180,6 +1231,19 @@ The following example demonstrates the usage of \verb!width! option.
\end{tblr}
\end{demohigh}
+You can omit \verb!colspec! name if it is the only key you use inside the mandatory argument.
+The following example demonstrates the usages of \verb!$! and \verb!$$! keys:
+\nopagebreak
+\begin{demohigh}
+\begin{tblr}{Q[l]Q[r,$]Q[r,$$]}
+\hline
+ Alpha & \frac12 & \frac12 \\
+ Epsilon & \frac34 & \frac34 \\
+ Iota & \frac56 & \frac56 \\
+\hline
+\end{tblr}
+\end{demohigh}
+
\subsection{Column Types}
The \verb!tabularray! package has only one type of primitive column: the \verb!Q! column.
@@ -1236,6 +1300,7 @@ Any new row type must be defined with \verb!\NewRowType! command.
It can have an optional argument when it's defined.
\chapter{Extra Interfaces}
+\label{chap:extra}
\section{Table Specifications}
@@ -1408,7 +1473,9 @@ The following example demonstrates how to define a new table command:
\verb!Tabularray! need to see every \verb!&! and \verb!\\! when splitting the table body
with \verb!l3regex!. And you can not put cell text inside any table command defined with
\verb!\NewTableCommand!. But you could use outer specification \verb!expand! to make \verb!tabularray!
-expand every occurrence of a specified macro \underline{once} before splitting the table body:
+expand every occurrence of a specified macro \underline{once} before splitting the table body.
+The macro \underline{can not} be defined with \verb!\NewDocumentCommand! or
+\verb!\NewExpandableDocumentCommand!, and \underline{can not} have optional argument.
\begin{demohigh}
\def\tblrbody{
@@ -1487,14 +1554,12 @@ All tracing messages will be written to the log files.
\chapter{Use Long Tables}
\label{chap:long}
-\mywarning{chapter}
-
\section{A Simple Example}
-In fact, to make a decent long table with header and footer, it is better to separate header/footer as
+To make a decent long table with header and footer, it is better to separate header/footer as
\underline{table head/foot} (which includes caption, footnotes, continuation text)
and \underline{row head/foot} (which includes some rows of the table that should appear in every page).
-By this approach, alternating row colors should work as expected.
+By this approach, alternating row colors work as expected.
\NewTblrTheme{fancy}{
\SetTblrStyle{firsthead}{font=\bfseries}
@@ -1689,25 +1754,25 @@ Alpha & Beta & Gamma \\
Rho & Sigma & Tau \\
\hline
Phi & Chi & Psi \\
-%\hline
-% Alpha & Beta & Gamma \\
-%\hline
-% Epsilon & Zeta & Eta \\
-%\hline
-% Iota & Kappa & Lambda \\
-%\hline
-% Nu & Xi & Omicron \\
-%\hline
-% Rho & Sigma & Tau \\
-%\hline
-% Phi & Chi & Psi \\
+\hline
+ Alpha & Beta & Gamma \\
+\hline
+ Epsilon & Zeta & Eta \\
+\hline
+ Iota & Kappa & Lambda \\
+\hline
+ Nu & Xi & Omicron \\
+\hline
+ Rho & Sigma & Tau \\
+\hline
+ Phi & Chi & Psi \\
\hline
Foot & Foot & Foot \\
\hline
\end{longtblr}
As you can see in the above example, the appearance of long tables of \verb!tabularray! package
-is similar to that of \verb!threeparttable! and \verb!threeparttablex! packages.
+is similar to that of \verb!threeparttablex! packages.
We support table footnotes, but not page footnotes in \verb!tabularray! package.
\newpage
@@ -1782,7 +1847,7 @@ In the above example, We set \verb!rowhead=2! and \verb!rowfoot=1!.
\begin{spectblr}[
caption = {Inner Specifications for Row Heads and Row Foots}
]{}
- Key Nama & Key Description & Initial Value \\
+ Key Name & Key Description & Initial Value \\
\V{rowhead} & number of the first rows of the table appear in every page & \V{0} \\
\V{rowfoot} & number of the last rows of the table appear in every page & \V{0} \\
\end{spectblr}
@@ -1793,7 +1858,7 @@ Their options are outer specifications and should be put in the optional argumen
\begin{spectblr}[
caption = {Outer Specifications for Table Heads and Table Foots}
]{verb}
- Key Nama & Key Description & Initial Value \\
+ Key Name & Key Description & Initial Value \\
\V{headsep} & vertical space between table head and table body & \V{6pt} \\
\V{footsep} & vertical space between table foot and table body & \V{6pt} \\
\V{presep} & vertical space between table head and the above text & \verb!1.5\bigskipamount! \\
@@ -2084,6 +2149,49 @@ TEXT\begin{talltblr}[
The \verb!tabularray! package emulates or fixes some commands in other packages.
To avoid potential conflict, you need to enable them with \verb!\UseTblrLibrary! command.
+\section{Library \texttt{amsmath}}
+
+With \verb!\UseTblrLibrary{amsmath}! in the preamble of the document,
+\verb!tabularray! will load \verb!amsmath! package, and define \verb!+array!, \verb!+matrix!,
+\verb!+bmatrix!, \verb!+Bmatrix!, \verb!+pmatrix!, \verb!+vmatrix!, \verb!+Vmatrix! and \verb!+cases!
+environments. Each of the environments is similar to the environment without \verb!+! prefix in its name,
+but has default \verb!rowsep=2pt! just as \verb!tblr! environment. Every environment
+except \verb!+array! accepts an optional argument, where you can write inner specifications.
+
+\begin{demo}
+$\begin{pmatrix}
+ \dfrac{2}{3} & \dfrac{2}{3} & \dfrac{1}{3} \\
+ \dfrac{2}{3} & -\dfrac{1}{3} & -\dfrac{2}{3} \\
+ \dfrac{1}{3} & -\dfrac{2}{3} & \dfrac{2}{3} \\
+\end{pmatrix}$
+\end{demo}
+
+\begin{demohigh}
+$\begin{+pmatrix}[cells={r},row{2}={purple8}]
+ \dfrac{2}{3} & \dfrac{2}{3} & \dfrac{1}{3} \\
+ \dfrac{2}{3} & -\dfrac{1}{3} & -\dfrac{2}{3} \\
+ \dfrac{1}{3} & -\dfrac{2}{3} & \dfrac{2}{3} \\
+\end{+pmatrix}$
+\end{demohigh}
+
+\begin{demo}
+$f(x)=\begin{cases}
+ 0, & x=1; \\
+ \dfrac{1}{3}, & x=2; \\
+ \dfrac{2}{3}, & x=3; \\
+ 1, & x=4. \\
+\end{cases}$
+\end{demo}
+
+\begin{demohigh}
+$f(x)=\begin{+cases}
+ 0, & x=1; \\
+ \dfrac{1}{3}, & x=2; \\
+ \dfrac{2}{3}, & x=3; \\
+ 1, & x=4. \\
+\end{+cases}$
+\end{demohigh}
+
\section{Library \texttt{booktabs}}
With \verb!\UseTblrLibrary{booktabs}! in the preamble of the document,
@@ -2212,6 +2320,21 @@ and the other half to \verb!abovesep! of current row.
\end{booktabs}
\end{demohigh}
+\section{Library \texttt{counter}}
+
+You need to load \verb!counter! library with \verb!\UseTblrLibrary{counter}!,
+if you want to modify some LaTeX counters inside \verb!tabularray! tables.
+
+\begin{demohigh}
+\newcounter{mycnta}
+\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}
+\begin{tblr}{hlines}
+ \mycnta & \mycnta & \mycnta \\
+ \mycnta & \mycnta & \mycnta \\
+ \mycnta & \mycnta & \mycnta \\
+\end{tblr}
+\end{demohigh}
+
\section{Library \texttt{diagbox}}
When writing \verb!\UseTblrLibrary{diagbox}! in the preamble of the document,
@@ -2297,11 +2420,12 @@ Also you must use \verb!l!, \verb!c! or \verb!r! to set horizontal alignment for
\end{tblr}
\end{demohigh}
-Both \verb!S! and \verb!s! columns are supported. In fact, These two columns are defined as follows:
+Both \verb!S! and \verb!s! columns are supported. In fact, These two columns have been defined as follows:
\begin{codehigh}
-\NewColumnType{S}[1][]{Q[si={##1},c]}
-\NewColumnType{s}[1][]{Q[si={##1},c,cmd=\TblrUnit]}
+\NewColumnType{S}[1][]{Q[si={#1},c]}
+\NewColumnType{s}[1][]{Q[si={#1},c,cmd=\TblrUnit]}
\end{codehigh}
+You don't need to and are not allowed to define them again.
\section{Library \texttt{varwidth}}