| 1 |
% -*- coding: utf-8 -*- |
| 2 |
% !TEX program = lualatex |
| 3 |
\documentclass[oneside]{book} |
| 4 |
\newcommand*{\myversion}{2025C} |
| 5 |
\newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi} |
| 6 |
|
| 7 |
\usepackage[a4paper,margin=2.5cm]{geometry} |
| 8 |
|
| 9 |
\setlength{\parindent}{0pt} |
| 10 |
\setlength{\parskip}{4pt plus 1pt minus 1pt} |
| 11 |
|
| 12 |
\makeatletter |
| 13 |
\ExplSyntaxOn |
| 14 |
\NewDocumentCommand\MyDebugSingle{m}{ |
| 15 |
\@ifpackageloaded{docmute}{#1}{ |
| 16 |
\str_if_eq:onTF{\jobname}{tabularray}{#1}{ |
| 17 |
\sys_ensure_backend: |
| 18 |
\debug_on:n{check-declarations} |
| 19 |
#1 |
| 20 |
\debug_off:n{check-declarations} |
| 21 |
} |
| 22 |
} |
| 23 |
} |
| 24 |
\ExplSyntaxOff |
| 25 |
\makeatother |
| 26 |
\MyDebugSingle{\usepackage{tabularray}} |
| 27 |
|
| 28 |
\usepackage{codehigh} % https://ctan.org/pkg/codehigh |
| 29 |
\usepackage{array,multirow,amsmath} |
| 30 |
\usepackage{environ} |
| 31 |
\usepackage{enumitem} |
| 32 |
|
| 33 |
\usepackage[firstpage=true]{background} |
| 34 |
\backgroundsetup{contents={}} |
| 35 |
|
| 36 |
\UseTblrLibrary{ |
| 37 |
amsmath,booktabs,counter,diagbox,functional,siunitx,tikz,varwidth |
| 38 |
} |
| 39 |
\usetikzlibrary{patterns} |
| 40 |
|
| 41 |
\usepackage{hyperref} |
| 42 |
\hypersetup{ |
| 43 |
colorlinks=true, |
| 44 |
urlcolor=blue3, |
| 45 |
linkcolor=blue3, |
| 46 |
} |
| 47 |
|
| 48 |
\usepackage{tcolorbox} |
| 49 |
\tcbset{sharp corners, boxrule=0.5pt, colback=red9} |
| 50 |
|
| 51 |
\usepackage{float} |
| 52 |
%\usepackage{enumerate} |
| 53 |
|
| 54 |
\setcounter{tocdepth}{1} |
| 55 |
|
| 56 |
\NewDocumentCommand\None{}{{\boldmath$\times$}} |
| 57 |
\NewDocumentCommand\K{m}{\texttt{#1}} % key |
| 58 |
\NewDocumentCommand\V{m}{\texttt{#1}} % value |
| 59 |
\NewDocumentCommand\Q{m}{\texttt{#1}} % column/row type |
| 60 |
|
| 61 |
\NewDocumentCommand\KK{m}{\texttt{\fakeverb{#1}}} % key |
| 62 |
\NewDocumentCommand\VV{m}{\texttt{\fakeverb{#1}}} % value |
| 63 |
\NewDocumentCommand\KV{m}{\texttt{\fakeverb{#1}}} % key and value |
| 64 |
\NewDocumentCommand\CC{m}{\texttt{\fakeverb{#1}}} % command |
| 65 |
\NewDocumentCommand\EE{m}{\texttt{\fakeverb{#1}}} % environment |
| 66 |
\NewDocumentCommand\LL{m}{\texttt{\fakeverb{#1}}} % library |
| 67 |
\NewDocumentCommand\PP{m}{\texttt{\fakeverb{#1}}} % package |
| 68 |
\NewDocumentCommand\FF{m}{\texttt{\fakeverb{#1}}} % file |
| 69 |
\NewDocumentCommand\NN{m}{\texttt{\fakeverb{#1}}} % tikz node |
| 70 |
\NewDocumentCommand\KP{m}{\texttt{\fakeverb{#1}}} % key path |
| 71 |
\NewDocumentCommand\HP{m}{\texttt{\fakeverb{#1}}} % hook path |
| 72 |
\NewDocumentCommand\CI{m}{\texttt{\fakeverb{#1}}} % child indexer |
| 73 |
\NewDocumentCommand\CS{m}{\texttt{\fakeverb{#1}}} % child selector |
| 74 |
\NewDocumentCommand\CO{m}{\texttt{\fakeverb{#1}}} % counter |
| 75 |
\NewDocumentCommand\EN{m}{\texttt{\fakeverb{#1}}} % element name |
| 76 |
\NewDocumentCommand\TN{m}{\texttt{\fakeverb{#1}}} % template name |
| 77 |
\NewDocumentCommand\TT{m}{\texttt{\fakeverb{#1}}} % text |
| 78 |
|
| 79 |
\NewTblrEnviron{newtblr} |
| 80 |
\SetTblrOuter[newtblr]{long} |
| 81 |
\SetTblrInner[newtblr]{ |
| 82 |
hlines = {gray3}, column{1,2} = {co=1}, colsep = 5pt, |
| 83 |
row{2-Z} = {brown8}, |
| 84 |
row{1} = {fg=white, bg=purple2, font=\bfseries\sffamily}, |
| 85 |
} |
| 86 |
|
| 87 |
\NewTblrEnviron{spectblr} |
| 88 |
\SetTblrOuter[spectblr]{long} |
| 89 |
\SetTblrInner[spectblr]{ |
| 90 |
hlines = {gray3}, column{2} = {co=1}, colsep = 5pt, |
| 91 |
row{2-Z} = {brown8}, |
| 92 |
row{1} = {fg=white, bg=purple2, font=\bfseries\sffamily}, |
| 93 |
rowhead = 1, |
| 94 |
} |
| 95 |
|
| 96 |
\renewcommand\emph[1]{\textit{\color{red3}#1}} |
| 97 |
|
| 98 |
\newcommand{\mywarning}[1]{% |
| 99 |
\begin{tcolorbox} |
| 100 |
#1 |
| 101 |
\end{tcolorbox}% |
| 102 |
} |
| 103 |
|
| 104 |
%\renewcommand*{\thefootnote}{*} |
| 105 |
|
| 106 |
\colorlet{highback}{azure9} |
| 107 |
\CodeHigh{language=latex/table,style/main=highback,style/code=highback} |
| 108 |
\NewCodeHighEnv{code}{style/main=gray9,style/code=gray9} |
| 109 |
\NewCodeHighEnv{demo}{style/main=gray9,style/code=gray9,demo} |
| 110 |
|
| 111 |
%\CodeHigh{lite} |
| 112 |
|
| 113 |
\begin{document} |
| 114 |
|
| 115 |
\savegeometry{standard} |
| 116 |
\newgeometry{left=0pt,right=0pt} |
| 117 |
|
| 118 |
\begin{titlepage} |
| 119 |
|
| 120 |
\backgroundsetup{ |
| 121 |
scale = 1, |
| 122 |
angle = 0, |
| 123 |
opacity = 1, |
| 124 |
%color = black, |
| 125 |
contents = { |
| 126 |
\begin{tblr}{ |
| 127 |
width = \paperwidth, columns = {1}, rows= {4em, gray9}, |
| 128 |
hlines = {2.8pt,white}, vlines = {2.8pt,white}, |
| 129 |
} |
| 130 |
& & & & & & & & & & & & & & \\ |
| 131 |
& & & & & & & & & & & & & & \\ |
| 132 |
& & & & & & & & & & & & & & \\ |
| 133 |
& & & & & & & & & & & & & & \\ |
| 134 |
& & & & & & & & & & & & & & \\ |
| 135 |
& & & & & & & & & & & & & & \\ |
| 136 |
& & & & & & & & & & & & & & \\ |
| 137 |
& & & & & & & & & & & & & & \\ |
| 138 |
& & & & & & & & & & & & & & \\ |
| 139 |
& & & & & & & & & & & & & & \\ |
| 140 |
& & & & & & & & & & & & & & \\ |
| 141 |
& & & & & & & & & & & & & & \\ |
| 142 |
& & & & & & & & & & & & & & \\ |
| 143 |
& & & & & & & & & & & & & & \\ |
| 144 |
& & & & & & & & & & & & & & \\ |
| 145 |
& & & & & & & & & & & & & & \\ |
| 146 |
& & & & & & & & & & & & & & \\ |
| 147 |
& & & & & & & & & & & & & & \\ |
| 148 |
\end{tblr} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
\noindent |
| 153 |
\begin{tblr}{ |
| 154 |
colspec = {rX}, colsep = 8mm, hlines = {2pt, white}, |
| 155 |
row{odd} = {azure8}, row{even} = {gray8}, |
| 156 |
row{1} = {6em,azure2,fg=white,font=\LARGE\bfseries\sffamily}, |
| 157 |
row{2-Z} = {3em,font=\Large}, |
| 158 |
} |
| 159 |
Tabularray & Typeset Tabulars and Arrays with \LaTeX3 \\ |
| 160 |
Author & Jianrui Lyu ([email protected]) \\ |
| 161 |
Version & \myversion\ (\the\year-\mylpad\month-\mylpad\day) \\ |
| 162 |
Code & \url{https://github.com/lvjr/tabularray} \\ |
| 163 |
Code & \url{https://bitbucket.org/lvjr/tabularray} \\ |
| 164 |
Issue & \url{https://github.com/lvjr/tabularray/issues} \\ |
| 165 |
Discussion & \url{https://github.com/lvjr/tabularray/discussions} \\ |
| 166 |
\end{tblr} |
| 167 |
|
| 168 |
\begin{codehigh}[boxsep=4mm] |
| 169 |
\begin{tblr}{ |
| 170 |
colspec = {rX}, colsep = 8mm, hlines = {2pt, white}, |
| 171 |
row{odd} = {azure8}, row{even} = {gray8}, |
| 172 |
row{1} = {6em,azure2,fg=white,font=\LARGE\bfseries\sffamily}, |
| 173 |
row{2-Z} = {3em,font=\Large}, |
| 174 |
} |
| 175 |
Tabularray & Typeset Tabulars and Arrays with \LaTeX3 \\ |
| 176 |
Author & Jianrui Lyu ([email protected]) \\ |
| 177 |
Version & \myversion\ (\the\year-\mylpad\month-\mylpad\day) \\ |
| 178 |
Code & \url{https://github.com/lvjr/tabularray} \\ |
| 179 |
Code & \url{https://bitbucket.org/lvjr/tabularray} \\ |
| 180 |
Issue & \url{https://github.com/lvjr/tabularray/issues} \\ |
| 181 |
Discussion & \url{https://github.com/lvjr/tabularray/discussions} \\ |
| 182 |
\end{tblr} |
| 183 |
\end{codehigh} |
| 184 |
|
| 185 |
\end{titlepage} |
| 186 |
|
| 187 |
\loadgeometry{standard} |
| 188 |
|
| 189 |
\tableofcontents |
| 190 |
|
| 191 |
\chapter{Overview of Features} |
| 192 |
|
| 193 |
Before using \PP{tabularray} package, it is better to know how to typeset simple text and |
| 194 |
math tables with traditional \EE{tabular}, \EE{tabularx} and \EE{array} environments, |
| 195 |
because we will compare \EE{tblr} environment from \PP{tabularray} package with these |
| 196 |
environments. You may read web pages on LaTeX tables on |
| 197 |
\href{https://www.learnlatex.org/en/lesson-08}{LearnLaTeX} and |
| 198 |
\href{https://www.overleaf.com/learn/latex/Tables}{Overleaf} first. |
| 199 |
|
| 200 |
\section{Vertical space} |
| 201 |
|
| 202 |
After loading \PP{tabularray} package in the preamble, |
| 203 |
we can use \EE{tblr} environments to typeset tabulars and arrays. |
| 204 |
The name \EE{tblr} is short for \PP{tabularray} or \VV{top-bottom-left-right}. |
| 205 |
The following is our first example: |
| 206 |
|
| 207 |
\begin{demo} |
| 208 |
\begin{tabular}{lccr} |
| 209 |
\hline |
| 210 |
Alpha & Beta & Gamma & Delta \\ |
| 211 |
\hline |
| 212 |
Epsilon & Zeta & Eta & Theta \\ |
| 213 |
\hline |
| 214 |
Iota & Kappa & Lambda & Mu \\ |
| 215 |
\hline |
| 216 |
\end{tabular} |
| 217 |
\end{demo} |
| 218 |
|
| 219 |
\begin{demohigh} |
| 220 |
\begin{tblr}{lccr} |
| 221 |
\hline |
| 222 |
Alpha & Beta & Gamma & Delta \\ |
| 223 |
\hline |
| 224 |
Epsilon & Zeta & Eta & Theta \\ |
| 225 |
\hline |
| 226 |
Iota & Kappa & Lambda & Mu \\ |
| 227 |
\hline |
| 228 |
\end{tblr} |
| 229 |
\end{demohigh} |
| 230 |
|
| 231 |
You may notice that there is extra space above and below the table rows with \EE{tblr} environment. |
| 232 |
This space makes the table look better. |
| 233 |
If you don't like it, you could use \CC{\SetTblrInner} command: |
| 234 |
|
| 235 |
\begin{demohigh} |
| 236 |
\SetTblrInner{rowsep=0pt} |
| 237 |
\begin{tblr}{lccr} |
| 238 |
\hline |
| 239 |
Alpha & Beta & Gamma & Delta \\ |
| 240 |
\hline |
| 241 |
Epsilon & Zeta & Eta & Theta \\ |
| 242 |
\hline |
| 243 |
Iota & Kappa & Lambda & Mu \\ |
| 244 |
\hline |
| 245 |
\end{tblr} |
| 246 |
\end{demohigh} |
| 247 |
|
| 248 |
But in many cases, this \KK{rowsep} is useful: |
| 249 |
|
| 250 |
\begin{demo} |
| 251 |
$\begin{array}{rrr} |
| 252 |
\hline |
| 253 |
\dfrac{2}{3} & \dfrac{2}{3} & \dfrac{1}{3} \\ |
| 254 |
\dfrac{2}{3} & -\dfrac{1}{3} & -\dfrac{2}{3} \\ |
| 255 |
\dfrac{1}{3} & -\dfrac{2}{3} & \dfrac{2}{3} \\ |
| 256 |
\hline |
| 257 |
\end{array}$ |
| 258 |
\end{demo} |
| 259 |
|
| 260 |
\begin{demohigh} |
| 261 |
$\begin{tblr}{rrr} |
| 262 |
\hline |
| 263 |
\dfrac{2}{3} & \dfrac{2}{3} & \dfrac{1}{3} \\ |
| 264 |
\dfrac{2}{3} & -\dfrac{1}{3} & -\dfrac{2}{3} \\ |
| 265 |
\dfrac{1}{3} & -\dfrac{2}{3} & \dfrac{2}{3} \\ |
| 266 |
\hline |
| 267 |
\end{tblr}$ |
| 268 |
\end{demohigh} |
| 269 |
|
| 270 |
Note that you can use \EE{tblr} in both text and math modes. |
| 271 |
|
| 272 |
\section{Multiline cells} |
| 273 |
|
| 274 |
It's quite easy to write multiline cells without fixing the column width in \EE{tblr} environments: |
| 275 |
just enclose the cell text with braces and use \CC{\\\\} to break lines: |
| 276 |
|
| 277 |
\begin{demohigh} |
| 278 |
\begin{tblr}{|l|c|r|} |
| 279 |
\hline |
| 280 |
Left & {Center \\ Cent \\ C} & {Right \\ R} \\ |
| 281 |
\hline |
| 282 |
{L \\ Left} & {C \\ Cent \\ Center} & R \\ |
| 283 |
\hline |
| 284 |
\end{tblr} |
| 285 |
\end{demohigh} |
| 286 |
|
| 287 |
\section{Cell alignment} |
| 288 |
|
| 289 |
From time to time, |
| 290 |
you may want to specify the horizontal and vertical alignment of cells at the same time. |
| 291 |
\PP{Tabularray} package provides a \Q{Q} column for this |
| 292 |
(In fact, \Q{Q} column is the only primitive column, |
| 293 |
other columns are defined as \Q{Q} columns with some options): |
| 294 |
|
| 295 |
\begin{demohigh} |
| 296 |
\begin{tblr}{|Q[l,t]|Q[c,m]|Q[r,b]|} |
| 297 |
\hline |
| 298 |
{Top Baseline \\ Left Left} & Middle Center & {Right Right \\ Bottom Baseline} \\ |
| 299 |
\hline |
| 300 |
\end{tblr} |
| 301 |
\end{demohigh} |
| 302 |
|
| 303 |
Note that you can use more meaningful \K{t} instead of \K{p} for top baseline alignment. |
| 304 |
For some users who are familiar with word processors, |
| 305 |
these \K{t} and \K{b} columns are counter-intuitive. |
| 306 |
In \PP{tabularray} package, there are another two column types \K{h} and \K{f}, |
| 307 |
which will align cell text at the head and the foot, respectively: |
| 308 |
|
| 309 |
\begin{demohigh} |
| 310 |
\begin{tblr}{Q[h,4em]Q[t,4em]Q[m,4em]Q[b,4em]Q[f,4em]} |
| 311 |
\hline |
| 312 |
{row\\head} & {top\\line} & {middle} & {line\\bottom} & {row\\foot} \\ |
| 313 |
\hline |
| 314 |
{row\\head} & {top\\line} & {11\\22\\mid\\44\\55} & {line\\bottom} & {row\\foot} \\ |
| 315 |
\hline |
| 316 |
\end{tblr} |
| 317 |
\end{demohigh} |
| 318 |
|
| 319 |
\section{Multirow cells} |
| 320 |
|
| 321 |
The above \K{h} and \K{f} alignments are necessary |
| 322 |
when we write multirow cells with \CC{\SetCell} command in \PP{tabularray}. |
| 323 |
|
| 324 |
\begin{demo} |
| 325 |
\begin{tabular}{|l|l|l|l|} |
| 326 |
\hline |
| 327 |
\multirow[t]{4}{1.5cm}{Multirow Cell One} & Alpha & |
| 328 |
\multirow[b]{4}{1.5cm}{Multirow Cell Two} & Alpha \\ |
| 329 |
& Beta & & Beta \\ |
| 330 |
& Gamma & & Gamma \\ |
| 331 |
& Delta & & Delta \\ |
| 332 |
\hline |
| 333 |
\end{tabular} |
| 334 |
\end{demo} |
| 335 |
|
| 336 |
\begin{demohigh} |
| 337 |
\begin{tblr}{|l|l|l|l|} |
| 338 |
\hline |
| 339 |
\SetCell[r=4]{h,1.5cm} Multirow Cell One & Alpha & |
| 340 |
\SetCell[r=4]{f,1.5cm} Multirow Cell Two & Alpha \\ |
| 341 |
& Beta & & Beta \\ |
| 342 |
& Gamma & & Gamma \\ |
| 343 |
& Delta & & Delta \\ |
| 344 |
\hline |
| 345 |
\end{tblr} |
| 346 |
\end{demohigh} |
| 347 |
|
| 348 |
Note that you don't need to load \PP{multirow} package first, |
| 349 |
since \PP{tabularray} doesn't depend on it. |
| 350 |
Furthermore, \PP{tabularray} will always typeset decent multirow cells. |
| 351 |
First, it will set correct vertical middle alignment, |
| 352 |
even though some rows have large height: |
| 353 |
|
| 354 |
\begin{demo} |
| 355 |
\begin{tabular}{|l|m{4em}|} |
| 356 |
\hline |
| 357 |
\multirow[c]{4}{1.5cm}{Multirow} & Alpha \\ |
| 358 |
& Beta \\ |
| 359 |
& Gamma \\ |
| 360 |
& Delta Delta Delta \\ |
| 361 |
\hline |
| 362 |
\end{tabular} |
| 363 |
\end{demo} |
| 364 |
|
| 365 |
\begin{demohigh} |
| 366 |
\begin{tblr}{|l|m{4em}|} |
| 367 |
\hline |
| 368 |
\SetCell[r=4]{m,1.5cm} Multirow & Alpha \\ |
| 369 |
& Beta \\ |
| 370 |
& Gamma \\ |
| 371 |
& Delta Delta Delta \\ |
| 372 |
\hline |
| 373 |
\end{tblr} |
| 374 |
\end{demohigh} |
| 375 |
|
| 376 |
Second, it will enlarge row heights if the multirow cells have large height, |
| 377 |
therefore it always avoids vertical overflow: |
| 378 |
|
| 379 |
\begin{demo} |
| 380 |
\begin{tabular}{|l|m{4em}|} |
| 381 |
\hline |
| 382 |
\multirow[c]{2}{1cm}{Line \\ Line \\ Line \\ Line} & Alpha \\ |
| 383 |
\cline{2-2} |
| 384 |
& Beta \\ |
| 385 |
\hline |
| 386 |
\end{tabular} |
| 387 |
\end{demo} |
| 388 |
|
| 389 |
\begin{demohigh} |
| 390 |
\begin{tblr}{|l|m{4em}|} |
| 391 |
\hline |
| 392 |
\SetCell[r=2]{m,1cm} {Line \\ Line \\ Line \\ Line} & Alpha \\ |
| 393 |
\cline{2} |
| 394 |
& Beta \\ |
| 395 |
\hline |
| 396 |
\end{tblr} |
| 397 |
\end{demohigh} |
| 398 |
|
| 399 |
If you want to distribute extra vertical space evenly to two rows, |
| 400 |
you may use \K{vspan} option described in Chapter \ref{chap:extra}. |
| 401 |
|
| 402 |
\section{Multi rows and columns} |
| 403 |
|
| 404 |
It was a hard job to typeset cells with multiple rows and multiple columns. For example: |
| 405 |
|
| 406 |
\begin{demo} |
| 407 |
\begin{tabular}{|c|c|c|c|c|} |
| 408 |
\hline |
| 409 |
\multirow{2}{*}{2 Rows} |
| 410 |
& \multicolumn{2}{c|}{2 Columns} |
| 411 |
& \multicolumn{2}{c|}{\multirow{2}{*}{2 Rows 2 Columns}} \\ |
| 412 |
\cline{2-3} |
| 413 |
& 2-2 & 2-3 & \multicolumn{2}{c|}{} \\ |
| 414 |
\hline |
| 415 |
3-1 & 3-2 & 3-3 & 3-4 & 3-5 \\ |
| 416 |
\hline |
| 417 |
\end{tabular} |
| 418 |
\end{demo} |
| 419 |
|
| 420 |
With \PP{tabularray} package, you can set spanned cells with \CC{\SetCell} command: |
| 421 |
within the optional argument of \CC{\SetCell} command, |
| 422 |
option \K{r} is for rowspan number, and \K{c} for colspan number; |
| 423 |
within the mandatory argument of it, horizontal and vertical alignment options are accepted. |
| 424 |
Therefore it's much simpler to typeset spanned cells: |
| 425 |
|
| 426 |
\begin{demohigh} |
| 427 |
\begin{tblr}{|c|c|c|c|c|} |
| 428 |
\hline |
| 429 |
\SetCell[r=2]{c} 2 Rows |
| 430 |
& \SetCell[c=2]{c} 2 Columns |
| 431 |
& & \SetCell[r=2,c=2]{c} 2 Rows 2 Columns & \\ |
| 432 |
\hline |
| 433 |
& 2-2 & 2-3 & & \\ |
| 434 |
\hline |
| 435 |
3-1 & 3-2 & 3-3 & 3-4 & 3-5 \\ |
| 436 |
\hline |
| 437 |
\end{tblr} |
| 438 |
\end{demohigh} |
| 439 |
|
| 440 |
Using \CC{\multicolumn} command, the omitted cells \emph{must} be removed. |
| 441 |
On the contrary, |
| 442 |
using \CC{\multirow} command, the omitted cells \emph{must not} be removed. |
| 443 |
\CC{\SetCell} command behaves the same as \CC{\multirow} command in this aspect. |
| 444 |
|
| 445 |
With \EE{tblr} environment, any \CC{\hline} segments inside a spanned cell will be ignored, |
| 446 |
therefore we're free to use \CC{\hline} in the above example. |
| 447 |
Also, any omitted cell will definitely be ignored when typesetting, |
| 448 |
no matter it's empty or not. |
| 449 |
With this feature, we could put row and column numbers into the omitted cells, |
| 450 |
which will help us to locate cells when the tables are rather complex: |
| 451 |
|
| 452 |
\begin{demohigh} |
| 453 |
\begin{tblr}{|ll|c|rr|} |
| 454 |
\hline |
| 455 |
\SetCell[r=3,c=2]{h} r=3 c=2 & 1-2 & \SetCell[r=2,c=3]{r} r=2 c=3 & 1-4 & 1-5 \\ |
| 456 |
2-1 & 2-2 & 2-3 & 2-4 & 2-5 \\ |
| 457 |
\hline |
| 458 |
3-1 & 3-2 & MIDDLE & \SetCell[r=3,c=2]{f} r=3 c=2 & 3-5 \\ |
| 459 |
\hline |
| 460 |
\SetCell[r=2,c=3]{l} r=2 c=3 & 4-2 & 4-3 & 4-4 & 4-5 \\ |
| 461 |
5-1 & 5-2 & 5-3 & 5-4 & 5-5 \\ |
| 462 |
\hline |
| 463 |
\end{tblr} |
| 464 |
\end{demohigh} |
| 465 |
|
| 466 |
\section{Column types} |
| 467 |
|
| 468 |
\PP{Tabularray} package supports all normal column types, as well as |
| 469 |
the extendable \Q{X} column type, |
| 470 |
which first occurred in \PP{tabularx} package and was largely improved by \PP{tabu} package: |
| 471 |
|
| 472 |
\begin{demohigh} |
| 473 |
\begin{tblr}{|X[2,l]|X[3,l]|X[1,r]|X[r]|} |
| 474 |
\hline |
| 475 |
Alpha & Beta & Gamma & Delta \\ |
| 476 |
\hline |
| 477 |
\end{tblr} |
| 478 |
\end{demohigh} |
| 479 |
|
| 480 |
Also, \Q{X} columns with negative coefficients are possible: |
| 481 |
|
| 482 |
\begin{demohigh} |
| 483 |
\begin{tblr}{|X[2,l]|X[3,l]|X[-1,r]|X[r]|} |
| 484 |
\hline |
| 485 |
Alpha & Beta & Gamma & Delta \\ |
| 486 |
\hline |
| 487 |
\end{tblr} |
| 488 |
\end{demohigh} |
| 489 |
|
| 490 |
We need the width to typeset a table with \Q{X} columns. |
| 491 |
If unset, the default is \CC{\linewidth}. |
| 492 |
To change the width, we have to first put all column specifications into \KV{colspec={...}}: |
| 493 |
|
| 494 |
\begin{demohigh} |
| 495 |
\begin{tblr}{width=0.8\linewidth,colspec={|X[2,l]|X[3,l]|X[-1,r]|X[r]|}} |
| 496 |
\hline |
| 497 |
Alpha & Beta & Gamma & Delta \\ |
| 498 |
\hline |
| 499 |
\end{tblr} |
| 500 |
\end{demohigh} |
| 501 |
|
| 502 |
You can define new column types with \CC{\NewTblrColumnType} command. |
| 503 |
For example, in \PP{tabularray} package, |
| 504 |
\Q{b} and \Q{X} columns are defined as special \Q{Q} columns: |
| 505 |
\begin{codehigh} |
| 506 |
\NewTblrColumnType{b}[1]{Q[b,wd=#1]} |
| 507 |
\NewTblrColumnType{X}[1][]{Q[co=1,#1]} |
| 508 |
\end{codehigh} |
| 509 |
|
| 510 |
\section{Row types} |
| 511 |
|
| 512 |
Now that we have column types and \K{colspec} option, |
| 513 |
you may ask for row types and \K{rowspec} option. |
| 514 |
Yes, they are here: |
| 515 |
|
| 516 |
\begin{demohigh} |
| 517 |
\begin{tblr}{colspec={Q[l]Q[c]Q[r]},rowspec={|Q[t]|Q[m]|Q[b]|}} |
| 518 |
{Alpha \\ Alpha} & Beta & Gamma \\ |
| 519 |
Delta & Epsilon & {Zeta \\ Zeta} \\ |
| 520 |
Eta & {Theta \\ Theta} & Iota \\ |
| 521 |
\end{tblr} |
| 522 |
\end{demohigh} |
| 523 |
|
| 524 |
Same as column types, \Q{Q} is the only primitive row type, |
| 525 |
and other row types are defined as \Q{Q} types with different options. |
| 526 |
It's better to specify horizontal alignment in \K{colspec}, |
| 527 |
and vertical alignment in \K{rowspec}, respectively. |
| 528 |
|
| 529 |
Inside \K{rowspec}, \Q{|} is the hline type. |
| 530 |
Therefore we need not to write \CC{\hline} command, which makes table code cleaner. |
| 531 |
|
| 532 |
\section{Hlines and vlines} |
| 533 |
|
| 534 |
Hlines and vlines have been improved too. You can specify the widths and styles of them: |
| 535 |
|
| 536 |
\begin{demohigh} |
| 537 |
\begin{tblr}{|l|[dotted]|[2pt]c|r|[solid]|[dashed]|} |
| 538 |
\hline |
| 539 |
One & Two & Three \\ |
| 540 |
\hline\hline[dotted]\hline |
| 541 |
Four & Five & Six \\ |
| 542 |
\hline[dashed]\hline[1pt] |
| 543 |
Seven & Eight & Nine \\ |
| 544 |
\hline |
| 545 |
\end{tblr} |
| 546 |
\end{demohigh} |
| 547 |
|
| 548 |
\section{Colorful tables} |
| 549 |
|
| 550 |
To add colors to your tables, you need to load \PP{xcolor} package first. |
| 551 |
\PP{Tabularray} package will also load |
| 552 |
\href{https://ctan.org/pkg/ninecolors}{\texttt{ninecolors}} package for proper color contrast. |
| 553 |
First you can specify background option for \Q{Q} rows/columns inside \K{rowspec}/\K{colspec}: |
| 554 |
|
| 555 |
\begin{demohigh} |
| 556 |
\begin{tblr}{colspec={lcr},rowspec={|Q[cyan7]|Q[azure7]|Q[blue7]|}} |
| 557 |
Alpha & Beta & Gamma \\ |
| 558 |
Epsilon & Zeta & Eta \\ |
| 559 |
Iota & Kappa & Lambda \\ |
| 560 |
\end{tblr} |
| 561 |
\end{demohigh} |
| 562 |
|
| 563 |
\begin{demohigh} |
| 564 |
\begin{tblr}{colspec={Q[l,brown7]Q[c,yellow7]Q[r,olive7]},rowspec={|Q|Q|Q|}} |
| 565 |
Alpha & Beta & Gamma \\ |
| 566 |
Epsilon & Zeta & Eta \\ |
| 567 |
Iota & Kappa & Lambda \\ |
| 568 |
\end{tblr} |
| 569 |
\end{demohigh} |
| 570 |
|
| 571 |
Also you can use \CC{\SetRow} or \CC{\SetColumn} command to specify row or column colors: |
| 572 |
|
| 573 |
\begin{demohigh} |
| 574 |
\begin{tblr}{colspec={lcr},rowspec={|Q|Q|Q|}} |
| 575 |
\SetRow{cyan7} Alpha & Beta & Gamma \\ |
| 576 |
\SetRow{azure7} Epsilon & Zeta & Eta \\ |
| 577 |
\SetRow{blue7} Iota & Kappa & Lambda \\ |
| 578 |
\end{tblr} |
| 579 |
\end{demohigh} |
| 580 |
|
| 581 |
\begin{demohigh} |
| 582 |
\begin{tblr}{colspec={lcr},rowspec={|Q|Q|Q|}} |
| 583 |
\SetColumn{brown7} |
| 584 |
Alpha & \SetColumn{yellow7} |
| 585 |
Beta & \SetColumn{olive7} |
| 586 |
Gamma \\ |
| 587 |
Epsilon & Zeta & Eta \\ |
| 588 |
Iota & Kappa & Lambda \\ |
| 589 |
\end{tblr} |
| 590 |
\end{demohigh} |
| 591 |
|
| 592 |
Hlines and vlines can also have colors: |
| 593 |
|
| 594 |
\begin{demohigh} |
| 595 |
\begin{tblr}{colspec={lcr},rowspec={|[2pt,green7]Q|[teal7]Q|[green7]Q|[3pt,teal7]}} |
| 596 |
Alpha & Beta & Gamma \\ |
| 597 |
Epsilon & Zeta & Eta \\ |
| 598 |
Iota & Kappa & Lambda \\ |
| 599 |
\end{tblr} |
| 600 |
\end{demohigh} |
| 601 |
|
| 602 |
\begin{demohigh} |
| 603 |
\begin{tblr}{colspec={|[2pt,violet5]l|[2pt,magenta5]c|[2pt,purple5]r|[2pt,red5]}} |
| 604 |
Alpha & Beta & Gamma \\ |
| 605 |
Epsilon & Zeta & Eta \\ |
| 606 |
Iota & Kappa & Lambda \\ |
| 607 |
\end{tblr} |
| 608 |
\end{demohigh} |
| 609 |
|
| 610 |
\chapter{Basic Interfaces} |
| 611 |
\label{chap:basic} |
| 612 |
|
| 613 |
\section{Old and new interfaces} |
| 614 |
|
| 615 |
With \PP{tabularray} package, you can change the styles of tables via old interfaces or new interfaces. |
| 616 |
|
| 617 |
The old interfaces consist of some table commands inside the table contents. |
| 618 |
Same as \EE{tabular} and \EE{array} environments, |
| 619 |
all table commands \emph{must} be put at the beginning of the cell text. |
| 620 |
Also, new table commands \emph{must} be defined with \CC{\NewTblrTableCommand}. |
| 621 |
|
| 622 |
The new interfaces consist of some options inside the mandatory argument, |
| 623 |
hence totally separating the styles and the contents of tables. |
| 624 |
|
| 625 |
\begin{newtblr}[ |
| 626 |
caption = {Old Interfaces and New Interfaces}, |
| 627 |
label = {key:interface}, |
| 628 |
]{} |
| 629 |
Old Interfaces & New Interfaces \\ |
| 630 |
\CC{\SetHlines} & \K{hlines} \\ |
| 631 |
\CC{\SetHline}, \CC{\hline}, \CC{\hborder}, \CC{\cline} |
| 632 |
& \K{hline}, \K{hborder}, \K{rowspec} \\ |
| 633 |
\CC{\SetVlines} & \K{vlines} \\ |
| 634 |
\CC{\SetVline}, \CC{\vline}, \CC{\vborder}, \CC{\rline} |
| 635 |
& \K{vline}, \K{vborder}, \K{colspec} \\ |
| 636 |
\CC{\SetCells} & \K{cells} \\ |
| 637 |
\CC{\SetCell} & \K{cell} \\ |
| 638 |
\CC{\SetRows} & \K{rows} \\ |
| 639 |
\CC{\SetRow} & \K{row}, \K{rowspec} \\ |
| 640 |
\CC{\SetColumns} & \K{columns} \\ |
| 641 |
\CC{\SetColumn} & \K{column}, \K{colspec} \\ |
| 642 |
\end{newtblr} |
| 643 |
|
| 644 |
\section{Hlines and vlines}\label{sec:hlines-vlines} |
| 645 |
|
| 646 |
All available keys for hlines and vlines are described in Table \ref{key:hline} and Table \ref{key:vline}. |
| 647 |
|
| 648 |
\begin{spectblr}[ |
| 649 |
caption = {Keys for Hlines}, |
| 650 |
label = {key:hline}, |
| 651 |
remark{Note} = {In most cases, you can omit the underlined key names and write only their values.} |
| 652 |
]{} |
| 653 |
Key & Description and Values & Initial Value \\ |
| 654 |
\underline{\K{dash}} & dash style: \V{solid}, \V{dashed} or \V{dotted} & \V{solid} \\ |
| 655 |
\K{text} & replace hline with text (like \V{!} specifier in \K{rowspec}) & \None \\ |
| 656 |
\underline{\K{wd}} & rule width dimension & \V{0.4pt} \\ |
| 657 |
\underline{\K{fg}} & rule color name & \None \\ |
| 658 |
\K{leftpos} & crossing or trimming position at the left side & \V{1} \\ |
| 659 |
\K{rightpos} & crossing or trimming position at the right side & \V{1} \\ |
| 660 |
\K{l} & same as \K{leftpos}, default \V{-0.8} & \V{1} \\ |
| 661 |
\K{r} & same as \K{rightpos}, default \V{-0.8} & \V{1} \\ |
| 662 |
\K{lr} & crossing or trimming positions at both sides, default \V{-0.8} & \V{1} \\ |
| 663 |
\K{endpos} & adjust leftpos/rightpos for only the leftmost/rightmost column & \V{false} \\ |
| 664 |
\end{spectblr} |
| 665 |
\vspace{-2em} |
| 666 |
\begin{spectblr}[ |
| 667 |
caption = {Keys for Vlines}, |
| 668 |
label = {key:vline}, |
| 669 |
remark{Note} = {In most cases, you can omit the underlined key names and write only their values.} |
| 670 |
]{} |
| 671 |
Key & Description and Values & Initial Value \\ |
| 672 |
\underline{\K{dash}} & dash style: \V{solid}, \V{dashed} or \V{dotted} & \V{solid} \\ |
| 673 |
\K{text} & replace vline with text (like \V{!} specifier in \K{colspec}) & \None \\ |
| 674 |
\underline{\K{wd}} & rule width dimension & \V{0.4pt} \\ |
| 675 |
\underline{\K{fg}} & rule color name & \None \\ |
| 676 |
\K{abovepos} & crossing or trimming position at the above side & \V{0} \\ |
| 677 |
\K{belowpos} & crossing or trimming position at the below side & \V{0} \\ |
| 678 |
\end{spectblr} |
| 679 |
|
| 680 |
\subsection{Hlines and vlines in new interfaces} |
| 681 |
|
| 682 |
Options \K{hlines} and \K{vlines} are for setting all hlines and vlines, respectively. |
| 683 |
With empty value, all hlines/vlines will be solid. |
| 684 |
|
| 685 |
\begin{demohigh} |
| 686 |
\begin{tblr}{hlines,vlines} |
| 687 |
Alpha & Beta & Gamma & Delta \\ |
| 688 |
Epsilon & Zeta & Eta & Theta \\ |
| 689 |
Iota & Kappa & Lambda & Mu \\ |
| 690 |
\end{tblr} |
| 691 |
\end{demohigh} |
| 692 |
|
| 693 |
With values inside one pair of braces, all hlines/vlines will be styled. |
| 694 |
|
| 695 |
\begin{demohigh} |
| 696 |
\begin{tblr}{ |
| 697 |
hlines = {1pt,solid}, vlines = {red3,dashed}, |
| 698 |
} |
| 699 |
Alpha & Beta & Gamma & Delta \\ |
| 700 |
Epsilon & Zeta & Eta & Theta \\ |
| 701 |
Iota & Kappa & Lambda & Mu \\ |
| 702 |
\end{tblr} |
| 703 |
\end{demohigh} |
| 704 |
|
| 705 |
Another pair of braces before will select segments in all hlines/vlines. |
| 706 |
|
| 707 |
\begin{demohigh} |
| 708 |
\begin{tblr}{ |
| 709 |
vlines = {1,3,5}{dashed}, |
| 710 |
vlines = {2,4}{solid}, |
| 711 |
} |
| 712 |
Alpha & Beta & Gamma & Delta \\ |
| 713 |
Epsilon & Zeta & Eta & Theta \\ |
| 714 |
Iota & Kappa & Lambda & Mu \\ |
| 715 |
Nu & Xi & Omicron & Pi \\ |
| 716 |
Rho & Sigma & Tau & Upsilon \\ |
| 717 |
\end{tblr} |
| 718 |
\end{demohigh} |
| 719 |
|
| 720 |
The above example can be simplified with \CS{odd} and \CS{even} values. |
| 721 |
|
| 722 |
\begin{demohigh} |
| 723 |
\begin{tblr}{ |
| 724 |
vlines = {odd}{dashed}, |
| 725 |
vlines = {even}{solid}, |
| 726 |
} |
| 727 |
Alpha & Beta & Gamma & Delta \\ |
| 728 |
Epsilon & Zeta & Eta & Theta \\ |
| 729 |
Iota & Kappa & Lambda & Mu \\ |
| 730 |
Nu & Xi & Omicron & Pi \\ |
| 731 |
Rho & Sigma & Tau & Upsilon \\ |
| 732 |
\end{tblr} |
| 733 |
\end{demohigh} |
| 734 |
|
| 735 |
Another pair of braces before will draw more hlines/vlines (in which \V{-} stands for all line segments). |
| 736 |
|
| 737 |
\begin{demohigh} |
| 738 |
\begin{tblr}{ |
| 739 |
hlines = {1}{-}{dashed}, hlines = {2}{-}{solid}, |
| 740 |
} |
| 741 |
Alpha & Beta & Gamma & Delta \\ |
| 742 |
Epsilon & Zeta & Eta & Theta \\ |
| 743 |
Iota & Kappa & Lambda & Mu \\ |
| 744 |
\end{tblr} |
| 745 |
\end{demohigh} |
| 746 |
|
| 747 |
Note that you \emph{must} use indexes in order: first 1, then 2, etc. |
| 748 |
|
| 749 |
Options \KK{hline{i}} and \KK{vline{j}} are for setting some hlines and vlines, respectively. |
| 750 |
Their values are the same as options \K{hlines} and \K{vlines}: |
| 751 |
|
| 752 |
\begin{demohigh} |
| 753 |
\begin{tblr}{ |
| 754 |
hline{1,7} = {1pt,solid}, |
| 755 |
hline{3-5} = {blue3,dashed}, |
| 756 |
vline{1,5} = {3-4}{dotted}, |
| 757 |
} |
| 758 |
Alpha & Beta & Gamma & Delta \\ |
| 759 |
Epsilon & Zeta & Eta & Theta \\ |
| 760 |
Iota & Kappa & Lambda & Mu \\ |
| 761 |
Nu & Xi & Omicron & Pi \\ |
| 762 |
Rho & Sigma & Tau & Upsilon \\ |
| 763 |
Phi & Chi & Psi & Omega \\ |
| 764 |
\end{tblr} |
| 765 |
\end{demohigh} |
| 766 |
|
| 767 |
You can use \V{U}, \V{V}, \V{W}, \V{X}, \V{Y}, \V{Z} to |
| 768 |
denote the last six children, respectively. |
| 769 |
It is especially useful when you are writing long tables: |
| 770 |
|
| 771 |
\begin{demohigh} |
| 772 |
\begin{tblr}{ |
| 773 |
hline{1,Z} = {2pt}, |
| 774 |
hline{2,Y} = {1pt}, |
| 775 |
hline{3-X} = {dashed}, |
| 776 |
} |
| 777 |
Alpha & Beta & Gamma & Delta \\ |
| 778 |
Epsilon & Zeta & Eta & Theta \\ |
| 779 |
Iota & Kappa & Lambda & Mu \\ |
| 780 |
Nu & Xi & Omicron & Pi \\ |
| 781 |
Rho & Sigma & Tau & Upsilon \\ |
| 782 |
Phi & Chi & Psi & Omega \\ |
| 783 |
\end{tblr} |
| 784 |
\end{demohigh} |
| 785 |
|
| 786 |
Now we show the usage of \K{text} key by the following example% |
| 787 |
\footnote{Code from \url{https://tex.stackexchange.com/questions/603023/tabularray-and-tabularx-column-separator}.}: |
| 788 |
|
| 789 |
\begin{demohigh} |
| 790 |
\begin{tblr}{ |
| 791 |
vlines, hlines, |
| 792 |
colspec = {lX[c]X[c]X[c]X[c]}, |
| 793 |
vline{2} = {1}{text=\clap{:}}, |
| 794 |
vline{3} = {1}{text=\clap{$+$}}, |
| 795 |
vline{4} = {1}{text=\clap{$\longrightarrow$}}, |
| 796 |
vline{5} = {1}{text=\clap{$+$}}, |
| 797 |
} |
| 798 |
Equation & $CH_4$ & $2O_2$ & $CO_2$ & $2H_2O$ \\ |
| 799 |
Initial & $n_1$ & $n_2$ & $0$ & $0$ \\ |
| 800 |
Final & $n_1-x$ & $n_2-2x$ & $x$ & $2x$ |
| 801 |
\end{tblr} |
| 802 |
\end{demohigh} |
| 803 |
|
| 804 |
The \K{leftpos} and \K{rightpos} keys specify crossing or trimming positions for hlines. |
| 805 |
The possible values for them are decimal numbers between \V{-1} and \V{1}. |
| 806 |
Their initial values are \V{1}. |
| 807 |
|
| 808 |
\begin{center} |
| 809 |
\begin{tblr}{width=0.5\textwidth,colspec={rX[l]},hlines} |
| 810 |
-1 & the hline is trimmed by \V{colsep} \\ |
| 811 |
0 & the hline only touches the first vline \\ |
| 812 |
1 & the hline touches all the vlines \\ |
| 813 |
\end{tblr} |
| 814 |
\end{center} |
| 815 |
|
| 816 |
The \K{abovepos} and \K{belowpos} keys for vlines have similar meanings. |
| 817 |
But their initial values are \V{0}. |
| 818 |
|
| 819 |
\begin{center} |
| 820 |
\begin{tblr}{width=0.5\textwidth,colspec={rX[l]},hlines} |
| 821 |
-1 & the vline is trimmed by \V{rowsep} \\ |
| 822 |
0 & the vline only touches the first hline \\ |
| 823 |
1 & the vline touches all the hlines \\ |
| 824 |
\end{tblr} |
| 825 |
\end{center} |
| 826 |
|
| 827 |
Here is an example for these four keys: |
| 828 |
|
| 829 |
\begin{demohigh} |
| 830 |
\begin{tblr}{ |
| 831 |
hline{1,4} = {1}{-}{}, |
| 832 |
hline{1,4} = {2}{-}{}, |
| 833 |
hline{2,3} = {1}{-}{leftpos = -1, rightpos = -1}, |
| 834 |
hline{2,3} = {2}{-}{leftpos = -1, rightpos = -1}, |
| 835 |
vline{1,4} = {abovepos = 1, belowpos = 1}, |
| 836 |
} |
| 837 |
Alpha & Beta & Gamma \\ |
| 838 |
Epsilon & Zeta & Eta \\ |
| 839 |
Iota & Kappa & Lambda \\ |
| 840 |
\end{tblr} |
| 841 |
\end{demohigh} |
| 842 |
|
| 843 |
There is also an \K{endpos} option for adjusting \K{leftpos}/\K{rightpos} |
| 844 |
for only the leftmost/rightmost column: |
| 845 |
|
| 846 |
\begin{demohigh} |
| 847 |
\begin{tblr}{ |
| 848 |
hline{1,4} = {1}{-}{}, |
| 849 |
hline{1,4} = {2}{-}{}, |
| 850 |
hline{2,3} = {leftpos = -1, rightpos = -1, endpos}, |
| 851 |
vline{1,4} = {abovepos = 1, belowpos = 1}, |
| 852 |
} |
| 853 |
Alpha & Beta & Gamma \\ |
| 854 |
Epsilon & Zeta & Eta \\ |
| 855 |
Iota & Kappa & Lambda \\ |
| 856 |
\end{tblr} |
| 857 |
\end{demohigh} |
| 858 |
|
| 859 |
\subsection{Hlines and vlines in old interfaces} |
| 860 |
|
| 861 |
The \CC{\hline} command has an optional argument which accepts key-value options. |
| 862 |
The available keys are described in Table \ref{key:hline}. |
| 863 |
|
| 864 |
\begin{demohigh} |
| 865 |
\begin{tblr}{llll} |
| 866 |
\hline |
| 867 |
Alpha & Beta & Gamma & Delta \\ |
| 868 |
\hline[dashed] |
| 869 |
Epsilon & Zeta & Eta & Theta \\ |
| 870 |
\hline[dotted] |
| 871 |
Iota & Kappa & Lambda & Mu \\ |
| 872 |
\hline[2pt,blue5] |
| 873 |
\end{tblr} |
| 874 |
\end{demohigh} |
| 875 |
|
| 876 |
The \CC{\cline} command also has an optional argument which is the same as \CC{\hline}. |
| 877 |
|
| 878 |
\begin{demohigh} |
| 879 |
\begin{tblr}{llll} |
| 880 |
\cline{1-4} |
| 881 |
Alpha & Beta & Gamma & Delta \\ |
| 882 |
\cline[dashed]{1,3} |
| 883 |
Epsilon & Zeta & Eta & Theta \\ |
| 884 |
\cline[dashed]{2,4} |
| 885 |
Iota & Kappa & Lambda & Mu \\ |
| 886 |
\cline[2pt,blue5]{-} |
| 887 |
\end{tblr} |
| 888 |
\end{demohigh} |
| 889 |
|
| 890 |
You can use child selectors in the mandatory argument of \CC{\cline}. |
| 891 |
|
| 892 |
\begin{demohigh} |
| 893 |
\begin{tblr}{llll} |
| 894 |
\cline{1-4} |
| 895 |
Alpha & Beta & Gamma & Delta \\ |
| 896 |
\cline[dashed]{odd} |
| 897 |
Epsilon & Zeta & Eta & Theta \\ |
| 898 |
\cline[dashed]{even} |
| 899 |
Iota & Kappa & Lambda & Mu \\ |
| 900 |
\cline[2pt,blue5]{-} |
| 901 |
\end{tblr} |
| 902 |
\end{demohigh} |
| 903 |
|
| 904 |
Commands \CC{\SetHline} combines the usages of \CC{\hline} and \CC{\cline}: |
| 905 |
|
| 906 |
\begin{demohigh} |
| 907 |
\begin{tblr}{llll} |
| 908 |
\SetHline{1-3}{blue5,1pt} |
| 909 |
Alpha & Beta & Gamma & Delta \\ |
| 910 |
Epsilon & Zeta & Eta & Theta \\ |
| 911 |
Iota & Kappa & Lambda & Mu \\ |
| 912 |
\SetHline{2-4}{teal5,1pt} |
| 913 |
\end{tblr} |
| 914 |
\end{demohigh} |
| 915 |
|
| 916 |
\begin{demohigh} |
| 917 |
\begin{tblr}{llll} |
| 918 |
\SetHline[1]{1-3}{blue5,1pt} |
| 919 |
\SetHline[2]{1-3}{azure5,1pt} |
| 920 |
Alpha & Beta & Gamma & Delta \\ |
| 921 |
Epsilon & Zeta & Eta & Theta \\ |
| 922 |
Iota & Kappa & Lambda & Mu \\ |
| 923 |
\SetHline[1]{2-4}{teal5,1pt} |
| 924 |
\SetHline[2]{2-4}{green5,1pt} |
| 925 |
\end{tblr} |
| 926 |
\end{demohigh} |
| 927 |
|
| 928 |
In fact, table command \CC{\SetHline[<index>]{<columns>}{<styles>}} at the beginning of row \V{i} |
| 929 |
is the same as table option \KV{hline{i}={<index>}{<columns>}{<styles>}}. |
| 930 |
|
| 931 |
Also, table command \CC{\SetHlines[<index>]{<columns>}{<styles>}} at the beginning of some row |
| 932 |
is the same as table option \KV{hlines={<index>}{<columns>}{<styles>}}. |
| 933 |
|
| 934 |
The usages of table commands \CC{\vline}, \CC{\rline}, \CC{\SetVline}, \CC{\SetVlines} |
| 935 |
are similar to those of \CC{\hline}, \CC{\cline}, \CC{\SetHline}, \CC{\SetHlines}, respectively. |
| 936 |
But normally you don't need to use them. |
| 937 |
|
| 938 |
\section{Hborders and vborders} |
| 939 |
|
| 940 |
Options \KK{hborder{i}} and \KK{vborder{j}} are similar to \KK{hline{i}} and \KK{vline{j}}, |
| 941 |
respectively, but they hold border specifications not related to one specific hline and vline. |
| 942 |
All available keys for \KK{hborder{i}} and \KK{vborder{j}} are described in |
| 943 |
Table~\ref{key:hborder} and Table~\ref{key:vborder}. |
| 944 |
|
| 945 |
\begin{spectblr}[ |
| 946 |
caption = {Keys for Hborders}, |
| 947 |
label = {key:hborder}, |
| 948 |
]{} |
| 949 |
Key & Description and Values & Initial Value \\ |
| 950 |
\K{pagebreak} & pagebreak at this position: \V{yes}, \V{no} or \V{auto} |
| 951 |
(See Chapter~\ref{chap:long}) & \V{auto} \\ |
| 952 |
\K{abovespace} & set \V{belowsep} of previous row (see Table \ref{key:row}) & \V{2pt} \\ |
| 953 |
\K{belowspace} & set \V{abovesep} of current row (see Table \ref{key:row}) & \V{2pt} \\ |
| 954 |
\K{abovespace+} & increase \V{belowsep} of previous row & \None \\ |
| 955 |
\K{belowspace+} & increase \V{abovesep} of current row & \None \\ |
| 956 |
\end{spectblr} |
| 957 |
\vspace{-2em} |
| 958 |
\begin{spectblr}[ |
| 959 |
caption = {Keys for Vborders}, |
| 960 |
label = {key:vborder}, |
| 961 |
]{} |
| 962 |
Key & Description and Values & Initial Value \\ |
| 963 |
\K{leftspace} & set \V{rightsep} of previous column (see Table \ref{key:column}) & \V{6pt} \\ |
| 964 |
\K{rightspace} & set \V{leftsep} of current column (see Table \ref{key:column}) & \V{6pt} \\ |
| 965 |
\K{leftspace+} & increase \V{rightsep} of previous column & \None \\ |
| 966 |
\K{rightspace+} & increase \V{leftsep} of current column & \None \\ |
| 967 |
\end{spectblr} |
| 968 |
|
| 969 |
Furthermore, table command \CC{\hborder{<specs>}} at the beginning of row \V{i} |
| 970 |
is the same as table option \KV{hborder{i}={<specs>}}, |
| 971 |
and table command \CC{\vborder{<specs>}} at the beginning of column \V{j} |
| 972 |
is the same as table option \KV{vborder{j}={<specs>}}. |
| 973 |
|
| 974 |
\section{Cells and spancells} |
| 975 |
|
| 976 |
All available keys for cells are described in Table \ref{key:cell} and Table \ref{key:cellspan}. |
| 977 |
|
| 978 |
\begin{spectblr}[ |
| 979 |
caption = {Keys for the Content of Cells}, |
| 980 |
label = {key:cell}, |
| 981 |
remark{Note} = {In most cases, you can omit the underlined key names and write only their values.} |
| 982 |
]{} |
| 983 |
Key & Description and Values & Initial Value \\ |
| 984 |
\underline{\K{halign}} |
| 985 |
& horizontal alignment: \V{l} (left), \V{c} (center), \V{r} (right) or \V{j} (justify) |
| 986 |
& \V{j} \\ |
| 987 |
\underline{\K{valign}} |
| 988 |
& vertical alignment: \V{t} (top), \V{m} (middle), \V{b} (bottom), |
| 989 |
\V{h} (head) or \V{f} (foot) |
| 990 |
& \V{t} \\ |
| 991 |
\underline{\K{wd}} & width dimension & \None \\ |
| 992 |
\underline{\K{bg}} & background color name & \None \\ |
| 993 |
\K{fg} & foreground color name & \None \\ |
| 994 |
\K{font} & font commands & \None \\ |
| 995 |
\K{mode} & set cell mode: \V{math}, \V{imath}, \V{dmath} or \V{text} & \None \\ |
| 996 |
\KK{$} & same as \V{mode=math} & \None \\ |
| 997 |
\KK{$$} & same as \V{mode=dmath} & \None \\ |
| 998 |
\K{cmd} & execute command for the cell text & \None \\ |
| 999 |
\K{preto} & prepend text to the cell & \None \\ |
| 1000 |
\K{appto} & append text to the cell & \None \\ |
| 1001 |
\end{spectblr} |
| 1002 |
\vspace{-2em} |
| 1003 |
\begin{spectblr}[ |
| 1004 |
caption = {Keys for Multispan of Cells}, |
| 1005 |
label = {key:cellspan}, |
| 1006 |
]{} |
| 1007 |
Key & Description and Values & Initial Value \\ |
| 1008 |
\K{r} & number of rows the cell spans & 1 \\ |
| 1009 |
\K{c} & number of columns the cell spans & 1 \\ |
| 1010 |
\end{spectblr} |
| 1011 |
|
| 1012 |
\subsection{Cells and spancells in new interfaces} |
| 1013 |
|
| 1014 |
Option \K{cells} is for setting all cells. |
| 1015 |
\nopagebreak |
| 1016 |
\begin{demohigh} |
| 1017 |
\begin{tblr}{hlines={white},cells={c,blue7}} |
| 1018 |
Alpha & Beta & Gamma & Delta \\ |
| 1019 |
Epsilon & Zeta & Eta & Theta \\ |
| 1020 |
Iota & Kappa & Lambda & Mu \\ |
| 1021 |
Nu & Xi & Omicron & Pi \\ |
| 1022 |
\end{tblr} |
| 1023 |
\end{demohigh} |
| 1024 |
|
| 1025 |
Option \KK{cell{i}{j}} is for setting some cells, |
| 1026 |
where \V{i} stands for the row numbers and \V{j} stands for the column numbers. |
| 1027 |
\nopagebreak |
| 1028 |
\begin{demohigh} |
| 1029 |
\begin{tblr}{ |
| 1030 |
cell{1}{2-4} = {cmd=\fbox} |
| 1031 |
} |
| 1032 |
Alpha & Beta & Gamma & Delta |
| 1033 |
\end{tblr} |
| 1034 |
\end{demohigh} |
| 1035 |
|
| 1036 |
\begin{demohigh} |
| 1037 |
\begin{tblr}{ |
| 1038 |
hlines = {white}, |
| 1039 |
vlines = {white}, |
| 1040 |
cell{1,6}{odd} = {teal7}, |
| 1041 |
cell{1,6}{even} = {green7}, |
| 1042 |
cell{2,4}{1,4} = {red7}, |
| 1043 |
cell{3,5}{1,4} = {purple7}, |
| 1044 |
cell{2}{2} = {r=4,c=2}{c,azure7}, |
| 1045 |
} |
| 1046 |
Alpha & Beta & Gamma & Delta \\ |
| 1047 |
Epsilon & Zeta & Eta & Theta \\ |
| 1048 |
Iota & Kappa & Lambda & Mu \\ |
| 1049 |
Nu & Xi & Omicron & Pi \\ |
| 1050 |
Rho & Sigma & Tau & Upsilon \\ |
| 1051 |
Phi & Chi & Psi & Omega \\ |
| 1052 |
\end{tblr} |
| 1053 |
\end{demohigh} |
| 1054 |
|
| 1055 |
From version 2025A, you can select cells with a list of two dimensional indexes: |
| 1056 |
\begin{demohigh} |
| 1057 |
\begin{tblr}{ |
| 1058 |
cell{{2}{6},{7}{3}} = {bg=blue7}, |
| 1059 |
cell{{1}{1}-{4}{4},{5}{8}-{8}{5}} = {bg=red7} |
| 1060 |
} |
| 1061 |
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ |
| 1062 |
2 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ |
| 1063 |
3 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ |
| 1064 |
4 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ |
| 1065 |
5 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ |
| 1066 |
6 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ |
| 1067 |
7 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ |
| 1068 |
8 & 2 & 3 & 4 & 5 & 6 & 7 & 8 |
| 1069 |
\end{tblr} |
| 1070 |
\end{demohigh} |
| 1071 |
In this example, \TT{-} characters are used for diagonal selection. |
| 1072 |
|
| 1073 |
\subsection{Cells and spancells in old interfaces} |
| 1074 |
|
| 1075 |
The \CC{\SetCell} command has a mandatory argument for setting the styles of current cell. |
| 1076 |
The available keys are described in Table \ref{key:cell}. |
| 1077 |
|
| 1078 |
\begin{demohigh} |
| 1079 |
\begin{tblr}{llll} |
| 1080 |
\hline[1pt] |
| 1081 |
Alpha & \SetCell{bg=teal2,fg=white} Beta & Gamma \\ |
| 1082 |
\hline |
| 1083 |
Epsilon & Zeta & \SetCell{r,font=\scshape} Eta \\ |
| 1084 |
\hline |
| 1085 |
Iota & Kappa & Lambda \\ |
| 1086 |
\hline[1pt] |
| 1087 |
\end{tblr} |
| 1088 |
\end{demohigh} |
| 1089 |
|
| 1090 |
The \CC{\SetCell} command also has an optional argument for setting the multispan of current cell. |
| 1091 |
The available keys are described in Table \ref{key:cellspan}. |
| 1092 |
|
| 1093 |
\begin{demohigh} |
| 1094 |
\begin{tblr}{|X|X|X|X|X|X|} |
| 1095 |
\hline |
| 1096 |
Alpha & Beta & Gamma & Delta & Epsilon & Zeta \\ |
| 1097 |
\hline |
| 1098 |
\SetCell[c=2]{c} Eta & 2-2 |
| 1099 |
& \SetCell[c=2]{c} Iota & 2-4 |
| 1100 |
& \SetCell[c=2]{c} Lambda & 2-6 \\ |
| 1101 |
\hline |
| 1102 |
\SetCell[c=3]{c} Nu & 3-2 & 3-3 |
| 1103 |
& \SetCell[c=3]{c} Pi & 3-5 & 3-6 \\ |
| 1104 |
\hline |
| 1105 |
\SetCell[c=6]{c} Tau & 4-2 & 4-3 & 4-4 & 4-5 & 4-6 \\ |
| 1106 |
\hline |
| 1107 |
\end{tblr} |
| 1108 |
\end{demohigh} |
| 1109 |
|
| 1110 |
\begin{demohigh} |
| 1111 |
\begin{tblr}{|X|X|X|X|X|X|} |
| 1112 |
\hline |
| 1113 |
Alpha & Beta & Gamma & Delta & Epsilon & Zeta \\ |
| 1114 |
\hline |
| 1115 |
\SetCell[r=2]{m} Eta |
| 1116 |
& Theta & Iota & Kappa & Lambda & \SetCell[r=2]{m} Mu \\ |
| 1117 |
\hline |
| 1118 |
Nu & Xi & Omicron & Pi & Rho & Sigma \\ |
| 1119 |
\hline |
| 1120 |
\end{tblr} |
| 1121 |
\end{demohigh} |
| 1122 |
|
| 1123 |
In fact, table command \CC{\SetCell[<span>]{<styles>}} at the beginning of cell at row \V{i} |
| 1124 |
and column \V{j} is the same as table option \KV{cell{i}{j}={<span>}{<styles>}}. |
| 1125 |
|
| 1126 |
Also, table command \CC{\SetCells[<span>]{<styles>}} at the beginning of some cell |
| 1127 |
is the same as table option \KV{cells={<span>}{<styles>}}. |
| 1128 |
|
| 1129 |
\section{Rows and columns} |
| 1130 |
|
| 1131 |
All available keys for rows and columns are described in Table \ref{key:row} and Table \ref{key:column}. |
| 1132 |
|
| 1133 |
\begin{spectblr}[ |
| 1134 |
caption = {Keys for Rows}, |
| 1135 |
label = {key:row}, |
| 1136 |
remark{Note} = {In most cases, you can omit the underlined key names and write only their values.} |
| 1137 |
]{} |
| 1138 |
Key & Description and Values & Initial Value \\ |
| 1139 |
\underline{\K{halign}} |
| 1140 |
& horizontal alignment: \V{l} (left), \V{c} (center), \V{r} (right) or \V{j} (justify) |
| 1141 |
& \V{j} \\ |
| 1142 |
\underline{\K{valign}} |
| 1143 |
& vertical alignment: \V{t} (top), \V{m} (middle), \V{b} (bottom), |
| 1144 |
\V{h} (head) or \V{f} (foot) |
| 1145 |
& \V{t} \\ |
| 1146 |
\underline{\K{ht}} & height dimension & \None \\ |
| 1147 |
\underline{\K{bg}} & background color name & \None \\ |
| 1148 |
\K{fg} & foreground color name & \None \\ |
| 1149 |
\K{font} & font commands & \None \\ |
| 1150 |
\K{mode} & set mode for row cells: \V{math}, \V{imath}, \V{dmath} or \V{text} & \None \\ |
| 1151 |
\KK{$} & same as \V{mode=math} & \None \\ |
| 1152 |
\KK{$$} & same as \V{mode=dmath} & \None \\ |
| 1153 |
\K{cmd} & execute command for every cell text & \None \\ |
| 1154 |
\K{abovesep} & set vertical space above the row & \V{2pt} \\ |
| 1155 |
\K{abovesep+} & increase vertical space above the row & \None \\ |
| 1156 |
\K{belowsep} & set vertical space below the row & \V{2pt} \\ |
| 1157 |
\K{belowsep+} & increase vertical space below the row & \None \\ |
| 1158 |
\K{rowsep} & set vertical space above and below the row & \V{2pt} \\ |
| 1159 |
\K{rowsep+} & increase vertical space above and below the row & \None \\ |
| 1160 |
\K{preto} & prepend text to every cell (like \V{>} specifier in \K{rowspec}) & \None \\ |
| 1161 |
\K{appto} & append text to every cell (like \V{<} specifier in \K{rowspec}) & \None \\ |
| 1162 |
\end{spectblr} |
| 1163 |
\vspace{-2em} |
| 1164 |
\begin{spectblr}[ |
| 1165 |
caption = {Keys for Columns}, |
| 1166 |
label = {key:column}, |
| 1167 |
remark{Note} = {In most cases, you can omit the underlined key names and write only their values.} |
| 1168 |
]{} |
| 1169 |
Key & Description and Values & Initial Value \\ |
| 1170 |
\underline{\K{halign}} |
| 1171 |
& horizontal alignment: \V{l} (left), \V{c} (center), \V{r} (right) or \V{j} (justify) |
| 1172 |
& \V{j} \\ |
| 1173 |
\underline{\K{valign}} |
| 1174 |
& vertical alignment: \V{t} (top), \V{m} (middle), \V{b} (bottom), |
| 1175 |
\V{h} (head) or \V{f} (foot) |
| 1176 |
& \V{t} \\ |
| 1177 |
\underline{\K{wd}} & width dimension & \None \\ |
| 1178 |
\underline{\K{co}} & coefficient for the extendable column (\V{X} column) & \None \\ |
| 1179 |
\underline{\K{bg}} & background color name & \None \\ |
| 1180 |
\K{fg} & foreground color name & \None \\ |
| 1181 |
\K{font} & font commands & \None \\ |
| 1182 |
\K{mode} & set mode for column cells: \V{math}, \V{imath}, \V{dmath} or \V{text} & \None \\ |
| 1183 |
\KK{$} & same as \V{mode=math} & \None \\ |
| 1184 |
\KK{$$} & same as \V{mode=dmath} & \None \\ |
| 1185 |
\K{cmd} & execute command for every cell text & \None \\ |
| 1186 |
\K{leftsep} & set horizontal space to the left of the column & \V{6pt} \\ |
| 1187 |
\K{leftsep+} & increase horizontal space to the left of the column & \None \\ |
| 1188 |
\K{rightsep} & set horizontal space to the right of the column & \V{6pt} \\ |
| 1189 |
\K{rightsep+} & increase horizontal space to the right of the column & \None \\ |
| 1190 |
\K{colsep} & set horizontal space to both sides of the column & \V{6pt} \\ |
| 1191 |
\K{colsep+} & increase horizontal space to both sides of the column & \None \\ |
| 1192 |
\K{preto} & prepend text to every cell (like \V{>} specifier in \K{colspec}) & \None \\ |
| 1193 |
\K{appto} & append text to every cell (like \V{<} specifier in \K{colspec}) & \None \\ |
| 1194 |
\end{spectblr} |
| 1195 |
|
| 1196 |
\subsection{Rows and columns in new interfaces} |
| 1197 |
|
| 1198 |
Options \K{rows} and \K{columns} are for setting all rows and columns, respectively. |
| 1199 |
\nopagebreak |
| 1200 |
\begin{demohigh} |
| 1201 |
\begin{tblr}{ |
| 1202 |
hlines, vlines, |
| 1203 |
rows = {7mm}, columns = {15mm,c}, |
| 1204 |
} |
| 1205 |
Alpha & Beta & Gamma & Delta \\ |
| 1206 |
Epsilon & Zeta & Eta & Theta \\ |
| 1207 |
Iota & Kappa & Lambda & Mu \\ |
| 1208 |
\end{tblr} |
| 1209 |
\end{demohigh} |
| 1210 |
|
| 1211 |
Options \KK{row{i}} and \KK{column{j}} are for setting some rows and columns, respectively. |
| 1212 |
|
| 1213 |
\begin{demohigh} |
| 1214 |
\begin{tblr}{ |
| 1215 |
hlines = {1pt,white}, |
| 1216 |
row{odd} = {blue7}, |
| 1217 |
row{even} = {azure7}, |
| 1218 |
column{1} = {purple7,c}, |
| 1219 |
} |
| 1220 |
Alpha & Beta & Gamma & Delta \\ |
| 1221 |
Epsilon & Zeta & Eta & Theta \\ |
| 1222 |
Iota & Kappa & Lambda & Mu \\ |
| 1223 |
Nu & Xi & Omicron & Pi \\ |
| 1224 |
Rho & Sigma & Tau & Upsilon \\ |
| 1225 |
Phi & Chi & Psi & Omega \\ |
| 1226 |
\end{tblr} |
| 1227 |
\end{demohigh} |
| 1228 |
|
| 1229 |
The following example demonstrates the usages of \K{bg}, \K{fg} and \K{font} keys: |
| 1230 |
\nopagebreak |
| 1231 |
\begin{demohigh} |
| 1232 |
\begin{tblr}{ |
| 1233 |
row{odd} = {bg=azure8}, |
| 1234 |
row{1} = {bg=azure3, fg=white, font=\sffamily}, |
| 1235 |
} |
| 1236 |
Alpha & Beta & Gamma \\ |
| 1237 |
Delta & Epsilon & Zeta \\ |
| 1238 |
Eta & Theta & Iota \\ |
| 1239 |
Kappa & Lambda & Mu \\ |
| 1240 |
Nu Xi Omicron & Pi Rho Sigma & Tau Upsilon Phi \\ |
| 1241 |
\end{tblr} |
| 1242 |
\end{demohigh} |
| 1243 |
|
| 1244 |
The following example demonstrates the usages of \K{mode} key: |
| 1245 |
\nopagebreak |
| 1246 |
\begin{demohigh} |
| 1247 |
$\begin{tblr}{ |
| 1248 |
column{1} = {mode=text}, |
| 1249 |
column{3} = {mode=dmath}, |
| 1250 |
} |
| 1251 |
\hline |
| 1252 |
Alpha & \frac12 & \frac12 \\ |
| 1253 |
Epsilon & \frac34 & \frac34 \\ |
| 1254 |
Iota & \frac56 & \frac56 \\ |
| 1255 |
\hline |
| 1256 |
\end{tblr}$ |
| 1257 |
\end{demohigh} |
| 1258 |
Note that you \emph{can not} write multiline math directly (such as \TT{\alpha\ \\\\ \beta}) |
| 1259 |
in any math-mode cell. |
| 1260 |
|
| 1261 |
The following example demonstrates the usages of |
| 1262 |
\K{abovesep}, \K{belowsep}, \K{leftsep}, \K{rightsep} keys: |
| 1263 |
%\nopagebreak |
| 1264 |
\begin{demohigh} |
| 1265 |
\begin{tblr}{ |
| 1266 |
hlines, vlines, |
| 1267 |
rows = {abovesep=1pt,belowsep=5pt}, |
| 1268 |
columns = {leftsep=1pt,rightsep=5pt}, |
| 1269 |
} |
| 1270 |
Alpha & Beta & Gamma & Delta \\ |
| 1271 |
Epsilon & Zeta & Eta & Theta \\ |
| 1272 |
Iota & Kappa & Lambda & Mu \\ |
| 1273 |
\end{tblr} |
| 1274 |
\end{demohigh} |
| 1275 |
|
| 1276 |
The following example shows that we can replace \CC{\\\\[dimen]} with \K{belowsep+} key. |
| 1277 |
|
| 1278 |
\begin{demohigh} |
| 1279 |
\begin{tblr}{ |
| 1280 |
hlines, row{2} = {belowsep+=5pt}, |
| 1281 |
} |
| 1282 |
Alpha & Beta & Gamma & Delta \\ |
| 1283 |
Epsilon & Zeta & Eta & Theta \\ |
| 1284 |
Iota & Kappa & Lambda & Mu \\ |
| 1285 |
\end{tblr} |
| 1286 |
\end{demohigh} |
| 1287 |
|
| 1288 |
\subsection{Rows and columns in old interfaces} |
| 1289 |
|
| 1290 |
The \CC{\SetRow} command has a mandatory argument for setting the styles of current row. |
| 1291 |
The available keys are described in Table \ref{key:row}. |
| 1292 |
|
| 1293 |
\begin{demohigh} |
| 1294 |
\begin{tblr}{llll} |
| 1295 |
\hline[1pt] |
| 1296 |
\SetRow{azure8} Alpha & Beta & Gamma & Delta \\ |
| 1297 |
\hline |
| 1298 |
\SetRow{blue8,c} Epsilon & Zeta & Eta & Theta \\ |
| 1299 |
\hline |
| 1300 |
\SetRow{violet8} Iota & Kappa & Lambda & Mu \\ |
| 1301 |
\hline[1pt] |
| 1302 |
\end{tblr} |
| 1303 |
\end{demohigh} |
| 1304 |
|
| 1305 |
In fact, table command \CC{\SetRow{<styles>}} at the beginning of row \V{i} |
| 1306 |
is the same as table option \KV{row{i}={<styles>}}. |
| 1307 |
|
| 1308 |
Also, table command \CC{\SetRows{<styles>}} at the beginning of some row |
| 1309 |
is the same as table option \KV{rows={<styles>}}. |
| 1310 |
|
| 1311 |
The usages of table commands \CC{\SetColumn} and \CC{\SetColumns} |
| 1312 |
are similar to those of \CC{\SetRow} and \CC{\SetRows}, respectively. |
| 1313 |
But normally you don't need to use them. |
| 1314 |
|
| 1315 |
\section{Colspec and rowspec} |
| 1316 |
|
| 1317 |
Options \K{colspec}/\K{rowspec} are for setting column/row specifications |
| 1318 |
with column/row type specifiers. |
| 1319 |
|
| 1320 |
\subsection{Colspec and width} |
| 1321 |
|
| 1322 |
Option \K{width} is for setting the width of the table with extendable columns. |
| 1323 |
The following example demonstrates the usage of \K{width} option. |
| 1324 |
\nopagebreak |
| 1325 |
\begin{demohigh} |
| 1326 |
\begin{tblr}{width=0.8\textwidth, colspec={|l|X[2]|X[3]|X[-1]|}} |
| 1327 |
Alpha & Beta & Gamma & Delta \\ |
| 1328 |
Epsilon & Zeta & Eta & Theta \\ |
| 1329 |
Iota & Kappa & Lambda & Mu \\ |
| 1330 |
\end{tblr} |
| 1331 |
\end{demohigh} |
| 1332 |
|
| 1333 |
You can omit \K{colspec} name if it is the only key you use inside the mandatory argument. |
| 1334 |
The following example demonstrates the usages of \KK{$} and \KK{$$} keys: |
| 1335 |
\nopagebreak |
| 1336 |
\begin{demohigh} |
| 1337 |
\begin{tblr}{Q[l]Q[r,$]Q[r,$$]} |
| 1338 |
\hline |
| 1339 |
Alpha & \frac12 & \frac12 \\ |
| 1340 |
Epsilon & \frac34 & \frac34 \\ |
| 1341 |
Iota & \frac56 & \frac56 \\ |
| 1342 |
\hline |
| 1343 |
\end{tblr} |
| 1344 |
\end{demohigh} |
| 1345 |
|
| 1346 |
\subsection{Column types} |
| 1347 |
|
| 1348 |
The \PP{tabularray} package has only one type of primitive column: the \Q{Q} column. |
| 1349 |
Other types of columns are defined as \Q{Q} columns with some keys. |
| 1350 |
|
| 1351 |
\begin{codehigh} |
| 1352 |
\NewTblrColumnType{l}{Q[l]} |
| 1353 |
\NewTblrColumnType{c}{Q[c]} |
| 1354 |
\NewTblrColumnType{r}{Q[r]} |
| 1355 |
\NewTblrColumnType{t}[1]{Q[t,wd=#1]} |
| 1356 |
\NewTblrColumnType{m}[1]{Q[m,wd=#1]} |
| 1357 |
\NewTblrColumnType{b}[1]{Q[b,wd=#1]} |
| 1358 |
\NewTblrColumnType{h}[1]{Q[h,wd=#1]} |
| 1359 |
\NewTblrColumnType{f}[1]{Q[f,wd=#1]} |
| 1360 |
\NewTblrColumnType{X}[1][]{Q[co=1,#1]} |
| 1361 |
\end{codehigh} |
| 1362 |
|
| 1363 |
\begin{demohigh} |
| 1364 |
\begin{tblr}{|t{15mm}|m{15mm}|b{20mm}|} |
| 1365 |
Alpha & Beta & {Gamma\\Gamma} \\ |
| 1366 |
Epsilon & Zeta & {Eta\\Eta} \\ |
| 1367 |
Iota & Kappa & {Lambda\\Lambda} \\ |
| 1368 |
\end{tblr} |
| 1369 |
\end{demohigh} |
| 1370 |
|
| 1371 |
Any new column type must be defined with \CC{\NewTblrColumnType} command. |
| 1372 |
It can have an optional argument when it's defined. |
| 1373 |
|
| 1374 |
\subsection{Row types} |
| 1375 |
|
| 1376 |
The \PP{tabularray} package has only one type of primitive row: the \Q{Q} row. |
| 1377 |
Other types of rows are defined as \Q{Q} rows with some keys. |
| 1378 |
|
| 1379 |
\begin{codehigh} |
| 1380 |
\NewTblrRowType{l}{Q[l]} |
| 1381 |
\NewTblrRowType{c}{Q[c]} |
| 1382 |
\NewTblrRowType{r}{Q[r]} |
| 1383 |
\NewTblrRowType{t}[1]{Q[t,ht=#1]} |
| 1384 |
\NewTblrRowType{m}[1]{Q[m,ht=#1]} |
| 1385 |
\NewTblrRowType{b}[1]{Q[b,ht=#1]} |
| 1386 |
\NewTblrRowType{h}[1]{Q[h,ht=#1]} |
| 1387 |
\NewTblrRowType{f}[1]{Q[f,ht=#1]} |
| 1388 |
\end{codehigh} |
| 1389 |
|
| 1390 |
\begin{demohigh} |
| 1391 |
\begin{tblr}{rowspec={|t{12mm}|m{10mm}|b{10mm}|}} |
| 1392 |
Alpha & Beta & {Gamma\\Gamma} \\ |
| 1393 |
Epsilon & Zeta & {Eta\\Eta} \\ |
| 1394 |
Iota & Kappa & {Lambda\\Lambda} \\ |
| 1395 |
\end{tblr} |
| 1396 |
\end{demohigh} |
| 1397 |
|
| 1398 |
Any new row type must be defined with \CC{\NewTblrRowType} command. |
| 1399 |
It can have an optional argument when it's defined. |
| 1400 |
|
| 1401 |
\chapter{Extra Interfaces} |
| 1402 |
\label{chap:extra} |
| 1403 |
|
| 1404 |
In general, \EE{tblr} environment accepts both inner and outer specifications: |
| 1405 |
|
| 1406 |
\begin{codehigh} |
| 1407 |
\begin{tblr}[<outer specs>]{<inner specs>} |
| 1408 |
<table body> |
| 1409 |
\end{tblr} |
| 1410 |
\end{codehigh} |
| 1411 |
|
| 1412 |
\textbf{Inner specifications} are all specifications written in the \underline{mandatory} argument |
| 1413 |
of \EE{tblr} environment, which include new interfaces described in Chapter \ref{chap:basic}. |
| 1414 |
|
| 1415 |
\textbf{Outer specifications} are all specifications written in the \underline{optional} argument |
| 1416 |
of \EE{tblr} environment, most of which are used for long tables (see Chapter \ref{chap:long}). |
| 1417 |
|
| 1418 |
You can use \CC{\SetTblrInner} and \CC{\SetTblrOuter} commands |
| 1419 |
to set default inner and outer specifications of tables, respectively (see Section \ref{sec:default}). |
| 1420 |
|
| 1421 |
\section{Inner specifications} |
| 1422 |
|
| 1423 |
In addition to new interfaces in Chapter \ref{chap:basic}, |
| 1424 |
there are several inner specifications which are described in Table~\ref{key:inner}. |
| 1425 |
|
| 1426 |
\begin{spectblr}[ |
| 1427 |
caption = {Keys for Inner Specifications}, |
| 1428 |
label = {key:inner}, |
| 1429 |
]{} |
| 1430 |
Key & Description and Values & Initial Value \\ |
| 1431 |
\K{rulesep} & space between two hlines or vlines & \V{2pt} \\ |
| 1432 |
\K{stretch} & stretch ratio for struts added to cell text & \V{1} \\ |
| 1433 |
\K{abovesep} & set vertical space above every row & \V{2pt} \\ |
| 1434 |
\K{belowsep} & set vertical space below every row & \V{2pt} \\ |
| 1435 |
\K{rowsep} & set vertical space above and below every row & \V{2pt} \\ |
| 1436 |
\K{leftsep} & set horizontal space to the left of every column & \V{6pt} \\ |
| 1437 |
\K{rightsep} & set horizontal space to the right of every column & \V{6pt} \\ |
| 1438 |
\K{colsep} & set horizontal space to both sides of every column & \V{6pt} \\ |
| 1439 |
\K{hspan} & horizontal span algorithm: \V{default}, \V{even}, or \V{minimal} & \V{default} \\ |
| 1440 |
\K{vspan} & vertical span algorithm: \V{default} or \V{even} & \V{default} \\ |
| 1441 |
%\K{verb} & you need this key to use verb commands & \None \\ |
| 1442 |
\K{baseline} & set the baseline of the table & \V{m} \\ |
| 1443 |
\end{spectblr} |
| 1444 |
|
| 1445 |
\subsection{Space between double rules} |
| 1446 |
|
| 1447 |
The following example shows that we can replace \CC{\doublerulesep} parameter with \K{rulesep} key. |
| 1448 |
\nopagebreak |
| 1449 |
\begin{demohigh} |
| 1450 |
\begin{tblr}{ |
| 1451 |
colspec={||llll||},rowspec={|QQQ|},rulesep=4pt, |
| 1452 |
} |
| 1453 |
Alpha & Beta & Gamma & Delta \\ |
| 1454 |
Epsilon & Zeta & Eta & Theta \\ |
| 1455 |
Iota & Kappa & Lambda & Mu \\ |
| 1456 |
\end{tblr} |
| 1457 |
\end{demohigh} |
| 1458 |
|
| 1459 |
\subsection{Minimal strut for cell text} |
| 1460 |
|
| 1461 |
The following example shows that we can replace \CC{\arraystretch} parameter with \K{stretch} key. |
| 1462 |
|
| 1463 |
\begin{demohigh} |
| 1464 |
\begin{tblr}{hlines,stretch=1.5} |
| 1465 |
Alpha & Beta & Gamma & Delta \\ |
| 1466 |
Epsilon & Zeta & Eta & Theta \\ |
| 1467 |
Iota & Kappa & Lambda & Mu \\ |
| 1468 |
\end{tblr} |
| 1469 |
\end{demohigh} |
| 1470 |
|
| 1471 |
By replacing stretch with row heights, we can get perfect vertical centering for your numerical tables. |
| 1472 |
|
| 1473 |
\begin{demohigh} |
| 1474 |
\begin{tblr}{hlines, stretch=0, rows={ht=\baselineskip}} |
| 1475 |
2021 & 2022 & 2023 \\ |
| 1476 |
0.4 & 0.5 & 0.6 \\ |
| 1477 |
1.1 & 2.2 & 3.3 \\ |
| 1478 |
\end{tblr} |
| 1479 |
\end{demohigh} |
| 1480 |
|
| 1481 |
\subsection{Rowseps and colseps for all} |
| 1482 |
|
| 1483 |
The following example uses \K{rowsep} and \K{colsep} keys to set padding for all rows and columns. |
| 1484 |
\nopagebreak |
| 1485 |
\begin{demohigh} |
| 1486 |
\SetTblrInner{rowsep=2pt,colsep=2pt} |
| 1487 |
\begin{tblr}{hlines,vlines} |
| 1488 |
Alpha & Beta & Gamma & Delta \\ |
| 1489 |
Epsilon & Zeta & Eta & Theta \\ |
| 1490 |
Iota & Kappa & Lambda & Mu \\ |
| 1491 |
\end{tblr} |
| 1492 |
\end{demohigh} |
| 1493 |
|
| 1494 |
\subsection{Hspan and vspan algorithms} |
| 1495 |
|
| 1496 |
With \KV{hspan=default} or \KV{hspan=even}, |
| 1497 |
\PP{tabularray} package will compute column widths from span widths. |
| 1498 |
But with \KV{hspan=minimal}, it will compute span widths from column widths. |
| 1499 |
The following examples show the results from different \K{hspan} values. |
| 1500 |
|
| 1501 |
\begin{demohigh} |
| 1502 |
\SetTblrInner{hlines, vlines, hspan=default} |
| 1503 |
\begin{tblr}{cell{2}{1}={c=2}{l},cell{3}{1}={c=3}{l},cell{4}{2}={c=2}{l}} |
| 1504 |
111 111 & 222 222 & 333 333 \\ |
| 1505 |
12 Multi Columns Multi Columns 12 & & 333 \\ |
| 1506 |
13 Multi Columns Multi Columns Multi Columns 13 & & \\ |
| 1507 |
111 & 23 Multi Columns Multi Columns 23 & \\ |
| 1508 |
\end{tblr} |
| 1509 |
\end{demohigh} |
| 1510 |
|
| 1511 |
\begin{demohigh} |
| 1512 |
\SetTblrInner{hlines, vlines, hspan=even} |
| 1513 |
\begin{tblr}{cell{2}{1}={c=2}{l},cell{3}{1}={c=3}{l},cell{4}{2}={c=2}{l}} |
| 1514 |
111 111 & 222 222 & 333 333 \\ |
| 1515 |
12 Multi Columns Multi Columns 12 & & 333 \\ |
| 1516 |
13 Multi Columns Multi Columns Multi Columns 13 & & \\ |
| 1517 |
111 & 23 Multi Columns Multi Columns 23 & \\ |
| 1518 |
\end{tblr} |
| 1519 |
\end{demohigh} |
| 1520 |
|
| 1521 |
\begin{demohigh} |
| 1522 |
\SetTblrInner{hlines, vlines, hspan=minimal} |
| 1523 |
\begin{tblr}{cell{2}{1}={c=2}{l},cell{3}{1}={c=3}{l},cell{4}{2}={c=2}{l}} |
| 1524 |
111 111 & 222 222 & 333 333 \\ |
| 1525 |
12 Multi Columns Multi Columns 12 & & 333 \\ |
| 1526 |
13 Multi Columns Multi Columns Multi Columns 13 & & \\ |
| 1527 |
111 & 23 Multi Columns Multi Columns 23 & \\ |
| 1528 |
\end{tblr} |
| 1529 |
\end{demohigh} |
| 1530 |
|
| 1531 |
The following examples show the results from different \K{vspan} values. |
| 1532 |
\nopagebreak |
| 1533 |
\begin{demohigh} |
| 1534 |
\SetTblrInner{hlines, vlines, vspan=default} |
| 1535 |
\begin{tblr}{column{2}={3.25cm}, cell{2}{2}={r=3}{l}} |
| 1536 |
Column1 & Column2 \\ |
| 1537 |
Row1 & Long text that needs multiple lines. |
| 1538 |
Long text that needs multiple lines. |
| 1539 |
Long text that needs multiple lines. \\ |
| 1540 |
Row2 & \\ |
| 1541 |
Row3 & \\ |
| 1542 |
Row4 & Short text \\ |
| 1543 |
\end{tblr} |
| 1544 |
\end{demohigh} |
| 1545 |
|
| 1546 |
\begin{demohigh} |
| 1547 |
\SetTblrInner{hlines, vlines, vspan=even} |
| 1548 |
\begin{tblr}{column{2}={3.25cm}, cell{2}{2}={r=3}{l}} |
| 1549 |
Column1 & Column2 \\ |
| 1550 |
Row1 & Long text that needs multiple lines. |
| 1551 |
Long text that needs multiple lines. |
| 1552 |
Long text that needs multiple lines. \\ |
| 1553 |
Row2 & \\ |
| 1554 |
Row3 & \\ |
| 1555 |
Row4 & Short text \\ |
| 1556 |
\end{tblr} |
| 1557 |
\end{demohigh} |
| 1558 |
|
| 1559 |
\subsection{Set baseline for the table} |
| 1560 |
|
| 1561 |
With \K{baseline} key, you can set baseline for the table. |
| 1562 |
All possible values for \K{baseline} are as follows: |
| 1563 |
|
| 1564 |
\begin{center} |
| 1565 |
\begin{tblr}{width=0.6\textwidth,colspec={cX[l]},hlines} |
| 1566 |
\V{t} & align the table at the top \\ |
| 1567 |
\V{T} & align the table at the first row \\ |
| 1568 |
\V{m} & align the table at the middle, initial value \\ |
| 1569 |
\V{b} & align the table at the bottom \\ |
| 1570 |
\V{B} & align the table at the last row \\ |
| 1571 |
\V{<n>} & align the table at row \V{<n>} (a positive integer) \\ |
| 1572 |
\end{tblr} |
| 1573 |
\end{center} |
| 1574 |
|
| 1575 |
If there is no hline above the first row, you get the same result with either \V{t} or \V{T}. |
| 1576 |
But you get different results if there are one or more hlines above the row: |
| 1577 |
|
| 1578 |
\begin{demohigh} |
| 1579 |
Baseline\begin{tblr}{hlines,baseline=t} |
| 1580 |
Alpha & Beta & Gamma \\ |
| 1581 |
Epsilon & Zeta & Eta \\ |
| 1582 |
Iota & Kappa & Lambda \\ |
| 1583 |
\end{tblr}Baseline |
| 1584 |
\end{demohigh} |
| 1585 |
|
| 1586 |
\begin{demohigh} |
| 1587 |
Baseline\begin{tblr}{hlines,baseline=T} |
| 1588 |
Alpha & Beta & Gamma \\ |
| 1589 |
Epsilon & Zeta & Eta \\ |
| 1590 |
Iota & Kappa & Lambda \\ |
| 1591 |
\end{tblr}Baseline |
| 1592 |
\end{demohigh} |
| 1593 |
|
| 1594 |
The differences between \V{b} and \V{B} are similar to \V{t} and \V{T}. |
| 1595 |
In fact, these two values \V{T} and \V{B} are better replacements |
| 1596 |
for currently obsolete \CC{\firsthline} and \CC{\lasthline} commands. |
| 1597 |
|
| 1598 |
\section{Outer specifications} |
| 1599 |
|
| 1600 |
Except for specifications to be introduced in Chapter \ref{chap:long}, |
| 1601 |
there are several other outer specifications which are described in Table~\ref{key:outer}. |
| 1602 |
|
| 1603 |
\begin{spectblr}[ |
| 1604 |
caption = {Keys for Outer Specifications}, |
| 1605 |
label = {key:outer}, |
| 1606 |
]{} |
| 1607 |
Key & Description and Values & Initial Value \\ |
| 1608 |
\K{baseline} & set the baseline of the table & \V{m} \\ |
| 1609 |
\K{long} & change the table to a long table & \None \\ |
| 1610 |
\K{tall} & change the table to a tall table & \None \\ |
| 1611 |
\K{expand} & you need this key to use verb commands & \None \\ |
| 1612 |
\K{expand+} & like \K{expand} but appends to previous values & \None \\ |
| 1613 |
\end{spectblr} |
| 1614 |
|
| 1615 |
\subsection{Set baseline in another way} |
| 1616 |
|
| 1617 |
You may notice that you can write \K{baseline} option as either an inner or an outer specification. |
| 1618 |
It is true that either way would do the job. But there is a small difference: |
| 1619 |
when \KV{baseline=t/T/m/b/B} is an outer specification, |
| 1620 |
you can omit the key name and write the value only. |
| 1621 |
|
| 1622 |
\begin{demohigh} |
| 1623 |
Baseline\begin{tblr}[m]{hlines} |
| 1624 |
Alpha & Beta & Gamma \\ |
| 1625 |
Epsilon & Zeta & Eta \\ |
| 1626 |
Iota & Kappa & Lambda \\ |
| 1627 |
\end{tblr}Baseline |
| 1628 |
\end{demohigh} |
| 1629 |
|
| 1630 |
\subsection{Long and tall tables} |
| 1631 |
|
| 1632 |
You can change a table to long table by passing outer specification \K{long}, |
| 1633 |
or change it to tall table by passing outer specification \K{tall} (see Chapter~\ref{chap:long}). |
| 1634 |
Therefore the following two tables are the same: |
| 1635 |
\begin{codehigh} |
| 1636 |
\begin{longtblr}{lcr} |
| 1637 |
Alpha & Beta & Gamma |
| 1638 |
\end{longtblr} |
| 1639 |
\begin{tblr}[long]{lcr} |
| 1640 |
Alpha & Beta & Gamma |
| 1641 |
\end{tblr} |
| 1642 |
\end{codehigh} |
| 1643 |
|
| 1644 |
\subsection{Expand macros first} |
| 1645 |
|
| 1646 |
In contrast to traditional \EE{tabular} environment, \PP{tabularray} environments |
| 1647 |
need to see every \TT{&} and \TT{\\\\} when splitting the table body. |
| 1648 |
And you can not put cell text inside any table command defined with \CC{\NewTblrTableCommand}. |
| 1649 |
But you could use outer key \K{expand} to make \PP{tabularray} expand |
| 1650 |
every occurrence of any of the specified macros \emph{once} and in the given order before splitting the table body. |
| 1651 |
Note that you \emph{can not} expand a command defined with \CC{\NewDocumentCommand}. |
| 1652 |
You can also use \K{expand+} if you still want to keep the macros in the current \K{expand} setting. |
| 1653 |
|
| 1654 |
To expand a command without optional argument, you can define it with \CC{\newcommand}. |
| 1655 |
|
| 1656 |
\begin{demohigh} |
| 1657 |
\newcommand*\tblrrowa{ |
| 1658 |
20 & 30 & 40 \\ |
| 1659 |
} |
| 1660 |
\newcommand*\tblrrowb{ |
| 1661 |
50 & 60 & 70 \\ |
| 1662 |
} |
| 1663 |
\newcommand*\tblrbody{ |
| 1664 |
\hline |
| 1665 |
\tblrrowa |
| 1666 |
\tblrrowb |
| 1667 |
\hline |
| 1668 |
} |
| 1669 |
\SetTblrOuter{expand=\tblrbody\tblrrowa} |
| 1670 |
\begin{tblr}[expand+=\tblrrowb]{ccc} |
| 1671 |
\hline |
| 1672 |
AA & BB & CC \\ |
| 1673 |
\tblrbody |
| 1674 |
DD & EE & FF \\ |
| 1675 |
\tblrbody |
| 1676 |
GG & HH & II \\ |
| 1677 |
\hline |
| 1678 |
\end{tblr} |
| 1679 |
\end{demohigh} |
| 1680 |
|
| 1681 |
To expand commands with optional arguments, you \emph{can not} define them |
| 1682 |
with \CC{\newcommand}. But you can define them with \CC{\NewExpandableDocumentCommand}, |
| 1683 |
and use option \KV{expand=\expanded} to do exhaustive expansions. |
| 1684 |
|
| 1685 |
\begin{demohigh} |
| 1686 |
\NewExpandableDocumentCommand\yes{O{Yes}m}{\SetCell{bg=green9}#1} |
| 1687 |
\NewExpandableDocumentCommand\no{O{No}m}{\SetCell{bg=red9}#1} |
| 1688 |
\begin{tblr}[expand=\expanded]{hlines} |
| 1689 |
What I get & is below \\ |
| 1690 |
\expanded{\yes{}} & \expanded{\no{}} \\ |
| 1691 |
\expanded{\yes[Great]{}} & \expanded{\no[Bad]{}} |
| 1692 |
\end{tblr} |
| 1693 |
\end{demohigh} |
| 1694 |
|
| 1695 |
Note that you need to protect fragile commands (if any) inside them with \CC{\unexpanded} command. |
| 1696 |
|
| 1697 |
\section{Default specifications}% |
| 1698 |
\label{sec:default} |
| 1699 |
|
| 1700 |
\PP{Tabularray} package provides \CC{\SetTblrInner} and \CC{\SetTblrOuter} commands |
| 1701 |
for you to change the default inner and outer specifications of tables. |
| 1702 |
|
| 1703 |
In general different \PP{tabularray} environments (\EE{tblr}, \EE{talltblr}, |
| 1704 |
\EE{longtblr}, etc) could have different default specifications. |
| 1705 |
You can list the environments in the optional arguments of these two commands, |
| 1706 |
and they only apply to \EE{tblr} environment when the optional arguments are omitted. |
| 1707 |
|
| 1708 |
In the following example, the first line draws all hlines and vlines for all \EE{tblr} tables |
| 1709 |
created afterwards, while the second line makes all \EE{tblr} tables created afterwards |
| 1710 |
vertically align at the last row. |
| 1711 |
|
| 1712 |
\begin{codehigh} |
| 1713 |
\SetTblrInner{hlines,vlines} |
| 1714 |
\SetTblrOuter{baseline=B} |
| 1715 |
\end{codehigh} |
| 1716 |
|
| 1717 |
And the following example sets zero \K{rowsep} for all \EE{tblr} and \EE{longtblr} tables |
| 1718 |
created afterwards. |
| 1719 |
|
| 1720 |
\begin{codehigh} |
| 1721 |
\SetTblrInner[tblr,longtblr]{rowsep=0pt} |
| 1722 |
\end{codehigh} |
| 1723 |
|
| 1724 |
\section{New tabularray environments} |
| 1725 |
|
| 1726 |
You can define new \PP{tabularray} environments using \CC{\NewTblrEnviron} command: |
| 1727 |
|
| 1728 |
\begin{demohigh} |
| 1729 |
\NewTblrEnviron{mytblr} |
| 1730 |
\SetTblrInner[mytblr]{hlines,vlines} |
| 1731 |
\SetTblrOuter[mytblr]{baseline=B} |
| 1732 |
Text \begin{mytblr}{cccc} |
| 1733 |
Alpha & Beta & Gamma & Delta \\ |
| 1734 |
Epsilon & Zeta & Eta & Theta \\ |
| 1735 |
Iota & Kappa & Lambda & Mu \\ |
| 1736 |
\end{mytblr} Text |
| 1737 |
\end{demohigh} |
| 1738 |
|
| 1739 |
\section{New general environments} |
| 1740 |
|
| 1741 |
With \V{+b} argument type of \CC{\NewDocumentEnvironment} command, |
| 1742 |
you can also define a new general environment based on \EE{tblr} environment |
| 1743 |
(note that there is an extra pair of curly braces at the end): |
| 1744 |
|
| 1745 |
\NewDocumentEnvironment{fancytblr}{+b}{ |
| 1746 |
Before Text |
| 1747 |
\begin{tblr}{hlines} |
| 1748 |
#1 |
| 1749 |
\end{tblr} |
| 1750 |
After Text |
| 1751 |
}{} |
| 1752 |
\begin{codehigh} |
| 1753 |
\NewDocumentEnvironment{fancytblr}{+b}{ |
| 1754 |
Before Text |
| 1755 |
\begin{tblr}{hlines} |
| 1756 |
#1 |
| 1757 |
\end{tblr} |
| 1758 |
After Text |
| 1759 |
}{} |
| 1760 |
\end{codehigh} |
| 1761 |
\begin{demohigh} |
| 1762 |
\begin{fancytblr} |
| 1763 |
One & Two & Three \\ |
| 1764 |
Four & Five & Six \\ |
| 1765 |
Seven & Eight & Nine \\ |
| 1766 |
\end{fancytblr} |
| 1767 |
\end{demohigh} |
| 1768 |
|
| 1769 |
\section{New table commands} |
| 1770 |
|
| 1771 |
All commands which change the specifications of tables \emph{must} be defined with \CC{\NewTblrTableCommand}. |
| 1772 |
The following example demonstrates how to define a new table command: |
| 1773 |
|
| 1774 |
\begin{demohigh} |
| 1775 |
\NewTblrTableCommand\myhline{\hline[0.1em,red5]} |
| 1776 |
\begin{tblr}{llll} |
| 1777 |
\myhline |
| 1778 |
Alpha & Beta & Gamma & Delta \\ |
| 1779 |
Epsilon & Zeta & Eta & Theta \\ |
| 1780 |
Iota & Kappa & Lambda & Mu \\ |
| 1781 |
\myhline |
| 1782 |
\end{tblr} |
| 1783 |
\end{demohigh} |
| 1784 |
|
| 1785 |
\section{Child indexers and selectors} |
| 1786 |
|
| 1787 |
From version 2025A, child indexer \CI{Z} accepts an optional argument for making a negative index. |
| 1788 |
|
| 1789 |
\begin{demohigh} |
| 1790 |
\begin{tblr}{ |
| 1791 |
cell{1}{2-Z[2]} = {red9}, |
| 1792 |
cell{2}{3-Z[3]} = {green9}, |
| 1793 |
cell{3}{Z[6]-Z[4]} = {blue9} |
| 1794 |
} |
| 1795 |
A & B & C & D & E & F & G & H & I \\ |
| 1796 |
A & B & C & D & E & F & G & H & I \\ |
| 1797 |
A & B & C & D & E & F & G & H & I |
| 1798 |
\end{tblr} |
| 1799 |
\end{demohigh} |
| 1800 |
|
| 1801 |
From version 2022A, child selectors \CS{odd} and \CS{even} accept an optional argument, |
| 1802 |
in which you can specify the start index of the children. |
| 1803 |
|
| 1804 |
\begin{demohigh} |
| 1805 |
\begin{tblr}{ |
| 1806 |
cell{1}{odd} = {yellow9}, |
| 1807 |
cell{2}{odd[5]} = {purple9}, |
| 1808 |
cell{3}{odd[4]} = {cyan9} |
| 1809 |
} |
| 1810 |
A & B & C & D & E & F & G & H & I & J \\ |
| 1811 |
A & B & C & D & E & F & G & H & I & J \\ |
| 1812 |
A & B & C & D & E & F & G & H & I & J |
| 1813 |
\end{tblr} |
| 1814 |
\end{demohigh} |
| 1815 |
|
| 1816 |
\begin{demohigh} |
| 1817 |
\begin{tblr}{ |
| 1818 |
cell{1}{even} = {red9}, |
| 1819 |
cell{2}{even[4]} = {green9}, |
| 1820 |
cell{3}{even[3]} = {blue9} |
| 1821 |
} |
| 1822 |
A & B & C & D & E & F & G & H & I & J \\ |
| 1823 |
A & B & C & D & E & F & G & H & I & J \\ |
| 1824 |
A & B & C & D & E & F & G & H & I & J \\ |
| 1825 |
\end{tblr} |
| 1826 |
\end{demohigh} |
| 1827 |
|
| 1828 |
From version 2025A, there is a new child selector \CS{every} |
| 1829 |
for selecting indexes in an arithmetic sequence. |
| 1830 |
|
| 1831 |
\begin{demohigh} |
| 1832 |
\begin{tblr}{ |
| 1833 |
cell{1}{every{2}{-2}} = {yellow9}, |
| 1834 |
cell{2}{every[2]{2}{-2}} = {purple9}, |
| 1835 |
cell{3}{every[3]{-9}{-2}} = {cyan9} |
| 1836 |
} |
| 1837 |
A & B & C & D & E & F & G & H & I & J \\ |
| 1838 |
A & B & C & D & E & F & G & H & I & J \\ |
| 1839 |
A & B & C & D & E & F & G & H & I & J |
| 1840 |
\end{tblr} |
| 1841 |
\end{demohigh} |
| 1842 |
|
| 1843 |
The interface of \CS{every} selector is \fakeverb{every[<step>]{<start>}{<end>}}, |
| 1844 |
where \fakeverb{<start>} and \fakeverb{<end>} are positive or negative indexes. |
| 1845 |
and they can not be child indexers such as \CI{U} or \CI{Z}. |
| 1846 |
|
| 1847 |
More child indexers and selectors can be defined by users (see Section~\ref{sect:newchild}). |
| 1848 |
|
| 1849 |
\section{Counters and lengths} |
| 1850 |
|
| 1851 |
Counters \CO{rownum}, \CO{colnum}, \CO{rowcount}, \CO{colcount} can be used in cell text: |
| 1852 |
\nopagebreak |
| 1853 |
\begin{demohigh} |
| 1854 |
\begin{tblr}{hlines} |
| 1855 |
Cell[\arabic{rownum}][\arabic{colnum}] & Cell[\arabic{rownum}][\arabic{colnum}] & |
| 1856 |
Cell[\arabic{rownum}][\arabic{colnum}] & Cell[\arabic{rownum}][\arabic{colnum}] \\ |
| 1857 |
Row=\arabic{rowcount}, Col=\arabic{colcount} & |
| 1858 |
Row=\arabic{rowcount}, Col=\arabic{colcount} & |
| 1859 |
Row=\arabic{rowcount}, Col=\arabic{colcount} & |
| 1860 |
Row=\arabic{rowcount}, Col=\arabic{colcount} \\ |
| 1861 |
Cell[\arabic{rownum}][\arabic{colnum}] & Cell[\arabic{rownum}][\arabic{colnum}] & |
| 1862 |
Cell[\arabic{rownum}][\arabic{colnum}] & Cell[\arabic{rownum}][\arabic{colnum}] \\ |
| 1863 |
\end{tblr} |
| 1864 |
\end{demohigh} |
| 1865 |
|
| 1866 |
Also, lengths \CC{\leftsep}, \CC{\rightsep}, \CC{\abovesep}, \CC{\belowsep} can be used in cell text. |
| 1867 |
|
| 1868 |
\section{Tracing tabularray} |
| 1869 |
|
| 1870 |
To trace internal data behind \EE{tblr} environment, you can use \CC{\SetTblrTracing} command. |
| 1871 |
For example, \CC{\SetTblrTracing{all}} will turn on all tracings, |
| 1872 |
and \CC{\SetTblrTracing{none}} will turn off all tracings. |
| 1873 |
\CC{\SetTblrTracing{+row,+column}} will only tracing row and column data. |
| 1874 |
All tracing messages will be written to the log files. |
| 1875 |
|
| 1876 |
\chapter{Use Long Tables} |
| 1877 |
\label{chap:long} |
| 1878 |
|
| 1879 |
\section{A simple example} |
| 1880 |
|
| 1881 |
To make a decent long table with header and footer, it is better to separate header/footer as |
| 1882 |
\underline{table head/foot} (which includes caption, footnotes, continuation text) |
| 1883 |
and \underline{row head/foot} (which includes some rows of the table that should appear in every page). |
| 1884 |
By this approach, alternating row colors work as expected. |
| 1885 |
|
| 1886 |
\NewTblrTheme{fancy}{ |
| 1887 |
\SetTblrStyle{firsthead}{font=\bfseries} |
| 1888 |
\SetTblrStyle{firstfoot}{fg=blue2} |
| 1889 |
\SetTblrStyle{middlefoot}{\itshape} |
| 1890 |
\SetTblrStyle{caption-tag}{red2} |
| 1891 |
} |
| 1892 |
\begin{longtblr}[ |
| 1893 |
theme = fancy, |
| 1894 |
caption = {A Long Long Long Long Long Long Long Table}, |
| 1895 |
entry = {Short Caption}, |
| 1896 |
label = {tblr:test}, |
| 1897 |
note{a} = {It is the first footnote.}, |
| 1898 |
note{$\dag$} = {It is the second long long long long long long footnote.}, |
| 1899 |
remark{Note} = {Some general note. Some general note. Some general note.}, |
| 1900 |
remark{Source} = {Made up by myself. Made up by myself. Made up by myself.}, |
| 1901 |
]{ |
| 1902 |
colspec = {XXX}, width = 0.85\linewidth, |
| 1903 |
rowhead = 2, rowfoot = 1, |
| 1904 |
row{odd} = {gray9}, row{even} = {brown9}, |
| 1905 |
row{1-2} = {purple7}, row{Z} = {blue7}, |
| 1906 |
} |
| 1907 |
\hline |
| 1908 |
Head & Head & Head \\ |
| 1909 |
\hline |
| 1910 |
Head & Head & Head \\ |
| 1911 |
\hline |
| 1912 |
Alpha & Beta & Gamma \\ |
| 1913 |
\hline |
| 1914 |
Epsilon & Zeta\TblrNote{a} & Eta \\ |
| 1915 |
\hline |
| 1916 |
Iota & Kappa\TblrNote{$\dag$} & Lambda \\ |
| 1917 |
\hline |
| 1918 |
Nu & Xi & Omicron \\ |
| 1919 |
\hline |
| 1920 |
Rho & Sigma & Tau \\ |
| 1921 |
\hline |
| 1922 |
Phi & Chi & Psi \\ |
| 1923 |
\hline |
| 1924 |
Alpha & Beta & Gamma \\ |
| 1925 |
\hline |
| 1926 |
Epsilon & Zeta & Eta \\ |
| 1927 |
\hline |
| 1928 |
Iota & Kappa & Lambda \\ |
| 1929 |
\hline |
| 1930 |
Nu & Xi & Omicron \\ |
| 1931 |
\hline |
| 1932 |
Rho & Sigma & Tau \\ |
| 1933 |
\hline |
| 1934 |
Phi & Chi & Psi \\ |
| 1935 |
\hline |
| 1936 |
Alpha & Beta & Gamma \\ |
| 1937 |
\hline |
| 1938 |
Epsilon & Zeta & Eta \\ |
| 1939 |
\hline |
| 1940 |
Iota & Kappa & Lambda \\ |
| 1941 |
\hline |
| 1942 |
Nu & Xi & Omicron \\ |
| 1943 |
\hline |
| 1944 |
Rho & Sigma & Tau \\ |
| 1945 |
\hline |
| 1946 |
Phi & Chi & Psi \\ |
| 1947 |
\hline |
| 1948 |
Alpha & Beta & Gamma \\ |
| 1949 |
\hline |
| 1950 |
Epsilon & Zeta & Eta \\ |
| 1951 |
\hline |
| 1952 |
Iota & Kappa & Lambda \\ |
| 1953 |
\hline |
| 1954 |
Nu & Xi & Omicron \\ |
| 1955 |
\hline |
| 1956 |
Rho & Sigma & Tau \\ |
| 1957 |
\hline |
| 1958 |
Phi & Chi & Psi \\ |
| 1959 |
\hline |
| 1960 |
Alpha & Beta & Gamma \\ |
| 1961 |
\hline |
| 1962 |
Epsilon & Zeta & Eta \\ |
| 1963 |
\hline |
| 1964 |
Iota & Kappa & Lambda \\ |
| 1965 |
\hline |
| 1966 |
Nu & Xi & Omicron \\ |
| 1967 |
\hline |
| 1968 |
Rho & Sigma & Tau \\ |
| 1969 |
\hline |
| 1970 |
Phi & Chi & Psi \\ |
| 1971 |
\hline |
| 1972 |
Alpha & Beta & Gamma \\ |
| 1973 |
\hline |
| 1974 |
Epsilon & Zeta & Eta \\ |
| 1975 |
\hline |
| 1976 |
Iota & Kappa & Lambda \\ |
| 1977 |
\hline |
| 1978 |
Nu & Xi & Omicron \\ |
| 1979 |
\hline |
| 1980 |
Rho & Sigma & Tau \\ |
| 1981 |
\hline |
| 1982 |
Phi & Chi & Psi \\ |
| 1983 |
\hline |
| 1984 |
Alpha & Beta & Gamma \\ |
| 1985 |
\hline |
| 1986 |
Epsilon & Zeta & Eta \\ |
| 1987 |
\hline |
| 1988 |
Iota & Kappa & Lambda \\ |
| 1989 |
\hline |
| 1990 |
Nu & Xi & Omicron \\ |
| 1991 |
\hline |
| 1992 |
Rho & Sigma & Tau \\ |
| 1993 |
\hline |
| 1994 |
Phi & Chi & Psi \\ |
| 1995 |
\hline |
| 1996 |
Alpha & Beta & Gamma \\ |
| 1997 |
\hline |
| 1998 |
Epsilon & Zeta & Eta \\ |
| 1999 |
\hline |
| 2000 |
Iota & Kappa & Lambda \\ |
| 2001 |
\hline |
| 2002 |
Nu & Xi & Omicron \\ |
| 2003 |
\hline |
| 2004 |
Rho & Sigma & Tau \\ |
| 2005 |
\hline |
| 2006 |
Phi & Chi & Psi \\ |
| 2007 |
\hline |
| 2008 |
Alpha & Beta & Gamma \\ |
| 2009 |
\hline |
| 2010 |
Epsilon & Zeta & Eta \\ |
| 2011 |
\hline |
| 2012 |
Iota & Kappa & Lambda \\ |
| 2013 |
\hline |
| 2014 |
Nu & Xi & Omicron \\ |
| 2015 |
\hline |
| 2016 |
Rho & Sigma & Tau \\ |
| 2017 |
\hline |
| 2018 |
Phi & Chi & Psi \\ |
| 2019 |
\hline |
| 2020 |
Alpha & Beta & Gamma \\ |
| 2021 |
\hline |
| 2022 |
Epsilon & Zeta & Eta \\ |
| 2023 |
\hline |
| 2024 |
Iota & Kappa & Lambda \\ |
| 2025 |
\hline |
| 2026 |
Nu & Xi & Omicron \\ |
| 2027 |
\hline |
| 2028 |
Rho & Sigma & Tau \\ |
| 2029 |
\hline |
| 2030 |
Phi & Chi & Psi \\ |
| 2031 |
\hline |
| 2032 |
Alpha & Beta & Gamma \\ |
| 2033 |
\hline |
| 2034 |
Epsilon & Zeta & Eta \\ |
| 2035 |
\hline |
| 2036 |
Iota & Kappa & Lambda \\ |
| 2037 |
\hline |
| 2038 |
Nu & Xi & Omicron \\ |
| 2039 |
\hline |
| 2040 |
Rho & Sigma & Tau \\ |
| 2041 |
\hline |
| 2042 |
Phi & Chi & Psi \\ |
| 2043 |
\hline |
| 2044 |
Alpha & Beta & Gamma \\ |
| 2045 |
\hline |
| 2046 |
Epsilon & Zeta & Eta \\ |
| 2047 |
\hline |
| 2048 |
Iota & Kappa & Lambda \\ |
| 2049 |
\hline |
| 2050 |
Nu & Xi & Omicron \\ |
| 2051 |
\hline |
| 2052 |
Rho & Sigma & Tau \\ |
| 2053 |
\hline |
| 2054 |
Phi & Chi & Psi \\ |
| 2055 |
\hline |
| 2056 |
Alpha & Beta & Gamma \\ |
| 2057 |
\hline |
| 2058 |
Epsilon & Zeta & Eta \\ |
| 2059 |
\hline |
| 2060 |
Iota & Kappa & Lambda \\ |
| 2061 |
\hline |
| 2062 |
Nu & Xi & Omicron \\ |
| 2063 |
\hline |
| 2064 |
Rho & Sigma & Tau \\ |
| 2065 |
\hline |
| 2066 |
Phi & Chi & Psi \\ |
| 2067 |
\hline |
| 2068 |
Alpha & Beta & Gamma \\ |
| 2069 |
\hline |
| 2070 |
Epsilon & Zeta & Eta \\ |
| 2071 |
\hline |
| 2072 |
Iota & Kappa & Lambda \\ |
| 2073 |
\hline |
| 2074 |
Nu & Xi & Omicron \\ |
| 2075 |
\hline |
| 2076 |
Rho & Sigma & Tau \\ |
| 2077 |
\hline |
| 2078 |
Phi & Chi & Psi \\ |
| 2079 |
\hline |
| 2080 |
Alpha & Beta & Gamma \\ |
| 2081 |
\hline |
| 2082 |
Epsilon & Zeta & Eta \\ |
| 2083 |
\hline |
| 2084 |
Iota & Kappa & Lambda \\ |
| 2085 |
\hline |
| 2086 |
Nu & Xi & Omicron \\ |
| 2087 |
\hline |
| 2088 |
Rho & Sigma & Tau \\ |
| 2089 |
\hline |
| 2090 |
Phi & Chi & Psi \\ |
| 2091 |
\hline |
| 2092 |
Foot & Foot & Foot \\ |
| 2093 |
\hline |
| 2094 |
\end{longtblr} |
| 2095 |
|
| 2096 |
As you can see in the above example, the appearance of long tables of \PP{tabularray} package |
| 2097 |
is similar to that of \PP{threeparttablex} packages. |
| 2098 |
It supports table footnotes, but not page footnotes. |
| 2099 |
|
| 2100 |
\newpage |
| 2101 |
|
| 2102 |
The source code for the above long table is shown below. It is mainly self-explanatory. |
| 2103 |
|
| 2104 |
\begin{codehigh} |
| 2105 |
\NewTblrTheme{fancy}{ |
| 2106 |
\SetTblrStyle{firsthead}{font=\bfseries} |
| 2107 |
\SetTblrStyle{firstfoot}{fg=blue2} |
| 2108 |
\SetTblrStyle{middlefoot}{\itshape} |
| 2109 |
\SetTblrStyle{caption-tag}{red2} |
| 2110 |
} |
| 2111 |
\begin{longtblr}[ |
| 2112 |
theme = fancy, |
| 2113 |
caption = {A Long Long Long Long Long Long Long Table}, |
| 2114 |
entry = {Short Caption}, |
| 2115 |
label = {tblr:test}, |
| 2116 |
note{a} = {It is the first footnote.}, |
| 2117 |
note{$\dag$} = {It is the second long long long long long long footnote.}, |
| 2118 |
remark{Note} = {Some general note. Some general note. Some general note.}, |
| 2119 |
remark{Source} = {Made up by myself. Made up by myself. Made up by myself.}, |
| 2120 |
]{ |
| 2121 |
colspec = {XXX}, width = 0.85\linewidth, |
| 2122 |
rowhead = 2, rowfoot = 1, |
| 2123 |
row{odd} = {gray9}, row{even} = {brown9}, |
| 2124 |
row{1-2} = {purple7}, row{Z} = {blue7}, |
| 2125 |
} |
| 2126 |
\hline |
| 2127 |
Head & Head & Head \\ |
| 2128 |
\hline |
| 2129 |
Head & Head & Head \\ |
| 2130 |
\hline |
| 2131 |
Alpha & Beta & Gamma \\ |
| 2132 |
\hline |
| 2133 |
Epsilon & Zeta\TblrNote{a} & Eta \\ |
| 2134 |
\hline |
| 2135 |
Iota & Kappa\TblrNote{$\dag$} & Lambda \\ |
| 2136 |
\hline |
| 2137 |
Nu & Xi & Omicron \\ |
| 2138 |
\hline |
| 2139 |
Rho & Sigma & Tau \\ |
| 2140 |
\hline |
| 2141 |
Phi & Chi & Psi \\ |
| 2142 |
\hline |
| 2143 |
...... |
| 2144 |
\hline |
| 2145 |
Alpha & Beta & Gamma \\ |
| 2146 |
\hline |
| 2147 |
Epsilon & Zeta & Eta \\ |
| 2148 |
\hline |
| 2149 |
Iota & Kappa & Lambda \\ |
| 2150 |
\hline |
| 2151 |
Nu & Xi & Omicron \\ |
| 2152 |
\hline |
| 2153 |
Rho & Sigma & Tau \\ |
| 2154 |
\hline |
| 2155 |
Phi & Chi & Psi \\ |
| 2156 |
\hline |
| 2157 |
Foot & Foot & Foot \\ |
| 2158 |
\hline |
| 2159 |
\end{longtblr} |
| 2160 |
\end{codehigh} |
| 2161 |
|
| 2162 |
As you can see in the above code, we typeset long tables with \EE{longtblr} environment. |
| 2163 |
And we can totally separate contents and styles of long tables with \PP{tabularray} package. |
| 2164 |
|
| 2165 |
Row head and row foot consist of some lines of the table and should appear in every page. |
| 2166 |
Their options are inner specifications and should be put in the mandatory argument of the \EE{longtblr} environment. |
| 2167 |
In the above example, We set \KV{rowhead=2} and \KV{rowfoot=1}. |
| 2168 |
|
| 2169 |
\begin{spectblr}[ |
| 2170 |
caption = {Inner Specifications for Row Heads and Row Foots} |
| 2171 |
]{} |
| 2172 |
Key Name & Key Description & Initial Value \\ |
| 2173 |
\V{rowhead} & number of the first rows of the table appear in every page & \V{0} \\ |
| 2174 |
\V{rowfoot} & number of the last rows of the table appear in every page & \V{0} \\ |
| 2175 |
\end{spectblr} |
| 2176 |
|
| 2177 |
Table head and table foot consist of the caption, continuation text, footnotes and remarks. |
| 2178 |
Their options are outer specifications and should be put in the optional argument of the \EE{longtblr} environment. |
| 2179 |
|
| 2180 |
\begin{spectblr}[ |
| 2181 |
caption = {Outer Specifications for Table Heads and Table Foots} |
| 2182 |
]{} |
| 2183 |
Key Name & Key Description & Initial Value \\ |
| 2184 |
\K{headsep} & vertical space between table head and table body & \V{6pt} \\ |
| 2185 |
\K{footsep} & vertical space between table foot and table body & \V{6pt} \\ |
| 2186 |
\K{presep} & vertical space between table head and the above text & \VV{1.5\bigskipamount} \\ |
| 2187 |
\K{postsep} & vertical space between table foot and the below text & \VV{1.5\bigskipamount} \\ |
| 2188 |
\K{theme} & table theme (including settings for templates and styles) & \None \\ |
| 2189 |
\K{caption} & table caption & \None \\ |
| 2190 |
\K{entry} & short table caption to be put in List of Tables & \None \\ |
| 2191 |
\K{label} & table label & \None \\ |
| 2192 |
\KK{note{<name>}} & table note with \V{<name>} as tag & \None \\ |
| 2193 |
\KK{remark{<name>}} & table remark with \V{<name>} as tag & \None \\ |
| 2194 |
\end{spectblr} |
| 2195 |
|
| 2196 |
If you write \KV{entry=none}, \PP{tabularray} package will not add an entry in List of Tables. |
| 2197 |
Therefore \KV{caption=text,entry=none} is similar to \CC{\caption[]{text}} in \PP{longtable}. |
| 2198 |
|
| 2199 |
If you write \KV{label=none}, \PP{tabularray} package will not step \CO{table} counter, |
| 2200 |
and set the \EN{caption-tag} and \EN{caption-sep} elements (see below) to empty. |
| 2201 |
Therefore \KV{caption=text,entry=none,label=none} is similar to \CC{\caption*{text}} |
| 2202 |
in \PP{longtable}, except for the counter. |
| 2203 |
|
| 2204 |
\section{Customize templates} |
| 2205 |
|
| 2206 |
\subsection{Overview of templates} |
| 2207 |
|
| 2208 |
The template system for table heads and table foots in \PP{tabularray} is largely inspired |
| 2209 |
by \PP{beamer}, \PP{caption} and \PP{longtable} packages. For elements in Table \ref{tblr:element}, |
| 2210 |
you can use \CC{\DeclareTblrTemplate} to define and modify templates, |
| 2211 |
and use \CC{\SetTblrTemplate} to choose default templates. In defining templates, |
| 2212 |
you can include other templates with \CC{\UseTblrTemplate} and \CC{\ExpTblrTemplate} commands. |
| 2213 |
|
| 2214 |
\begin{spectblr}[ |
| 2215 |
caption = {Elements for Table Heads and Table Foots}, |
| 2216 |
label = {tblr:element}, |
| 2217 |
]{} |
| 2218 |
Element Name & Element Description and Default Template \\ |
| 2219 |
\V{contfoot-text}& continuation text in the foot, normally ``Continued on next page'' \\ |
| 2220 |
\V{contfoot} & continuation paragraph in the foot, normally including \V{contfoot-text} template \\ |
| 2221 |
\V{conthead-text}& continuation text in the head, normally ``(Continued)'' \\ |
| 2222 |
\V{conthead} & continuation paragraph in the head, normally including \V{conthead-text} template \\ |
| 2223 |
\V{caption-tag} & caption tag, normally like ``Table 4.2'' \\ |
| 2224 |
\V{caption-sep} & caption separator, normally like ``:\quad'' \\ |
| 2225 |
\V{caption-text} & caption text, normally using user provided value \\ |
| 2226 |
\V{caption} & including \V{caption-tag} + \V{caption-sep} + \V{caption-text} \\ |
| 2227 |
\V{note-tag} & note tag, normally using user provided value \\ |
| 2228 |
\V{note-sep} & note separator, normally like ``\enskip'' \\ |
| 2229 |
\V{note-text} & note tag, normally using user provided value \\ |
| 2230 |
\V{note} & including \V{note-tag} + \V{note-sep} + \V{note-text} \\ |
| 2231 |
\V{remark-tag} & remark tag, normally using user provided value \\ |
| 2232 |
\V{remark-sep} & remark separator, normally like ``:\enskip'' \\ |
| 2233 |
\V{remark-text} & remark text, normally using user provided value\\ |
| 2234 |
\V{remark} & including \V{remark-tag} + \V{remark-sep} + \V{remark-text} \\ |
| 2235 |
\V{firsthead} & table head on the first page, normally including \V{caption} template \\ |
| 2236 |
\V{middlehead} & table head on middle pages, normally including \V{caption} and \V{conthead} templates \\ |
| 2237 |
\V{lasthead} & table head on the last page, normally including \V{caption} and \V{conthead} templates \\ |
| 2238 |
\V{head} & setting all of \V{firsthead}, \V{middlehead} and \V{lasthead} \\ |
| 2239 |
\V{firstfoot} & table foot on the first page, normally including \V{contfoot} template \\ |
| 2240 |
\V{middlefoot} & table foot on middle pages, normally including \V{contfoot} template \\ |
| 2241 |
\V{lastfoot} & table foot on the last page, normally including \V{note} and \V{remark} templates \\ |
| 2242 |
\V{foot} & setting all of \V{firstfoot}, \V{middlefoot} and \V{lastfoot} \\ |
| 2243 |
\end{spectblr} |
| 2244 |
|
| 2245 |
An element which only includes short text is called a \underline{sub element}. |
| 2246 |
Normally there is one \TT{-} in the name of a sub element. |
| 2247 |
An element which includes one or more paragraphs is called a \underline{main element}. |
| 2248 |
Normally there isn't any \TT{-} in the name of a main element. |
| 2249 |
|
| 2250 |
For each of the above elements, two templates \TN{normal} and \TN{empty} are always defined. |
| 2251 |
You can select one of them with \CC{\SetTblrTemplate} command. |
| 2252 |
|
| 2253 |
\subsection{Continuation templates} |
| 2254 |
|
| 2255 |
Let us have a look at the code for defining templates of continuation text first:% |
| 2256 |
\footnote{To tell the truth, the default \texttt{conthead-text} and \texttt{contfoot-text} |
| 2257 |
are actually stored in commands \texttt{\string\tblrcontheadname} and \texttt{\string\tblrcontfootname} |
| 2258 |
respectively. And you may contribute your translations of them to \textbf{babel} package.} |
| 2259 |
|
| 2260 |
\begin{codehigh} |
| 2261 |
\DeclareTblrTemplate{contfoot-text}{normal}{Continued on next page} |
| 2262 |
\SetTblrTemplate{contfoot-text}{normal} |
| 2263 |
\DeclareTblrTemplate{conthead-text}{normal}{(Continued)} |
| 2264 |
\SetTblrTemplate{conthead-text}{normal} |
| 2265 |
\end{codehigh} |
| 2266 |
|
| 2267 |
In the above code, command \CC{\DeclareTblrTemplate} defines the templates with name \TN{normal}, |
| 2268 |
and then command \CC{\SetTblrTemplate} sets the templates with name \TN{normal} as default. |
| 2269 |
The \TN{normal} template is always defined and set as default for any element in \PP{tabularray}. |
| 2270 |
Therefore you had better use another name when defining new templates. |
| 2271 |
|
| 2272 |
If you use \TN{default} as template name in \CC{\DeclareTblrTemplate}, |
| 2273 |
you define and set it as default at the same time. |
| 2274 |
Therefore the above code can be written in another way: |
| 2275 |
|
| 2276 |
\begin{codehigh} |
| 2277 |
\DeclareTblrTemplate{contfoot-text}{default}{Continued on next page} |
| 2278 |
\DeclareTblrTemplate{conthead-text}{default}{(Continued)} |
| 2279 |
\end{codehigh} |
| 2280 |
|
| 2281 |
You may modify the code to customize continuation text to fit your needs. |
| 2282 |
|
| 2283 |
The templates for \EN{contfoot} and \EN{conthead} normally |
| 2284 |
include the templates of their sub elements with \CC{\UseTblrTemplate} commands. |
| 2285 |
But you can also handle user settings such as horizontal alignment here. |
| 2286 |
|
| 2287 |
\begin{codehigh} |
| 2288 |
\DeclareTblrTemplate{contfoot}{default}{\UseTblrTemplate{contfoot-text}{default}} |
| 2289 |
\DeclareTblrTemplate{conthead}{default}{\UseTblrTemplate{conthead-text}{default}} |
| 2290 |
\end{codehigh} |
| 2291 |
|
| 2292 |
\subsection{Caption templates} |
| 2293 |
|
| 2294 |
Normally a caption consists of three parts, and their templates are defined with the follow code: |
| 2295 |
|
| 2296 |
\begin{codehigh} |
| 2297 |
\DeclareTblrTemplate{caption-tag}{default}{Table\hspace{0.25em}\thetable} |
| 2298 |
\DeclareTblrTemplate{caption-sep}{default}{:\enskip} |
| 2299 |
\DeclareTblrTemplate{caption-text}{default}{\InsertTblrText{caption}} |
| 2300 |
\end{codehigh} |
| 2301 |
|
| 2302 |
The command \CC{\InsertTblrText{caption}} inserts the value of \K{caption} key, |
| 2303 |
which you could write in the optional argument of \EE{longtblr} environment. |
| 2304 |
|
| 2305 |
The \EN{caption} template normally includes three sub templates with \CC{\UseTblrTemplate} commands: |
| 2306 |
The \EN{caption} template will be used in \EN{firsthead} template. |
| 2307 |
|
| 2308 |
\begin{codehigh} |
| 2309 |
\DeclareTblrTemplate{caption}{default}{ |
| 2310 |
\UseTblrTemplate{caption-tag}{default} |
| 2311 |
\UseTblrTemplate{caption-sep}{default} |
| 2312 |
\UseTblrTemplate{caption-text}{default} |
| 2313 |
} |
| 2314 |
\end{codehigh} |
| 2315 |
|
| 2316 |
Furthermore \EN{capcont} template includes \EN{conthead} template as well. |
| 2317 |
The \EN{capcont} template will be used in \EN{middlehead} and \EN{lasthead} templates. |
| 2318 |
|
| 2319 |
\begin{codehigh} |
| 2320 |
\DeclareTblrTemplate{capcont}{default}{ |
| 2321 |
\UseTblrTemplate{caption-tag}{default} |
| 2322 |
\UseTblrTemplate{caption-sep}{default} |
| 2323 |
\UseTblrTemplate{caption-text}{default} |
| 2324 |
\UseTblrTemplate{conthead-text}{default} |
| 2325 |
} |
| 2326 |
\end{codehigh} |
| 2327 |
|
| 2328 |
\subsection{Note and remark templates} |
| 2329 |
|
| 2330 |
The templates for table notes can be defined like this: |
| 2331 |
|
| 2332 |
\begin{codehigh} |
| 2333 |
\DeclareTblrTemplate{note-tag}{default}{\textsuperscript{\InsertTblrNoteTag}} |
| 2334 |
\DeclareTblrTemplate{note-sep}{default}{\space} |
| 2335 |
\DeclareTblrTemplate{note-text}{default}{\InsertTblrNoteText} |
| 2336 |
\end{codehigh} |
| 2337 |
\begin{codehigh} |
| 2338 |
\DeclareTblrTemplate{note}{default}{ |
| 2339 |
\MapTblrNotes{ |
| 2340 |
\noindent |
| 2341 |
\UseTblrTemplate{note-tag}{default} |
| 2342 |
\UseTblrTemplate{note-sep}{default} |
| 2343 |
\UseTblrTemplate{note-text}{default} |
| 2344 |
\par |
| 2345 |
} |
| 2346 |
} |
| 2347 |
\end{codehigh} |
| 2348 |
|
| 2349 |
The \CC{\MapTblrNotes} command loops for all table notes, |
| 2350 |
which are written in the optional argument of \EE{longtblr} environment. |
| 2351 |
Inside the loop, you can use \CC{\InsertTblrNoteTag} and \CC{\InsertTblrNoteText} |
| 2352 |
commands to insert current note tag and note text, respectively. |
| 2353 |
|
| 2354 |
The definition of remark templates are similar to note templates. |
| 2355 |
\nopagebreak |
| 2356 |
\begin{codehigh} |
| 2357 |
\DeclareTblrTemplate{remark-tag}{default}{\InsertTblrRemarkTag} |
| 2358 |
\DeclareTblrTemplate{remark-sep}{default}{:\space} |
| 2359 |
\DeclareTblrTemplate{remark-text}{default}{\InsertTblrRemarkText} |
| 2360 |
\end{codehigh} |
| 2361 |
\begin{codehigh} |
| 2362 |
\DeclareTblrTemplate{remark}{default}{ |
| 2363 |
\MapTblrRemarks{ |
| 2364 |
\noindent |
| 2365 |
\UseTblrTemplate{remark-tag}{default} |
| 2366 |
\UseTblrTemplate{remark-sep}{default} |
| 2367 |
\UseTblrTemplate{remark-text}{default} |
| 2368 |
\par |
| 2369 |
} |
| 2370 |
} |
| 2371 |
\end{codehigh} |
| 2372 |
|
| 2373 |
\subsection{Head and foot templates} |
| 2374 |
|
| 2375 |
The templates for table heads and foots are defined as including other templates: |
| 2376 |
|
| 2377 |
\begin{codehigh} |
| 2378 |
\DeclareTblrTemplate{firsthead}{default}{ |
| 2379 |
\UseTblrTemplate{caption}{default} |
| 2380 |
} |
| 2381 |
\DeclareTblrTemplate{middlehead,lasthead}{default}{ |
| 2382 |
\UseTblrTemplate{capcont}{default} |
| 2383 |
} |
| 2384 |
\DeclareTblrTemplate{firstfoot,middlefoot}{default}{ |
| 2385 |
\UseTblrTemplate{contfoot}{default} |
| 2386 |
} |
| 2387 |
\DeclareTblrTemplate{lastfoot}{default}{ |
| 2388 |
\UseTblrTemplate{note}{default} |
| 2389 |
\UseTblrTemplate{remark}{default} |
| 2390 |
} |
| 2391 |
\end{codehigh} |
| 2392 |
|
| 2393 |
Note that you can define the same template for multiple elements in \CC{\DeclareTblrTemplate} command. |
| 2394 |
If you only want to show table caption in the first page, you may change the definitions of |
| 2395 |
\EN{middlehead} and \EN{lasthead} elements: |
| 2396 |
|
| 2397 |
\begin{codehigh} |
| 2398 |
\DeclareTblrTemplate{middlehead,lasthead}{default}{ |
| 2399 |
\UseTblrTemplate{conthead}{default} |
| 2400 |
} |
| 2401 |
\end{codehigh} |
| 2402 |
|
| 2403 |
\section{Change styles} |
| 2404 |
|
| 2405 |
All available keys for template elements are described in Table \ref{key:element}. |
| 2406 |
|
| 2407 |
\begin{spectblr}[ |
| 2408 |
caption = {Keys for the Styles of Elements}, |
| 2409 |
label = {key:element}, |
| 2410 |
remark{Note} = {In most cases, you can omit the underlined key names and write only their values. |
| 2411 |
The keys \K{halign}, \K{indent} and \K{hang} are only for main templates.} |
| 2412 |
]{} |
| 2413 |
Key Name & Key Description & Initial Value\\ |
| 2414 |
\underline{\K{fg}} & foreground color & \None \\ |
| 2415 |
\underline{\K{font}} & font commands & \None \\ |
| 2416 |
\underline{\K{halign}} |
| 2417 |
& horizontal alignment: \V{l} (left), \V{c} (center), \V{r} (right) or \V{j} (justify) |
| 2418 |
& \V{j} \\ |
| 2419 |
\K{indent} & parindent value & \V{0pt} \\ |
| 2420 |
\K{hang} & hangindent value & \V{0pt} or \V{0.7em} \\ |
| 2421 |
\end{spectblr} |
| 2422 |
|
| 2423 |
You may change the styles of elements with \CC{\SetTblrStyle} command: |
| 2424 |
|
| 2425 |
\begin{codehigh} |
| 2426 |
\SetTblrStyle{firsthead}{font=\bfseries} |
| 2427 |
\SetTblrStyle{firstfoot}{fg=blue2} |
| 2428 |
\SetTblrStyle{middlefoot}{\itshape} |
| 2429 |
\SetTblrStyle{caption-tag}{red2} |
| 2430 |
\end{codehigh} |
| 2431 |
|
| 2432 |
When you write \CC{\UseTblrTemplate{element}{default}} in defining a template, |
| 2433 |
beside including template code of the \EN{element}, the foreground color and font commands |
| 2434 |
of the \EN{element} will be set up automatically. |
| 2435 |
In contrast, \CC{\ExpTblrTemplate{element}{default}} will only include template code. |
| 2436 |
|
| 2437 |
\section{Define themes} |
| 2438 |
|
| 2439 |
You may define your own themes for table heads and foots with \CC{\NewTblrTheme} command. |
| 2440 |
a theme consists of some template and style settings. For example: |
| 2441 |
\nopagebreak |
| 2442 |
\begin{codehigh} |
| 2443 |
\NewTblrTheme{fancy}{ |
| 2444 |
\DeclareTblrTemplate{conthead}{default}{[Continued]} |
| 2445 |
\SetTblrStyle{firsthead}{font=\bfseries} |
| 2446 |
\SetTblrStyle{firstfoot}{fg=blue2} |
| 2447 |
\SetTblrStyle{middlefoot}{\itshape} |
| 2448 |
\SetTblrStyle{caption-tag}{red2} |
| 2449 |
} |
| 2450 |
\end{codehigh} |
| 2451 |
|
| 2452 |
After defining the theme \V{fancy}, you can use it |
| 2453 |
by writing \KV{theme=fancy} in the optional argument of \EE{longtblr} environment. |
| 2454 |
|
| 2455 |
\section{Control page breaks} |
| 2456 |
|
| 2457 |
Just like \PP{longtable} package, inside \EE{longtblr} environment, |
| 2458 |
you can use \CC{\\\\*} or \CC{\nopagebreak} to prohibit a page break, |
| 2459 |
and use \CC{\pagebreak} to force a page break. |
| 2460 |
|
| 2461 |
\section{Floatable tall tables} |
| 2462 |
|
| 2463 |
There is also a \EE{talltblr} environment as an alternative to \EE{threeparttable} environment. |
| 2464 |
It can not cross multiple pages, but it can be put inside \EE{table} environment. |
| 2465 |
|
| 2466 |
\begin{demohigh} |
| 2467 |
TEXT\begin{talltblr}[ |
| 2468 |
caption = {Long Long Long Long Tabular}, |
| 2469 |
entry = {Short Caption}, |
| 2470 |
label = {tblr:tall}, |
| 2471 |
note{a} = {It is the first footnote.}, |
| 2472 |
note{$\dag$} = {It is the second long long long long long long footnote.}, |
| 2473 |
]{ |
| 2474 |
colspec = {XXX}, width = 0.5\linewidth, hlines, |
| 2475 |
} |
| 2476 |
Alpha & Beta & Gamma \\ |
| 2477 |
Epsilon & Zeta & Eta\TblrNote{a} \\ |
| 2478 |
Iota & Kappa & Lambda\TblrNote{$\dag$} \\ |
| 2479 |
\end{talltblr}TEXT |
| 2480 |
\end{demohigh} |
| 2481 |
|
| 2482 |
\chapter{Use Some Libraries} |
| 2483 |
\label{chap:lib} |
| 2484 |
|
| 2485 |
A \PP{tabularray} library could be loaded by \CC{\UseTblrLibrary} command. |
| 2486 |
From version 2025A, an external library \fakeverb{foo} could also be loaded |
| 2487 |
if its filename is \FF{tblrlibfoo.sty}. |
| 2488 |
|
| 2489 |
\section{Library \texttt{amsmath}} |
| 2490 |
|
| 2491 |
With \CC{\UseTblrLibrary{amsmath}} in the preamble of the document, |
| 2492 |
\PP{tabularray} will load \PP{amsmath} package, and define \EE{+array}, \EE{+matrix}, |
| 2493 |
\EE{+bmatrix}, \EE{+Bmatrix}, \EE{+pmatrix}, \EE{+vmatrix}, \EE{+Vmatrix} and \EE{+cases} |
| 2494 |
environments. Each of the environments is similar to the environment without \TT{+} prefix in its name, |
| 2495 |
but has default \KV{rowsep=2pt} just as \EE{tblr} environment. Every environment |
| 2496 |
except \EE{+array} accepts an optional argument, where you can write inner specifications. |
| 2497 |
|
| 2498 |
\begin{demo} |
| 2499 |
$\begin{pmatrix} |
| 2500 |
\dfrac{2}{3} & \dfrac{2}{3} & \dfrac{1}{3} \\ |
| 2501 |
\dfrac{2}{3} & -\dfrac{1}{3} & -\dfrac{2}{3} \\ |
| 2502 |
\dfrac{1}{3} & -\dfrac{2}{3} & \dfrac{2}{3} \\ |
| 2503 |
\end{pmatrix}$ |
| 2504 |
\end{demo} |
| 2505 |
|
| 2506 |
\begin{demohigh} |
| 2507 |
$\begin{+pmatrix}[cells={r},row{2}={purple8}] |
| 2508 |
\dfrac{2}{3} & \dfrac{2}{3} & \dfrac{1}{3} \\ |
| 2509 |
\dfrac{2}{3} & -\dfrac{1}{3} & -\dfrac{2}{3} \\ |
| 2510 |
\dfrac{1}{3} & -\dfrac{2}{3} & \dfrac{2}{3} \\ |
| 2511 |
\end{+pmatrix}$ |
| 2512 |
\end{demohigh} |
| 2513 |
|
| 2514 |
\begin{demo} |
| 2515 |
$f(x)=\begin{cases} |
| 2516 |
0, & x=1; \\ |
| 2517 |
\dfrac{1}{3}, & x=2; \\ |
| 2518 |
\dfrac{2}{3}, & x=3; \\ |
| 2519 |
1, & x=4. \\ |
| 2520 |
\end{cases}$ |
| 2521 |
\end{demo} |
| 2522 |
|
| 2523 |
\begin{demohigh} |
| 2524 |
$f(x)=\begin{+cases} |
| 2525 |
0, & x=1; \\ |
| 2526 |
\dfrac{1}{3}, & x=2; \\ |
| 2527 |
\dfrac{2}{3}, & x=3; \\ |
| 2528 |
1, & x=4. \\ |
| 2529 |
\end{+cases}$ |
| 2530 |
\end{demohigh} |
| 2531 |
|
| 2532 |
\section{Library \texttt{booktabs}} |
| 2533 |
|
| 2534 |
With \CC{\UseTblrLibrary{booktabs}} in the preamble of the document, |
| 2535 |
\PP{tabularray} will load \PP{booktabs} package, |
| 2536 |
and define |
| 2537 |
\CC{\toprule}, \CC{\midrule}, \CC{\bottomrule}, |
| 2538 |
\CC{\cmidrule}, \CC{\cmidrulemore}, \CC{\morecmidrules}, |
| 2539 |
\CC{\specialrule}, \CC{\addrowspace}, and \CC{\addlinespace} |
| 2540 |
as table commands. |
| 2541 |
|
| 2542 |
\begin{demohigh} |
| 2543 |
\begin{tblr}{llll} |
| 2544 |
\toprule |
| 2545 |
Alpha & Beta & Gamma & Delta \\ |
| 2546 |
\midrule |
| 2547 |
Epsilon & Zeta & Eta & Theta \\ |
| 2548 |
\cmidrule{1-3} |
| 2549 |
Iota & Kappa & Lambda & Mu \\ |
| 2550 |
\cmidrule{2-4} |
| 2551 |
Nu & Xi & Omicron & Pi \\ |
| 2552 |
\bottomrule |
| 2553 |
\end{tblr} |
| 2554 |
\end{demohigh} |
| 2555 |
|
| 2556 |
Just like \CC{\hline} and \CC{\cline} commands, |
| 2557 |
you can also specify rule width and color by using hline keys in the optional |
| 2558 |
argument of any of these commands. |
| 2559 |
|
| 2560 |
Like in \PP{booktabs}, by default |
| 2561 |
width of \CC{\toprule} and \CC{\bottomrule} are determined by \CC{\heavyrulewidth}, |
| 2562 |
width of \CC{\midrule} is determined by \CC{\lightrulewidth}, and |
| 2563 |
width of \CC{\cmidrule} and \CC{\cmidrulemore} are determined by \CC{\cmidrulewidth}, respectively. |
| 2564 |
All three \CC{\...rulewidth} are dimensions. |
| 2565 |
|
| 2566 |
\begin{demohigh} |
| 2567 |
\begin{tblr}{llll} |
| 2568 |
\toprule[2pt,purple3] |
| 2569 |
Alpha & Beta & Gamma & Delta \\ |
| 2570 |
\midrule[blue3] |
| 2571 |
Epsilon & Zeta & Eta & Theta \\ |
| 2572 |
\cmidrule[azure3]{2-3} |
| 2573 |
Iota & Kappa & Lambda & Mu \\ |
| 2574 |
\bottomrule[2pt,purple3] |
| 2575 |
\end{tblr} |
| 2576 |
\end{demohigh} |
| 2577 |
|
| 2578 |
If you need more than one \verb!\cmidrule!s, you can use \verb!\cmidrulemore! |
| 2579 |
command, which is simpler than the \verb!booktabs! usage |
| 2580 |
\verb!\morecmidrules\cmidrule!. |
| 2581 |
\verb!\cmidrulemore! can receive hline keys in an optional argument too. |
| 2582 |
|
| 2583 |
\begin{demohigh} |
| 2584 |
\begin{tblr}{llll} |
| 2585 |
\toprule |
| 2586 |
Alpha & Beta & Gamma & Delta \\ |
| 2587 |
\cmidrule{1-3} \cmidrulemore{2-4} |
| 2588 |
Epsilon & Zeta & Eta & Theta \\ |
| 2589 |
\cmidrule{1-3} \morecmidrules \cmidrule{2-4} |
| 2590 |
Iota & Kappa & Lambda & Mu \\ |
| 2591 |
\bottomrule |
| 2592 |
\end{tblr} |
| 2593 |
\end{demohigh} |
| 2594 |
|
| 2595 |
From version 2021N, you can set trimming positions of |
| 2596 |
\CC{\cmidrule} and \CC{\cmidrulemore}, using newly introduced trimming |
| 2597 |
options (\K{leftpos}, \K{rightpos}, \K{endpos}, \K{l}, \K{r}, |
| 2598 |
and \K{lr}) (see Section~\ref{sec:hlines-vlines}). |
| 2599 |
Option \K{endpos} is already applied to these two commands. |
| 2600 |
|
| 2601 |
\begin{demohigh} |
| 2602 |
\begin{tblr}{llll} |
| 2603 |
\toprule |
| 2604 |
Alpha & Beta & Gamma & Delta \\ |
| 2605 |
\cmidrule[lr]{1-2} \cmidrule[lr=-0.4]{3-4} |
| 2606 |
Epsilon & Zeta & Eta & Theta \\ |
| 2607 |
\cmidrule[r]{1-2} \cmidrule[l]{3-4} |
| 2608 |
Iota & Kappa & Lambda & Mu \\ |
| 2609 |
\bottomrule |
| 2610 |
\end{tblr} |
| 2611 |
\end{demohigh} |
| 2612 |
|
| 2613 |
Since \PP{booktabs} tables usually don't have vlines, the meaningful values |
| 2614 |
here are decimal numbers between \V{-1} and \V{0}. |
| 2615 |
The default value \V{-0.8} for \V{l}, \V{r}, and \V{lr} is chosen to |
| 2616 |
make similar result as \PP{booktabs} package does. |
| 2617 |
|
| 2618 |
There is also a \EE{booktabs} environment for you. With this environment, |
| 2619 |
the default \KV{rowsep=0pt}, but extra vertical space will be added by |
| 2620 |
\CC{\toprule}, \CC{\midrule}, \CC{\bottomrule} and \CC{\cmidrule} commands. |
| 2621 |
The sizes of vertical space are determined by \CC{\aboverulesep} and \CC{\belowrulesep} dimensions. |
| 2622 |
|
| 2623 |
\begin{demohigh} |
| 2624 |
\begin{booktabs}{ |
| 2625 |
colspec = lcccc, |
| 2626 |
cell{1}{1} = {r=2}{}, cell{1}{2,4} = {c=2}{}, |
| 2627 |
} |
| 2628 |
\toprule |
| 2629 |
Sample & I & & II & \\ |
| 2630 |
\cmidrule[lr]{2-3} \cmidrule[lr]{4-5} |
| 2631 |
& A & B & C & D \\ |
| 2632 |
\midrule |
| 2633 |
S1 & 5 & 6 & 7 & 8 \\ |
| 2634 |
S2 & 6 & 7 & 8 & 5 \\ |
| 2635 |
S3 & 7 & 8 & 5 & 6 \\ |
| 2636 |
\bottomrule |
| 2637 |
\end{booktabs} |
| 2638 |
\end{demohigh} |
| 2639 |
% S4 & 8 & 5 & 6 & 7 \\ |
| 2640 |
|
| 2641 |
You can also use \CC{\specialrule} command. |
| 2642 |
The second argument sets \K{belowsep} of previous row, |
| 2643 |
and the third argument sets \K{abovesep} of current row, |
| 2644 |
|
| 2645 |
\begin{demohigh} |
| 2646 |
\begin{booktabs}{row{2}={olive9}} |
| 2647 |
\toprule |
| 2648 |
Alpha & Beta & Gamma & Delta \\ |
| 2649 |
\specialrule{0.5pt}{4pt}{6pt} |
| 2650 |
Epsilon & Zeta & Eta & Theta \\ |
| 2651 |
\specialrule{0.8pt,blue3}{3pt}{2pt} |
| 2652 |
Iota & Kappa & Lambda & Mu \\ |
| 2653 |
\bottomrule |
| 2654 |
\end{booktabs} |
| 2655 |
\end{demohigh} |
| 2656 |
|
| 2657 |
At last, there is also an \CC{\addlinespace} command, with an alternative |
| 2658 |
name \CC{\addrowspace}. |
| 2659 |
You can specify the size of vertical space to be added in its optional |
| 2660 |
argument, and the default size is determinted by \CC{\defaultaddspace} |
| 2661 |
dimension, initially \V{0.5em}. |
| 2662 |
This command adds one half of the space to \K{belowsep} of previous row, |
| 2663 |
and the other half to \K{abovesep} of current row. |
| 2664 |
|
| 2665 |
\begin{demohigh} |
| 2666 |
\begin{booktabs}{row{2}={olive9}} |
| 2667 |
\toprule |
| 2668 |
Alpha & Beta & Gamma & Delta \\ |
| 2669 |
\addlinespace |
| 2670 |
Epsilon & Zeta & Eta & Theta \\ |
| 2671 |
\addlinespace[1em] |
| 2672 |
Iota & Kappa & Lambda & Mu \\ |
| 2673 |
\bottomrule |
| 2674 |
\end{booktabs} |
| 2675 |
\end{demohigh} |
| 2676 |
|
| 2677 |
From version 2022A, there is a \EE{longtabs} environment |
| 2678 |
for writing long \PP{booktabs} tables, |
| 2679 |
and a \EE{talltabs} environment for writing tall \PP{booktabs} tables. |
| 2680 |
|
| 2681 |
\section{Library \texttt{counter}} |
| 2682 |
|
| 2683 |
You need to load \LL{counter} library with \CC{\UseTblrLibrary{counter}}, |
| 2684 |
if you want to modify some LaTeX counters inside \PP{tabularray} tables. |
| 2685 |
|
| 2686 |
\begin{demohigh} |
| 2687 |
\newcounter{mycnta} |
| 2688 |
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}} |
| 2689 |
\begin{tblr}{hlines} |
| 2690 |
\mycnta & \mycnta & \mycnta \\ |
| 2691 |
\mycnta & \mycnta & \mycnta \\ |
| 2692 |
\mycnta & \mycnta & \mycnta \\ |
| 2693 |
\end{tblr} |
| 2694 |
\end{demohigh} |
| 2695 |
|
| 2696 |
\section{Library \texttt{diagbox}} |
| 2697 |
|
| 2698 |
When writing \CC{\UseTblrLibrary{diagbox}} in the preamble of the document, |
| 2699 |
\PP{tabularray} package loads \PP{diagbox} package, |
| 2700 |
and you can use \CC{\diagbox} and \CC{\diagboxthree} commands inside \EE{tblr} environment. |
| 2701 |
|
| 2702 |
\begin{demohigh} |
| 2703 |
\begin{tblr}{hlines,vlines} |
| 2704 |
\diagbox{Aa}{Pp} & Beta & Gamma \\ |
| 2705 |
Epsilon & Zeta & Eta \\ |
| 2706 |
Iota & Kappa & Lambda \\ |
| 2707 |
\end{tblr} |
| 2708 |
\end{demohigh} |
| 2709 |
|
| 2710 |
\begin{demohigh} |
| 2711 |
\begin{tblr}{hlines,vlines} |
| 2712 |
\diagboxthree{Aa}{Pp}{Hh} & Beta & Gamma \\ |
| 2713 |
Epsilon & Zeta & Eta \\ |
| 2714 |
Iota & Kappa & Lambda \\ |
| 2715 |
\end{tblr} |
| 2716 |
\end{demohigh} |
| 2717 |
|
| 2718 |
You can also use \CC{\diagbox} and \CC{\diagboxthree} commands in math mode. |
| 2719 |
\nopagebreak |
| 2720 |
\begin{demohigh} |
| 2721 |
$\begin{tblr}{|c|cc|} |
| 2722 |
\hline |
| 2723 |
\diagbox{X_1}{X_2} & 0 & 1 \\ |
| 2724 |
\hline |
| 2725 |
0 & 0.1 & 0.2 \\ |
| 2726 |
1 & 0.3 & 0.4 \\ |
| 2727 |
\hline |
| 2728 |
\end{tblr}$ |
| 2729 |
\end{demohigh} |
| 2730 |
|
| 2731 |
\section{Library \texttt{functional}} |
| 2732 |
|
| 2733 |
With \CC{\UseTblrLibrary{functional}} in the preamble of the document, |
| 2734 |
\PP{tabularray} will load \href{https://ctan.org/pkg/functional}{\PP{functional}} package, |
| 2735 |
and define outer key \K{evaluate} and inner key \K{process}. |
| 2736 |
This library brings intuitive functional programming into \PP{tabularray} tables. |
| 2737 |
|
| 2738 |
\subsection{Evaluate inner specifications} |
| 2739 |
|
| 2740 |
With this library, \PP{tabularray} will evaluate every function |
| 2741 |
(defined with \CC{\prgNewFunction}) within inner specifications, |
| 2742 |
replacing it with its return value, before parsing the key-value pairs. Here is an example: |
| 2743 |
\begin{demohigh} |
| 2744 |
\begin{tblr}{ |
| 2745 |
hlines, |
| 2746 |
row{2} = {bg=\funColor{RGB}{180,180,255}} |
| 2747 |
} |
| 2748 |
Alpha & Beta & Gamma \\ |
| 2749 |
Epsilon & Zeta & Eta \\ |
| 2750 |
Iota & Kappa & Lambda |
| 2751 |
\end{tblr} |
| 2752 |
\end{demohigh} |
| 2753 |
The \CC{\funColor} function is provided by \PP{functional} package. |
| 2754 |
And now let's see another example: |
| 2755 |
\begin{demohigh} |
| 2756 |
\begin{tblr}{ |
| 2757 |
row{2} = {bg=\intIfOddTF{\value{page}}{\prgReturn{red7}}{\prgReturn{blue7}}} |
| 2758 |
} |
| 2759 |
Alpha & Beta & Gamma \\ |
| 2760 |
Epsilon & Zeta & Eta \\ |
| 2761 |
Iota & Kappa & Lambda \\ |
| 2762 |
\end{tblr} |
| 2763 |
\end{demohigh} |
| 2764 |
|
| 2765 |
You may like to define a new function for it if you need to use it several times: |
| 2766 |
|
| 2767 |
\begin{demohigh} |
| 2768 |
\IgnoreSpacesOn |
| 2769 |
\prgNewFunction \colorMagic {mm} { |
| 2770 |
\intIfOddTF{\value{page}}{\prgReturn{#1}}{\prgReturn{#2}} |
| 2771 |
} |
| 2772 |
\IgnoreSpacesOff |
| 2773 |
\begin{tblr}{ |
| 2774 |
row{1} = {bg=\colorMagic{yellow7}{brown7}}, |
| 2775 |
row{3} = {bg=\colorMagic{green7}{teal7}} |
| 2776 |
} |
| 2777 |
Alpha & Beta & Gamma \\ |
| 2778 |
Epsilon & Zeta & Eta \\ |
| 2779 |
Iota & Kappa & Lambda \\ |
| 2780 |
\end{tblr} |
| 2781 |
\end{demohigh} |
| 2782 |
|
| 2783 |
\subsection{Evaluate table body} |
| 2784 |
|
| 2785 |
With outer key \K{evaluate}, you can evaluate every occurrence of a specified protected function |
| 2786 |
(defined with \CC{\prgNewFunction}) and replace it with the return value before splitting the table body. |
| 2787 |
|
| 2788 |
The first application of \K{evaluate} key is for inputting files inside tables. |
| 2789 |
Assume you have two files \FF{test1.tmp} and \FF{test2.tmp} with the following contents: |
| 2790 |
|
| 2791 |
\begin{filecontents*}[overwrite]{test1.tmp} |
| 2792 |
Some & Some \\ |
| 2793 |
\end{filecontents*} |
| 2794 |
\begin{filecontents*}[overwrite]{test2.tmp} |
| 2795 |
Other & Other \\ |
| 2796 |
\end{filecontents*} |
| 2797 |
|
| 2798 |
\begin{codehigh} |
| 2799 |
\begin{filecontents*}[overwrite]{test1.tmp} |
| 2800 |
Some & Some \\ |
| 2801 |
\end{filecontents*} |
| 2802 |
\end{codehigh} |
| 2803 |
|
| 2804 |
\begin{codehigh} |
| 2805 |
\begin{filecontents*}[overwrite]{test2.tmp} |
| 2806 |
Other & Other \\ |
| 2807 |
\end{filecontents*} |
| 2808 |
\end{codehigh} |
| 2809 |
|
| 2810 |
Then you can input them with outer specification \KV{evaluate=\fileInput}. |
| 2811 |
The \CC{\fileInput} function is provided by \PP{functional} package. |
| 2812 |
|
| 2813 |
\begin{demohigh} |
| 2814 |
\begin{tblr}[evaluate=\fileInput]{hlines} |
| 2815 |
Row1 & 1 \\ |
| 2816 |
\fileInput{test1.tmp} |
| 2817 |
Row3 & 3 \\ |
| 2818 |
\fileInput{test2.tmp} |
| 2819 |
Row5 & 5 \\ |
| 2820 |
\end{tblr} |
| 2821 |
\end{demohigh} |
| 2822 |
|
| 2823 |
In general, you can define your functions which return parts of table contents, |
| 2824 |
and use \K{evaluate} key to evaluate them inside tables. |
| 2825 |
|
| 2826 |
\begin{demohigh} |
| 2827 |
\IgnoreSpacesOn |
| 2828 |
\prgNewFunction \myFunOne {m} { |
| 2829 |
\prgReturn {#1 & #1 \\} |
| 2830 |
} |
| 2831 |
\IgnoreSpacesOff |
| 2832 |
\begin{tblr}[evaluate=\myFunOne]{hlines} |
| 2833 |
Row1 & 1 \\ |
| 2834 |
\myFunOne{Text} |
| 2835 |
Row3 & 3 \\ |
| 2836 |
\myFunOne{Text} |
| 2837 |
Row5 & 5 \\ |
| 2838 |
\end{tblr} |
| 2839 |
\end{demohigh} |
| 2840 |
|
| 2841 |
\begin{demohigh} |
| 2842 |
\IgnoreSpacesOn |
| 2843 |
\prgNewFunction \myFunTwo {} { |
| 2844 |
\prgReturn {Other & Other \\} |
| 2845 |
} |
| 2846 |
\IgnoreSpacesOff |
| 2847 |
\begin{tblr}[evaluate=\myFunTwo]{hlines} |
| 2848 |
Row1 & 1 \\ |
| 2849 |
\myFunTwo |
| 2850 |
Row3 & 3 \\ |
| 2851 |
\myFunTwo |
| 2852 |
Row5 & 5 \\ |
| 2853 |
\end{tblr} |
| 2854 |
\end{demohigh} |
| 2855 |
|
| 2856 |
You can even generate the whole table with some function. |
| 2857 |
|
| 2858 |
\begin{demohigh} |
| 2859 |
\IgnoreSpacesOn |
| 2860 |
\prgNewFunction \makeEmptyTable {mm} { |
| 2861 |
\tlSet \lTmpaTl {\intReplicate {\intEval{#2-1}} {&}} |
| 2862 |
\tlPutRight \lTmpaTl {\\} |
| 2863 |
\intReplicate {#1} {\tlUse \lTmpaTl} |
| 2864 |
} |
| 2865 |
\IgnoreSpacesOff |
| 2866 |
\begin{tblr}[evaluate=\makeEmptyTable]{hlines,vlines} |
| 2867 |
\makeEmptyTable{3}{7} |
| 2868 |
\end{tblr} |
| 2869 |
\end{demohigh} |
| 2870 |
|
| 2871 |
From version 2023A, you can evaluate all functions in the table body |
| 2872 |
with option \texttt{evaluate=all}. |
| 2873 |
|
| 2874 |
\subsection{Process table elements} |
| 2875 |
|
| 2876 |
With inner key \K{process}, you can modify the contents and styles before the table is built. |
| 2877 |
Several public functions defined with \CC{\prgNewFuncton} are provided for you: |
| 2878 |
|
| 2879 |
\begin{itemize} |
| 2880 |
\item \CC{\cellGetText{<rownum>}{<colnum>}} |
| 2881 |
\item \CC{\cellSetText{<rownum>}{<colnum>}{<text>}} |
| 2882 |
\item \CC{\cellSetStyle{<rownum>}{<colnum>}{<style>}} |
| 2883 |
\item \CC{\rowSetStyle{<rownum>}{<style>}} |
| 2884 |
\item \CC{\columnSetStyle{<colnum>}{<style>}} |
| 2885 |
\end{itemize} |
| 2886 |
|
| 2887 |
As the first example, let's calculate the sums of cells column by column: |
| 2888 |
|
| 2889 |
\IgnoreSpacesOn |
| 2890 |
\prgNewFunction \calcSum {} { |
| 2891 |
\intStepOneInline {1} {\arabic{colcount}} { |
| 2892 |
\intZero \lTmpaInt |
| 2893 |
\intStepOneInline {1} {\arabic{rowcount}-1} { |
| 2894 |
\intAdd \lTmpaInt {\cellGetText {####1} {##1}} |
| 2895 |
} |
| 2896 |
\cellSetText {\expWhole{\arabic{rowcount}}} {##1} {\intUse\lTmpaInt} |
| 2897 |
} |
| 2898 |
} |
| 2899 |
\IgnoreSpacesOff |
| 2900 |
\begin{codehigh} |
| 2901 |
\IgnoreSpacesOn |
| 2902 |
\prgNewFunction \calcSum {} { |
| 2903 |
\intStepOneInline {1} {\arabic{colcount}} { |
| 2904 |
\intZero \lTmpaInt |
| 2905 |
\intStepOneInline {1} {\arabic{rowcount}-1} { |
| 2906 |
\intAdd \lTmpaInt {\cellGetText {####1} {##1}} |
| 2907 |
} |
| 2908 |
\cellSetText {\expWhole{\arabic{rowcount}}} {##1} {\intUse\lTmpaInt} |
| 2909 |
} |
| 2910 |
} |
| 2911 |
\IgnoreSpacesOff |
| 2912 |
\end{codehigh} |
| 2913 |
|
| 2914 |
\begin{demohigh} |
| 2915 |
\begin{tblr}{colspec={rrr},process=\calcSum} |
| 2916 |
\hline |
| 2917 |
1 & 2 & 3 \\ |
| 2918 |
4 & 5 & 6 \\ |
| 2919 |
7 & 8 & 9 \\ |
| 2920 |
\hline |
| 2921 |
& & \\ |
| 2922 |
\hline |
| 2923 |
\end{tblr} |
| 2924 |
\end{demohigh} |
| 2925 |
|
| 2926 |
Now, let's set background colors of cells depending on their contents: |
| 2927 |
|
| 2928 |
\IgnoreSpacesOn |
| 2929 |
\prgNewFunction \colorBack {} { |
| 2930 |
\intStepOneInline {1} {\arabic{rowcount}} { |
| 2931 |
\intStepOneInline {1} {\arabic{colcount}} { |
| 2932 |
\intSet \lTmpaInt {\cellGetText {##1} {####1}} |
| 2933 |
\intCompareTF {\lTmpaInt} > {0} |
| 2934 |
{\cellSetStyle {##1} {####1} {bg=purple8}} |
| 2935 |
{\cellSetStyle {##1} {####1} {bg=olive8}} |
| 2936 |
} |
| 2937 |
} |
| 2938 |
} |
| 2939 |
\IgnoreSpacesOff |
| 2940 |
\begin{codehigh} |
| 2941 |
\IgnoreSpacesOn |
| 2942 |
\prgNewFunction \colorBack {} { |
| 2943 |
\intStepOneInline {1} {\arabic{rowcount}} { |
| 2944 |
\intStepOneInline {1} {\arabic{colcount}} { |
| 2945 |
\intSet \lTmpaInt {\cellGetText {##1} {####1}} |
| 2946 |
\intCompareTF {\lTmpaInt} > {0} |
| 2947 |
{\cellSetStyle {##1} {####1} {bg=purple8}} |
| 2948 |
{\cellSetStyle {##1} {####1} {bg=olive8}} |
| 2949 |
} |
| 2950 |
} |
| 2951 |
} |
| 2952 |
\IgnoreSpacesOff |
| 2953 |
\end{codehigh} |
| 2954 |
|
| 2955 |
\begin{demohigh} |
| 2956 |
\begin{tblr}{hlines,vlines,cells={r,$},process=\colorBack} |
| 2957 |
-1 & 2 & 3 \\ |
| 2958 |
4 & 5 & -6 \\ |
| 2959 |
7 & -8 & 9 \\ |
| 2960 |
\end{tblr} |
| 2961 |
\end{demohigh} |
| 2962 |
|
| 2963 |
We can also use color series of \PP{xcolor} package to color table rows: |
| 2964 |
|
| 2965 |
\definecolor{lightb}{RGB}{217,224,250} |
| 2966 |
\definecolorseries{tblrow}{rgb}{last}{lightb}{white} |
| 2967 |
\resetcolorseries[3]{tblrow} |
| 2968 |
\IgnoreSpacesOn |
| 2969 |
\prgNewFunction \colorSeries {} { |
| 2970 |
\intStepOneInline {1} {\arabic{rowcount}} { |
| 2971 |
\tlSet \lTmpaTl {\intMathMod {##1-1} {3}} |
| 2972 |
\rowSetStyle {##1} {\expWhole{bg=tblrow!![\lTmpaTl]}} |
| 2973 |
} |
| 2974 |
} |
| 2975 |
\IgnoreSpacesOff |
| 2976 |
\begin{codehigh} |
| 2977 |
\definecolor{lightb}{RGB}{217,224,250} |
| 2978 |
\definecolorseries{tblrow}{rgb}{last}{lightb}{white} |
| 2979 |
\resetcolorseries[3]{tblrow} |
| 2980 |
\IgnoreSpacesOn |
| 2981 |
\prgNewFunction \colorSeries {} { |
| 2982 |
\intStepOneInline {1} {\arabic{rowcount}} { |
| 2983 |
\tlSet \lTmpaTl {\intMathMod {##1-1} {3}} |
| 2984 |
\rowSetStyle {##1} {\expWhole{bg=tblrow!![\lTmpaTl]}} |
| 2985 |
} |
| 2986 |
} |
| 2987 |
\IgnoreSpacesOff |
| 2988 |
\end{codehigh} |
| 2989 |
|
| 2990 |
\begin{demohigh} |
| 2991 |
\begin{tblr}{hlines,process=\colorSeries} |
| 2992 |
Row1 & 1 \\ |
| 2993 |
Row2 & 2 \\ |
| 2994 |
Row3 & 3 \\ |
| 2995 |
Row4 & 4 \\ |
| 2996 |
Row5 & 5 \\ |
| 2997 |
Row6 & 6 \\ |
| 2998 |
\end{tblr} |
| 2999 |
\end{demohigh} |
| 3000 |
|
| 3001 |
\section{Library \texttt{hook}} |
| 3002 |
|
| 3003 |
This library is \emph{experimental}. |
| 3004 |
It will also load \LL{varwidth} library and set \KV{measure=vstore} as default. |
| 3005 |
See Section~\ref{sect:hook} for more details of the library. |
| 3006 |
|
| 3007 |
\section{Library \texttt{html}} |
| 3008 |
|
| 3009 |
This library is \emph{experimental}. |
| 3010 |
See Section~\ref{sect:pubvar} for more details of the library. |
| 3011 |
|
| 3012 |
\section{Library \texttt{nameref}} |
| 3013 |
|
| 3014 |
From version 2022D, you can load \LL{nameref} library |
| 3015 |
to make \CC{\nameref} and \EE{longtblr} work together. |
| 3016 |
|
| 3017 |
\section{Library \texttt{siunitx}} |
| 3018 |
|
| 3019 |
When writing \CC{\UseTblrLibrary{siunitx}} in the preamble of the document, |
| 3020 |
\PP{tabularray} package loads \PP{siunitx} package, |
| 3021 |
and defines \Q{S} column as \Q{Q} column with \K{si} key. |
| 3022 |
|
| 3023 |
\begin{demohigh} |
| 3024 |
\begin{tblr}{ |
| 3025 |
hlines, vlines, |
| 3026 |
colspec={S[table-format=3.2]S[table-format=3.2]} |
| 3027 |
} |
| 3028 |
{Head} & {Head} \\ |
| 3029 |
111 & 111 \\ |
| 3030 |
2.1 & 2.2 \\ |
| 3031 |
33.11 & 33.22 \\ |
| 3032 |
\end{tblr} |
| 3033 |
\end{demohigh} |
| 3034 |
|
| 3035 |
\begin{demohigh} |
| 3036 |
\begin{tblr}{ |
| 3037 |
hlines, vlines, |
| 3038 |
colspec={Q[si={table-format=3.2},c]Q[si={table-format=3.2},c]} |
| 3039 |
} |
| 3040 |
{Head} & {Head} \\ |
| 3041 |
111 & 111 \\ |
| 3042 |
2.1 & 2.2 \\ |
| 3043 |
33.11 & 33.22 \\ |
| 3044 |
\end{tblr} |
| 3045 |
\end{demohigh} |
| 3046 |
|
| 3047 |
Note that you need to use one pairs of curly braces to guard non-numeric cells% |
| 3048 |
\footnote{Before version 2025A, three pairs of braces are needed.}. |
| 3049 |
But it is cumbersome to enclose each cell with braces. From version 2022B |
| 3050 |
a new key \K{guard} is provided for cells and rows. With \K{guard} key the previous example |
| 3051 |
can be largely simplified. |
| 3052 |
|
| 3053 |
\begin{demohigh} |
| 3054 |
\begin{tblr}{ |
| 3055 |
hlines, vlines, |
| 3056 |
colspec={Q[si={table-format=3.2},c]Q[si={table-format=3.2},c]}, |
| 3057 |
row{1} = {guard} |
| 3058 |
} |
| 3059 |
Head & Head \\ |
| 3060 |
111 & 111 \\ |
| 3061 |
2.1 & 2.2 \\ |
| 3062 |
33.11 & 33.22 \\ |
| 3063 |
\end{tblr} |
| 3064 |
\end{demohigh} |
| 3065 |
|
| 3066 |
Also you must use \K{l}, \K{c} or \K{r} to set horizontal alignment for non-numeric cells: |
| 3067 |
\nopagebreak |
| 3068 |
\begin{demohigh} |
| 3069 |
\begin{tblr}{ |
| 3070 |
hlines, vlines, columns={6em}, |
| 3071 |
colspec={ |
| 3072 |
Q[si={table-format=3.2,table-number-alignment=left},l,blue7] |
| 3073 |
Q[si={table-format=3.2,table-number-alignment=center},c,teal7] |
| 3074 |
Q[si={table-format=3.2,table-number-alignment=right},r,purple7] |
| 3075 |
}, |
| 3076 |
row{1} = {guard} |
| 3077 |
} |
| 3078 |
Head & Head & Head \\ |
| 3079 |
111 & 111 & 111 \\ |
| 3080 |
2.1 & 2.2 & 2.3 \\ |
| 3081 |
33.11 & 33.22 & 33.33 \\ |
| 3082 |
\end{tblr} |
| 3083 |
\end{demohigh} |
| 3084 |
|
| 3085 |
Both \Q{S} and \Q{s} columns are supported. In fact, These two columns have been defined as follows: |
| 3086 |
\begin{codehigh} |
| 3087 |
\NewTblrColumnType{S}[1][]{Q[si={#1},c]} |
| 3088 |
\NewTblrColumnType{s}[1][]{Q[si={#1},c,cmd=\TblrUnit]} |
| 3089 |
\end{codehigh} |
| 3090 |
You don't need to and are not allowed to define them again. |
| 3091 |
|
| 3092 |
\section{Library \texttt{tikz}} |
| 3093 |
\label{sect:tikz} |
| 3094 |
|
| 3095 |
With this \emph{experimental} \LL{tikz} library,% |
| 3096 |
\footnote{The author thanks \href{https://github.com/jasperhabicht}{Jasper Habicht} |
| 3097 |
for his contributions to this library.} |
| 3098 |
you can draw \PP{tikz} pictures below or above (short or tall) tables. |
| 3099 |
This library depends on and loads \PP{tabularray} library \PP{hook} and \PP{tikz} library \TT{calc}.% |
| 3100 |
\footnote{Please have a look at this \href{https://github.com/pgf-tikz/pgf/issues/1213}{\PP{tikz} issue} |
| 3101 |
first if you need to write \fakeverb{\UseTblrLibrary{tikz}} in your LaTeX3 package.} |
| 3102 |
|
| 3103 |
To draw below/above a table, |
| 3104 |
write some \PP{tikz} code inside \EE{tblrtikzbelow}/\EE{tblrtikzabove} environment. |
| 3105 |
Both of them should be put before the table, and two compilations are needed to get desired result. |
| 3106 |
|
| 3107 |
Inside \EE{tblrtikzbelow}/\EE{tblrtikzabove} environment, you can use these predefined nodes: |
| 3108 |
|
| 3109 |
\begin{spectblr}[ |
| 3110 |
caption = {Nodes created by \PP{tikz} library} |
| 3111 |
]{} |
| 3112 |
Node Name & Node Description \\ |
| 3113 |
table node \NN{table} & rectangle node for the whole table \\ |
| 3114 |
cell node \NN{<i>-<j>} & rectangle node for \KK{cell{<i>}{<j>}} \\ |
| 3115 |
corner node \NN{h<i>} & coordinate node at the intersection point |
| 3116 |
of \KK{hborder{<i>}} and \KK{vborder{1}} \\ |
| 3117 |
corner node \NN{v<j>} & coordinate node at the intersection point |
| 3118 |
of \KK{vborder{<j>}} and \KK{hborder{1}} |
| 3119 |
\end{spectblr} |
| 3120 |
|
| 3121 |
The first example below demonstrates the table node and cell nodes: |
| 3122 |
|
| 3123 |
\begin{demohigh} |
| 3124 |
\begin{tblrtikzbelow} |
| 3125 |
\path[pattern color=gray9,pattern=checkerboard, |
| 3126 |
draw=blue3, ultra thick, rounded corners] |
| 3127 |
(table.north west) rectangle (table.south east); |
| 3128 |
\end{tblrtikzbelow}% |
| 3129 |
\begin{tblrtikzabove} |
| 3130 |
\draw[red3, thick] |
| 3131 |
(2-2.north west) -- (2-3.south east) |
| 3132 |
(2-2.south west) -- (2-3.north east); |
| 3133 |
\end{tblrtikzabove}% |
| 3134 |
\begin{tblr}{hline{2-3},vline{2-4}} |
| 3135 |
1-1 & 1-2 & 1-3 & 1-4 \\ |
| 3136 |
2-1 & 2-2 & 2-3 & 2-4 \\ |
| 3137 |
3-1 & 3-2 & 3-3 & 3-4 |
| 3138 |
\end{tblr} |
| 3139 |
\end{demohigh} |
| 3140 |
|
| 3141 |
The second example below demonstrates corner nodes: |
| 3142 |
|
| 3143 |
\begin{demohigh} |
| 3144 |
\begin{tblrtikzabove} |
| 3145 |
\draw[color=white,thick] |
| 3146 |
(h1-|v1) -- (h1-|v2) -- (h2-|v2) |
| 3147 |
-- (h2-|v3) -- (h3-|v3) -- (h3-|v4) |
| 3148 |
-- (h4-|v4) -- (h4-|v5) -- (h2-|v5) |
| 3149 |
-- (h2-|v6) -- (h1-|v6); |
| 3150 |
\end{tblrtikzabove}% |
| 3151 |
\begin{tblr}{hlines={wd=4pt},vlines={wd=3pt}} |
| 3152 |
1-1 & 1-2 & 1-3 & 1-4 & 1-5 \\ |
| 3153 |
2-1 & 2-2 & 2-3 & 2-4 & 2-5 \\ |
| 3154 |
3-1 & 3-2 & 3-3 & 3-4 & 3-5 |
| 3155 |
\end{tblr} |
| 3156 |
\end{demohigh} |
| 3157 |
|
| 3158 |
By \PP{tikz} intersection syntax, \fakeverb{h<i>-|v<j>} is |
| 3159 |
the intersection point of \KK{hborder{<i>}} and \KK{vborder{<j>}}. |
| 3160 |
|
| 3161 |
It is rather complicated to add full support for drawing \PP{tikz} pictures on long tables. |
| 3162 |
At present, the support is limited: only cell nodes are available for multi-page long tables. |
| 3163 |
In writing drawing code, |
| 3164 |
users are responsible for making sure the elements to draw are actually in current page table. |
| 3165 |
These public variables might come in handy: \CC{\lTblrRowHeadInt}, \CC{\lTblrRowFootInt}, |
| 3166 |
\CC{\lTblrTablePageInt}, \CC{\lTblrRowFirstInt}, \CC{\lTblrRowLastInt} |
| 3167 |
(they are described in Section~\ref{sect:pubvar}). Here is an example: |
| 3168 |
|
| 3169 |
\ExplSyntaxOn |
| 3170 |
\cs_generate_variant:Nn \clist_map_inline:nn {e} |
| 3171 |
\cs_new_protected:Npn \mymagic #1 |
| 3172 |
{ |
| 3173 |
\clist_map_inline:en {\ExpTblrChildClass {#1}} |
| 3174 |
{ |
| 3175 |
\bool_lazy_and:nnT |
| 3176 |
{ \int_compare_p:n {\lTblrRowFirstInt <= \use_i:nn ##1} } |
| 3177 |
{ \int_compare_p:n {\lTblrRowLastInt >= \use_i:nn ##1} } |
| 3178 |
{ \exp_args:Noo \mymagicfill {\use_i:nn ##1} {\use_ii:nn ##1} } |
| 3179 |
} |
| 3180 |
} |
| 3181 |
\ExplSyntaxOff |
| 3182 |
\newcommand\mymagicfill[2]{ |
| 3183 |
\fill[teal7,rounded corners=8pt] (#1-#2.north west) rectangle (#1-#2.south east); |
| 3184 |
} |
| 3185 |
\begin{tblrtikzbelow} |
| 3186 |
\mymagic{magic} |
| 3187 |
\end{tblrtikzbelow}% |
| 3188 |
\begin{longtblr}[ |
| 3189 |
caption = Long Table Tikz |
| 3190 |
]{ |
| 3191 |
rowhead=1, rowfoot=1, hlines, vlines, colspec={*{5}{X[r]}} |
| 3192 |
} |
| 3193 |
Head1 & Head2 & Head3 & Head4 & Head5 \\ |
| 3194 |
2-1 & 2-2 & \SetChild{class=magic}2-3 & 2-4 & 2-5 \\ |
| 3195 |
3-1 & 3-2 & 3-3 & 3-4 & 3-5 \\ |
| 3196 |
4-1 & 4-2 & 4-3 & \SetChild{class=magic}4-4 &4-5 \\ |
| 3197 |
5-1 & 5-2 & 5-3 & 5-4 & 5-5 \\ |
| 3198 |
6-1 & 6-2 & 6-3 & 6-4 & 6-5 \\ |
| 3199 |
7-1 & \SetChild{class=magic}7-2 & 7-3 & 7-4 & 7-5 \\ |
| 3200 |
8-1 & 8-2 & 8-3 & 8-4 & \SetChild{class=magic}8-5 \\ |
| 3201 |
9-1 & 9-2 & 9-3 & 9-4 & 9-5 \\ |
| 3202 |
0-1 & 0-2 & \SetChild{class=magic}0-3 & 0-4 & 0-5 \\ |
| 3203 |
1-1 & 1-2 & 1-3 & 1-4 & 1-5 \\ |
| 3204 |
\SetChild{class=magic}2-1 & 2-2 & 2-3 & 2-4 & 2-5 \\ |
| 3205 |
3-1 & 3-2 & 3-3 & 3-4 & 3-5 \\ |
| 3206 |
4-1 & 4-2 & 4-3 & \SetChild{class=magic}4-4 &4-5 \\ |
| 3207 |
5-1 & 5-2 & 5-3 & 5-4 & 5-5 \\ |
| 3208 |
Foot1 & Foot2 & Foot3 & Foot4 & Foot5 \\ |
| 3209 |
\end{longtblr} |
| 3210 |
|
| 3211 |
\begin{codehigh}[language=latex/latex3] |
| 3212 |
\ExplSyntaxOn |
| 3213 |
\cs_generate_variant:Nn \clist_map_inline:nn {e} |
| 3214 |
\cs_new_protected:Npn \mymagic #1 |
| 3215 |
{ |
| 3216 |
\clist_map_inline:en {\ExpTblrChildClass {#1}} |
| 3217 |
{ |
| 3218 |
\bool_lazy_and:nnT |
| 3219 |
{ \int_compare_p:n {\lTblrRowFirstInt <= \use_i:nn ##1} } |
| 3220 |
{ \int_compare_p:n {\lTblrRowLastInt >= \use_i:nn ##1} } |
| 3221 |
{ \exp_args:Noo \mymagicfill {\use_i:nn ##1} {\use_ii:nn ##1} } |
| 3222 |
} |
| 3223 |
} |
| 3224 |
\ExplSyntaxOff |
| 3225 |
\newcommand\mymagicfill[2]{ |
| 3226 |
\fill[teal7,rounded corners=8pt] (#1-#2.north west) rectangle (#1-#2.south east); |
| 3227 |
} |
| 3228 |
\begin{tblrtikzbelow} |
| 3229 |
\mymagic{magic} |
| 3230 |
\end{tblrtikzbelow}% |
| 3231 |
\begin{longtblr}[ |
| 3232 |
caption = Long Table Tikz |
| 3233 |
]{ |
| 3234 |
rowhead=1, rowfoot=1, hlines, vlines, colspec={*{5}{X[r]}} |
| 3235 |
} |
| 3236 |
Head1 & Head2 & Head3 & Head4 & Head5 \\ |
| 3237 |
2-1 & 2-2 & \SetChild{class=magic}2-3 & 2-4 & 2-5 \\ |
| 3238 |
3-1 & 3-2 & 3-3 & 3-4 & 3-5 \\ |
| 3239 |
4-1 & 4-2 & 4-3 & \SetChild{class=magic}4-4 &4-5 \\ |
| 3240 |
5-1 & 5-2 & 5-3 & 5-4 & 5-5 \\ |
| 3241 |
6-1 & 6-2 & 6-3 & 6-4 & 6-5 \\ |
| 3242 |
7-1 & \SetChild{class=magic}7-2 & 7-3 & 7-4 & 7-5 \\ |
| 3243 |
8-1 & 8-2 & 8-3 & 8-4 & \SetChild{class=magic}8-5 \\ |
| 3244 |
9-1 & 9-2 & 9-3 & 9-4 & 9-5 \\ |
| 3245 |
0-1 & 0-2 & \SetChild{class=magic}0-3 & 0-4 & 0-5 \\ |
| 3246 |
1-1 & 1-2 & 1-3 & 1-4 & 1-5 \\ |
| 3247 |
\SetChild{class=magic}2-1 & 2-2 & 2-3 & 2-4 & 2-5 \\ |
| 3248 |
3-1 & 3-2 & 3-3 & 3-4 & 3-5 \\ |
| 3249 |
4-1 & 4-2 & 4-3 & \SetChild{class=magic}4-4 &4-5 \\ |
| 3250 |
5-1 & 5-2 & 5-3 & 5-4 & 5-5 \\ |
| 3251 |
Foot1 & Foot2 & Foot3 & Foot4 & Foot5 \\ |
| 3252 |
\end{longtblr} |
| 3253 |
\end{codehigh} |
| 3254 |
|
| 3255 |
\section{Library \texttt{varwidth}} |
| 3256 |
|
| 3257 |
To build a nice table, \PP{tabularray} need to measure the widths of cells. |
| 3258 |
By default, it uses \CC{\hbox} to measure the sizes. |
| 3259 |
This causes an error if a cell contains some vertical material, such as lists or display maths. |
| 3260 |
|
| 3261 |
With \PP{varwidth} library, \PP{tabularray} will load \PP{varwidth} package, |
| 3262 |
add a new inner specification \K{measure}, and set \KV{measure=vbox} |
| 3263 |
so that it will use \CC{\vbox} to measure cell widths. |
| 3264 |
|
| 3265 |
\begin{demohigh} |
| 3266 |
\begin{tblr}{hlines,measure=vbox} |
| 3267 |
Text Text Text Text Text Text Text |
| 3268 |
\begin{itemize} |
| 3269 |
\item List List List List List List |
| 3270 |
\item List List List List List List List |
| 3271 |
\end{itemize} |
| 3272 |
Text Text Text Text Text Text Text \\ |
| 3273 |
\end{tblr} |
| 3274 |
\end{demohigh} |
| 3275 |
|
| 3276 |
From version 2022A, you can remove extra space above and below lists, |
| 3277 |
by adding option \KV{stretch=-1}. |
| 3278 |
The following example also needs \PP{enumitem} package and its \K{nosep} option: |
| 3279 |
|
| 3280 |
{\centering\begin{tblr}{ |
| 3281 |
hlines,vlines,rowspec={Q[l,t]Q[l,b]}, |
| 3282 |
measure=vbox,stretch=-1, |
| 3283 |
} |
| 3284 |
\begin{itemize}[nosep] |
| 3285 |
\item List List List List List |
| 3286 |
\item List List List List List List |
| 3287 |
\end{itemize} & oooo \\ |
| 3288 |
\begin{itemize}[nosep] |
| 3289 |
\item List List List List List |
| 3290 |
\item List List List List List List |
| 3291 |
\end{itemize} & gggg \\ |
| 3292 |
\end{tblr}\par} |
| 3293 |
|
| 3294 |
%% BUG: there is extra vertical space at the beginning of the first cell if I use demohigh |
| 3295 |
%\begin{demohigh} |
| 3296 |
\begin{codehigh} |
| 3297 |
\begin{tblr}{ |
| 3298 |
hlines,vlines,rowspec={Q[l,t]Q[l,b]}, |
| 3299 |
measure=vbox,stretch=-1, |
| 3300 |
} |
| 3301 |
\begin{itemize}[nosep] |
| 3302 |
\item List List List List List |
| 3303 |
\item List List List List List List |
| 3304 |
\end{itemize} & oooo \\ |
| 3305 |
\begin{itemize}[nosep] |
| 3306 |
\item List List List List List |
| 3307 |
\item List List List List List List |
| 3308 |
\end{itemize} & gggg \\ |
| 3309 |
\end{tblr} |
| 3310 |
\end{codehigh} |
| 3311 |
%\end{demohigh} |
| 3312 |
|
| 3313 |
Note that option \KV{stretch=-1} also removes struts from cells, therefore it may not work well |
| 3314 |
in \PP{tabularray} environments with \KV{rowsep=0pt}, such as |
| 3315 |
\EE{booktabs}/\EE{longtabs}/\EE{talltabs} environments from \LL{booktabs} library. |
| 3316 |
|
| 3317 |
From version 2025A, \KK{measure} key also accepts an \emph{experimental} \VV{vstore} value. |
| 3318 |
With \KV{measure=vstore}, \PP{tabularray} also measures cells with \CC{\vbox}, |
| 3319 |
but it will store the boxes for later use, |
| 3320 |
which is necessary to make \CC{\lTblrMeasuringBool} status correct. |
| 3321 |
|
| 3322 |
From version 2025A, the setting of \KK{measure} key also applies to subtables. |
| 3323 |
|
| 3324 |
\section{Library \texttt{zref}} |
| 3325 |
|
| 3326 |
From version 2022D, you can load \LL{zref} library |
| 3327 |
to make \CC{\zref} and \EE{longtblr} work together. |
| 3328 |
|
| 3329 |
\chapter{Tips and Tricks} |
| 3330 |
|
| 3331 |
\section{Default rule widths and colors} |
| 3332 |
|
| 3333 |
From version 2025A, default hrule and vrule widths are stored in variables |
| 3334 |
\CC{\lTblrDefaultHruleWidthDim} and \CC{\lTblrDefaultVruleWidthDim} respectively, |
| 3335 |
and default hrule and vrule colors are stored in variables \CC{\lTblrDefaultHruleColorTl} |
| 3336 |
and \CC{\lTblrDefaultVruleColorTl} respectively. Here is an example: |
| 3337 |
|
| 3338 |
\begin{demohigh} |
| 3339 |
\setlength\lTblrDefaultHruleWidthDim{1pt}% |
| 3340 |
\setlength\lTblrDefaultVruleWidthDim{2pt}% |
| 3341 |
\renewcommand\lTblrDefaultHruleColorTl{blue5}% |
| 3342 |
\renewcommand\lTblrDefaultVruleColorTl{red5}% |
| 3343 |
\begin{tblr}{ |
| 3344 |
hlines, hline{2} = {wd=2pt, fg=cyan5}, |
| 3345 |
vlines, vline{2} = {wd=1pt, fg=green5} |
| 3346 |
} |
| 3347 |
Alpha & Beta & Gamma \\ |
| 3348 |
Epsilon & Zeta & Eta \\ |
| 3349 |
Iota & Kappa & Lambda \\ |
| 3350 |
\end{tblr} |
| 3351 |
\end{demohigh} |
| 3352 |
|
| 3353 |
\section{Control horizontal alignment} |
| 3354 |
|
| 3355 |
You can control horizontal alignment of cells in \texttt{tabularray} with |
| 3356 |
\href{https://www.ctan.org/pkg/ragged2e}{\texttt{ragged2e}} package, |
| 3357 |
by redefining some of the following commands: |
| 3358 |
|
| 3359 |
\begin{codehigh} |
| 3360 |
\RenewDocumentCommand\TblrAlignBoth{}{\justifying} |
| 3361 |
\RenewDocumentCommand\TblrAlignLeft{}{\RaggedRight} |
| 3362 |
\RenewDocumentCommand\TblrAlignCenter{}{\Centering} |
| 3363 |
\RenewDocumentCommand\TblrAlignRight{}{\RaggedLeft} |
| 3364 |
\end{codehigh} |
| 3365 |
|
| 3366 |
Please read the documentation of \texttt{ragged2e} package for more details of |
| 3367 |
their alignment commands. |
| 3368 |
|
| 3369 |
\section{Use safe verbatim commands}% |
| 3370 |
\label{sec:fakeverb} |
| 3371 |
|
| 3372 |
Due to the limitations of TeX, |
| 3373 |
we are not able to make \CC{\verb} command behave well inside \PP{tabularray} tables. |
| 3374 |
As a replacement, you may use \CC{\fakeverb} command from \href{https://www.ctan.org/pkg/codehigh}{\PP{codehigh}} package. |
| 3375 |
|
| 3376 |
The \CC{\fakeverb} command will remove the backslashes in the following control symbols before |
| 3377 |
typesetting its content: \CC{\\\\}, \CC{\\\{}, \CC{\\\}}, \CC{\\\#}, \CC{\\\^} and \texttt{\textbackslash\textvisiblespace}, \CC{\\\%}. |
| 3378 |
Also the argument of \CC{\fakeverb} command need to be enclosed with curly braces. |
| 3379 |
Therefore it could be safely used inside \PP{tabularray} tables and other LaTeX commands. |
| 3380 |
|
| 3381 |
Here is an example of using \CC{\fakeverb} commands inside a \EE{tblr} environment: |
| 3382 |
|
| 3383 |
\begin{demohigh} |
| 3384 |
\begin{tblr}{hlines} |
| 3385 |
Special & \fakeverb{\abc{}$&^_^uvw 123} \\ |
| 3386 |
Spacing & \fakeverb{\bfseries\ \#\%} \\ |
| 3387 |
Nesting & \fbox{\fakeverb{$\left\\\{A\right.$\#}} |
| 3388 |
\end{tblr} |
| 3389 |
\end{demohigh} |
| 3390 |
|
| 3391 |
In the above example, balanced curly braces and control words (such as \CC{\bfseries}) |
| 3392 |
need not to be escaped---only several special characters need to be escaped. |
| 3393 |
Please read the documentation of \PP{codehigh} package for more details of |
| 3394 |
\CC{\fakeverb} commands.% |
| 3395 |
\footnote{By the way, \CC{\EscVerb} command from |
| 3396 |
\href{https://www.ctan.org/pkg/fvextra}{\PP{fvextra}} package is similar to |
| 3397 |
\CC{\fakeverb} command, but with \CC{\EscVerb} you need to escape every control word.} |
| 3398 |
|
| 3399 |
\section{Blank lines around cells} |
| 3400 |
|
| 3401 |
In \PP{tabularray} tables, there could be a blank line before a cell, after a cell, |
| 3402 |
or between table commands and cell text. Here is an example: |
| 3403 |
|
| 3404 |
\begin{demohigh} |
| 3405 |
\begin{tblr}{rl} |
| 3406 |
|
| 3407 |
\hline |
| 3408 |
|
| 3409 |
One |
| 3410 |
|
| 3411 |
& |
| 3412 |
|
| 3413 |
Two |
| 3414 |
|
| 3415 |
\\ |
| 3416 |
|
| 3417 |
\hline |
| 3418 |
|
| 3419 |
Three |
| 3420 |
|
| 3421 |
& |
| 3422 |
|
| 3423 |
Four |
| 3424 |
|
| 3425 |
\\ |
| 3426 |
|
| 3427 |
\hline |
| 3428 |
|
| 3429 |
\end{tblr} |
| 3430 |
\end{demohigh} |
| 3431 |
|
| 3432 |
But more blank lines are not supported. |
| 3433 |
Therefore putting more than one blank line at any of these positions may cause wrong result. |
| 3434 |
|
| 3435 |
|
| 3436 |
\chapter{Experimental Interfaces} |
| 3437 |
\label{chap:exp} |
| 3438 |
|
| 3439 |
\mywarning{The interfaces in this chapter |
| 3440 |
(and other undocumented public interfaces even if mentioned in the changelog) should be seen as \emph{experimental} |
| 3441 |
and are likely to change in future releases, if necessary. Don’t use them in important documents.} |
| 3442 |
|
| 3443 |
\section{Experimental public key paths} |
| 3444 |
|
| 3445 |
In version 2025A, all \PP{tabularray} key paths were cleaned up as follows: |
| 3446 |
\begin{itemize}[nosep] |
| 3447 |
\item \KP{tabularray/table/inner} (from \KP{tblr}): for inner specifications. |
| 3448 |
\item \KP{tabularray/table/outer} (from \KP{tblr-outer}): for outer specifications. |
| 3449 |
\item \KP{tabularray/column/inner} (from \KP{tblr-column}): for column specifications. |
| 3450 |
\item \KP{tabularray/row/inner} (from \KP{tblr-row}): for row specifications. |
| 3451 |
\item \KP{tabularray/cell/inner} (from \KP{tblr-cell-spec}): for cell specifications. |
| 3452 |
\item \KP{tabularray/cell/outer} (from \KP{tblr-cell-span}): for cell spanning specifications. |
| 3453 |
\item \KP{tabularray/hline/inner} (from \KP{tblr-hline}): for hline specifications. |
| 3454 |
\item \KP{tabularray/vline/inner} (from \KP{tblr-vline}): for vline specifications. |
| 3455 |
\item \KP{tabularray/hborder/inner} (from \KP{tblr-hborder}) for hborder specifications. |
| 3456 |
\item \KP{tabularray/vborder/inner} (from \KP{tblr-vborder}) for vborder specifications. |
| 3457 |
\end{itemize} |
| 3458 |
An advanced user or package writer can use \CC{\DeclareKeys} and \CC{\SetKeys} commands |
| 3459 |
(provided by LaTeX format) to declare new keys and apply key-value lists, respectively. |
| 3460 |
|
| 3461 |
The key paths are quite long, therefore \PP{tabularray} provides two shortcut commands |
| 3462 |
\CC{\DeclareTblrKeys} and \CC{\SetTblrKeys}: |
| 3463 |
|
| 3464 |
\begin{codehigh} |
| 3465 |
\DeclareTblrKeys{<path>}{<keyvals>} = \DeclareKeys[tabularray/<path>]{<keyvals>} |
| 3466 |
\SetTblrKeys{<path>}{<keyvals>} = \SetKeys[tabularray/<path>]{<keyvals>} |
| 3467 |
\end{codehigh} |
| 3468 |
|
| 3469 |
\section{Experimental public hook names} |
| 3470 |
\label{sect:hook} |
| 3471 |
|
| 3472 |
All experimental public \PP{tabularray} hook names provided by \LL{hook} library are as follows: |
| 3473 |
\begin{itemize}[nosep] |
| 3474 |
\item \HP{tabularray/trial/before}: hook before trial typesetting. |
| 3475 |
\item \HP{tabularray/trial/after}: hook after trial typesetting. |
| 3476 |
\item \HP{tabularray/table/before}: hook before building the whole table. |
| 3477 |
\item \HP{tabularray/table/after}: hook after building the whole table. |
| 3478 |
\item \HP{tabularray/row/before}: hook before typesetting a table row. |
| 3479 |
\item \HP{tabularray/row/after}: hook after typesetting a table row. |
| 3480 |
\item \HP{tabularray/cell/before}: hook before typesetting a table cell. |
| 3481 |
\item \HP{tabularray/cell/after}: hook after typesetting a table cell. |
| 3482 |
\end{itemize} |
| 3483 |
An advanced user or package writer can use \CC{\AddToHook} and \CC{\AddToHookNext} commands |
| 3484 |
(provided by LaTeX format) to inject code to \PP{tabularray} tables. |
| 3485 |
|
| 3486 |
The hook names are quite long, therefore \PP{tabularray} provides two shortcut commands |
| 3487 |
\CC{\AddToTblrHook} and \CC{\AddToTblrHookNext}: |
| 3488 |
|
| 3489 |
%\begin{codehigh} |
| 3490 |
%\AddToTblrHook{<name>}[<label>]{<code>}=\AddToHook{tabularray/<name>}[<label>]{<code>} |
| 3491 |
%\AddToTblrHookNext{<name>}{<code>}=\AddToHookNext{tabularray/<name>}{<code>} |
| 3492 |
%\end{codehigh} |
| 3493 |
\begin{codehigh} |
| 3494 |
\AddToTblrHook{<name>}{<code>} = \AddToHook{tabularray/<name>}{<code>} |
| 3495 |
\AddToTblrHookNext{<name>}{<code>} = \AddToHookNext{tabularray/<name>}{<code>} |
| 3496 |
\end{codehigh} |
| 3497 |
|
| 3498 |
\section{Experimental public variables} |
| 3499 |
\label{sect:pubvar} |
| 3500 |
|
| 3501 |
This variable can be used to change page break settings for multirow cells: |
| 3502 |
\begin{itemize}[nosep] |
| 3503 |
\item \CC{\lTblrCellBreakBool}: whether to allow page breaks in the middle of multirow cells. |
| 3504 |
\end{itemize} |
| 3505 |
|
| 3506 |
This variable is always available throughout the whole typesetting process of tables: |
| 3507 |
\begin{itemize}[nosep] |
| 3508 |
\item \CC{\lTblrMeasuringBool}: if \PP{tabularray} is doing trial typesetting. |
| 3509 |
\end{itemize} |
| 3510 |
You need to make sure \KV{measure=vstore} to make \CC{\lTblrMeasuringBool} correct. |
| 3511 |
|
| 3512 |
This variable is available before building every table: |
| 3513 |
\begin{itemize}[nosep] |
| 3514 |
\item \CC{\lTblrPortraitTypeTl}: table type (\VV{short}, \VV{tall} or \VV{long}). |
| 3515 |
\end{itemize} |
| 3516 |
|
| 3517 |
These variables are updated in building long tables: |
| 3518 |
\begin{itemize}[nosep] |
| 3519 |
\item \CC{\lTblrRowHeadInt}: total number of head rows. |
| 3520 |
\item \CC{\lTblrRowFootInt}: total number of foot rows. |
| 3521 |
\item \CC{\lTblrTablePageInt}: index number of current page table. |
| 3522 |
\item \CC{\lTblrRowFirstInt}: first row number in row body of current page table. |
| 3523 |
\item \CC{\lTblrRowLastInt}: last row number in row body of current page table. |
| 3524 |
\end{itemize} |
| 3525 |
|
| 3526 |
These variables are updated by default before building every cell: |
| 3527 |
\begin{itemize}[nosep] |
| 3528 |
\item \CC{\lTblrCellRowSpanInt}: how many rows are spanned by current cell. |
| 3529 |
\item \CC{\lTblrCellColSpanInt}: how many columns are spanned by current cell. |
| 3530 |
\item \CC{\lTblrCellOmittedBool}: if current cell is spanned by another cell. |
| 3531 |
\item \CC{\lTblrCellBackgroundTl}: background color of current cell. |
| 3532 |
\end{itemize} |
| 3533 |
|
| 3534 |
These variables are updated by \LL{html} library before building every cell: |
| 3535 |
%(you need to write \CC{\UseTblrLibrary{html}} first): |
| 3536 |
\begin{itemize}[nosep] |
| 3537 |
\item \CC{\lTblrCellAboveBorderStyleTl} |
| 3538 |
\item \CC{\lTblrCellAboveBorderWidthDim} |
| 3539 |
\item \CC{\lTblrCellAboveBorderColorTl} |
| 3540 |
\item \CC{\lTblrCellBelowBorderStyleTl} |
| 3541 |
\item \CC{\lTblrCellBelowBorderWidthDim} |
| 3542 |
\item \CC{\lTblrCellBelowBorderColorTl} |
| 3543 |
\item \CC{\lTblrCellLeftBorderStyleTl} |
| 3544 |
\item \CC{\lTblrCellLeftBorderWidthDim} |
| 3545 |
\item \CC{\lTblrCellLeftBorderColorTl} |
| 3546 |
\item \CC{\lTblrCellRightBorderStyleTl} |
| 3547 |
\item \CC{\lTblrCellRightBorderWidthDim} |
| 3548 |
\item \CC{\lTblrCellRightBorderColorTl} |
| 3549 |
\end{itemize} |
| 3550 |
In the above, \TT{BorderStyle}, \TT{BorderWidth}, \TT{BorderColor} are similar to |
| 3551 |
\K{border-style}, \K{border-width}, \K{border-color} in HTML/CSS, respectively. |
| 3552 |
\TT{BorderStyle} and \TT{BorderColor} are empty by default. |
| 3553 |
|
| 3554 |
\section{New child indexers and selectors} |
| 3555 |
\label{sect:newchild} |
| 3556 |
|
| 3557 |
\subsection{One dimensional indexers and selectors} |
| 3558 |
|
| 3559 |
You can define new child indexers with \CC{\NewTblrChildIndexer} command. |
| 3560 |
As an example, the following is the simplified definition of \CI{Z} indexer: |
| 3561 |
\begin{codehigh}[language=latex/latex3] |
| 3562 |
\ExplSyntaxOn |
| 3563 |
\NewTblrChildIndexer {Z} [1] [1] |
| 3564 |
{ |
| 3565 |
\tl_set:Ne \lTblrChildIndexTl { \int_eval:n {\lTblrChildTotalInt + 1 - #1} {1} } |
| 3566 |
} |
| 3567 |
\ExplSyntaxOff |
| 3568 |
\end{codehigh} |
| 3569 |
In the definition, you can use \CC{\lTblrChildTotalInt} which is the total number of children. |
| 3570 |
And you only need to store the result index \fakeverb{<i>} in \CC{\lTblrChildIndexTl}. |
| 3571 |
The name of an indexer \emph{must} consist of letters and start with an uppercase letter. |
| 3572 |
|
| 3573 |
You can define new child selectors with \CC{\NewTblrChildSelector} command. |
| 3574 |
As an example, the following is the simplified definition of \CI{odd} selector: |
| 3575 |
\begin{codehigh}[language=latex/latex3] |
| 3576 |
\ExplSyntaxOn |
| 3577 |
\NewTblrChildSelector {odd} [1] [1] |
| 3578 |
{ |
| 3579 |
\clist_set:Ne \lTblrChildClist { {#1} {2} {\int_use:N \lTblrChildTotalInt} } |
| 3580 |
} |
| 3581 |
\ExplSyntaxOff |
| 3582 |
\end{codehigh} |
| 3583 |
In the definition, you can use \CC{\lTblrChildTotalInt} which is the total number of children. |
| 3584 |
And you only need to store the result indexes in \CC{\lTblrChildClist}. |
| 3585 |
When some indexes form an arithmetic sequence, |
| 3586 |
you can simplify them as \fakeverb{{<start>}{<step>}{<end>}}. |
| 3587 |
The name of a selector \emph{must} consist of letters and start with a lowercase letter. |
| 3588 |
|
| 3589 |
\subsection{Two dimensional indexers and selectors} |
| 3590 |
|
| 3591 |
When selecting cells, you may need two dimensional indexers and selectors. |
| 3592 |
You can also define new two dimensional child indexers with \CC{\NewTblrChildIndexer} command, |
| 3593 |
and two dimensional child selectors with \CC{\NewTblrChildSelector} command. |
| 3594 |
|
| 3595 |
In the definitions, you can use \CC{\lTblrChildHtotalInt} |
| 3596 |
which is the total number of horizontal children (rows), and \CC{\lTblrChildVtotalInt} |
| 3597 |
which is the total number of vertical children (columns). |
| 3598 |
|
| 3599 |
You also need to store the result index \fakeverb{{<i>}{<j>}} in \CC{\lTblrChildIndexTl} |
| 3600 |
in defining two dimensional child indexers. |
| 3601 |
Similarly you also need to store the result indexes in \CC{\lTblrChildClist} |
| 3602 |
in defining two dimensional child selectors. |
| 3603 |
|
| 3604 |
\subsection{Child ids and classes} |
| 3605 |
|
| 3606 |
When the table is long, it is clumsy to select children with indexes, positive or negative. |
| 3607 |
In version 2025A, \PP{tabularray} borrows ideas of ids and classes from HTML/CSS. |
| 3608 |
With table command \CC{\SetChild}, you can mark a hborder/vborder/row/column/cell with |
| 3609 |
an id or class, and use it in inner specifications. |
| 3610 |
|
| 3611 |
The \CC{\SetChild} command accepts key-value input: |
| 3612 |
\begin{spectblr}[ |
| 3613 |
caption = {Key-value input in \fakeverb{\\SetChild} command} %FIXME |
| 3614 |
]{} |
| 3615 |
Input & Description \\ |
| 3616 |
\KV{id=Hello} & create a child indexer \TT{Hello} which is an index \TT{{<i>}{<j>}} \\ |
| 3617 |
\KV{idh=Hello} & create a child indexer \TT{Helloh} which is a horizontal index \TT{<i>} \\ |
| 3618 |
\KV{idv=Hello} & create a child indexer \TT{Hellov} which is a vertical index \TT{<j>} \\ |
| 3619 |
\KV{id*=Hello} & create all of the above three child indexers \\ |
| 3620 |
\KV{class=world} & create a child selector \TT{world} which is a list of indexes \TT{{<i>}{<j>}} \\ |
| 3621 |
\KV{classh=world} & create a child selector \TT{worldh} which is a list of horizontal indexes \TT{<i>} \\ |
| 3622 |
\KV{classv=world} & create a child selector \TT{worldv} which is a list of vertical indexes \TT{<j>} \\ |
| 3623 |
\KV{class*=world} & create all of the above three child selectors |
| 3624 |
\end{spectblr} |
| 3625 |
|
| 3626 |
The following is an example of child ids |
| 3627 |
(every id name must start with uppercase letter since it creates a child indexer): |
| 3628 |
|
| 3629 |
\begin{demohigh} |
| 3630 |
\begin{tblr}{ |
| 3631 |
hline{1,Z}, |
| 3632 |
row{Barh,Quxh} = {bg=azure7}, |
| 3633 |
column{Bazv,Quxv} = {fg=red3}, |
| 3634 |
cell{Foo,Qux} = {cmd=\fbox} |
| 3635 |
} |
| 3636 |
1 & 2 & 3 & \SetChild{id=Foo} 4 & 5 & 6 & 7 & 8 \\ |
| 3637 |
2 & 2 & \SetChild{idh=Bar} 3 & 4 & 5 & 6 & 7 & 8 \\ |
| 3638 |
3 & \SetChild{idv=Baz} 2 & 3 & 4 & 5 & 6 & 7 & 8 \\ |
| 3639 |
\SetChild{id*=Qux} 4 & 2 & 3 & 4 & 5 & 6 & 7 & 8 |
| 3640 |
\end{tblr} |
| 3641 |
\end{demohigh} |
| 3642 |
|
| 3643 |
The following is an example of child classes |
| 3644 |
(every class name must start with lowercase letter since it creates a child selector): |
| 3645 |
|
| 3646 |
\begin{demohigh} |
| 3647 |
\begin{tblr}{ |
| 3648 |
hline{1,Z}, |
| 3649 |
row{fooh} = {bg=azure7}, |
| 3650 |
column{barv} = {fg=red3}, |
| 3651 |
cell{baz} = {cmd=\fbox} |
| 3652 |
} |
| 3653 |
1 & 2 & \SetChild{classh=foo} 3 & 4 & 5 & 6 & 7 \\ |
| 3654 |
2 & \SetChild{classv=bar} 2 & 3 & 4 & 5 & 6 & 7 \\ |
| 3655 |
\SetChild{class=baz} 3 & 2 & 3 & 4 & 5 & 6 & 7 \\ |
| 3656 |
4 & 2 & 3 & 4 & \SetChild{class=baz} 5 & 6 & 7 \\ |
| 3657 |
5 & 2 & 3 & 4 & 5 & \SetChild{classh=foo} 6 & 7 \\ |
| 3658 |
6 & 2 & 3 & 4 & 5 & 6 & \SetChild{classv=bar} 7 |
| 3659 |
\end{tblr} |
| 3660 |
\end{demohigh} |
| 3661 |
|
| 3662 |
Since \CC{\SetChild} commands need to be extracted first |
| 3663 |
before parsing inner specifications, they \emph{must} be put |
| 3664 |
at the beginning of cells, before other table commands such as \CC{\hline}. |
| 3665 |
Therefore it conflicts with syntaxes \fakeverb{\\\\[<dimen>]} and \fakeverb{\\\\*}. |
| 3666 |
They can be replaced with \fakeverb{\\\\\SetRow{belowsep+=<dimen>}} |
| 3667 |
and \fakeverb{\\\\\nopagebreak} respectively, |
| 3668 |
so that \CC{\SetChild} can be inserted in the middle: |
| 3669 |
\begin{demohigh} |
| 3670 |
\begin{tblr}{cell{Foo,Bar} = {fg=red3}} |
| 3671 |
\hline |
| 3672 |
1 & 2 & 3 & 4 & 5 & 6 & 7 \\ |
| 3673 |
\SetChild{id=Foo}\SetRow{belowsep+=5pt}\hline |
| 3674 |
2 & 2 & 3 & 4 & 5 & 6 & 7 \\ |
| 3675 |
\SetChild{id=Bar}\nopagebreak\hline |
| 3676 |
3 & 2 & 3 & 4 & 5 & 6 & 7 \\ |
| 3677 |
\hline |
| 3678 |
\end{tblr} |
| 3679 |
\end{demohigh} |
| 3680 |
|
| 3681 |
Only one \CC{\SetChild} command in each cell is supported. |
| 3682 |
But you can create multiple ids or classes with single \CC{\SetChild} command. |
| 3683 |
|
| 3684 |
In drawing \PP{tikz} pictures on tables (see Section~\ref{sect:tikz}), |
| 3685 |
you may want to get the value of a child id or class with \CC{\ExpTblrChildId} or \CC{\ExpTblrChildClass}. |
| 3686 |
These two commands are fully expandable. |
| 3687 |
|
| 3688 |
\chapter{History and Future} |
| 3689 |
|
| 3690 |
\section{The future} |
| 3691 |
|
| 3692 |
As a policy, \PP{tabularray} can support at most four TeX Live releases with latest updates. |
| 3693 |
For example, \PP{tabularray} releases published in \the\year{} could be used in TeX Live |
| 3694 |
\inteval{\year-3}--\the\year{} with latest updates. |
| 3695 |
|
| 3696 |
To make the upcoming releases more stable, you are very welcome to test the latest package file |
| 3697 |
in the repository. To test it, you only need to download the following \FF{tabularray.sty} |
| 3698 |
and put it into the folder of your TeX documents:\newline |
| 3699 |
\centerline{\url{https://github.com/lvjr/tabularray/raw/main/tabularray.sty}} |
| 3700 |
|
| 3701 |
\section{The history} |
| 3702 |
|
| 3703 |
The change log of \PP{tabularray} package will be updated on the wiki page:\newline |
| 3704 |
\centerline{\url{https://github.com/lvjr/tabularray/wiki/ChangeLog}} |
| 3705 |
|
| 3706 |
When \PP{tabularray} makes some breaking changes of \emph{stable public} interfaces in a new release, |
| 3707 |
you will be able to roll back to previous release to make your existing documents unaffected. |
| 3708 |
|
| 3709 |
Normally you don't know when there will be a new breaking release. |
| 3710 |
To keep your old documents as they are, you may add the date of current release |
| 3711 |
to the last optional argument of \CC{\usepackage} in loading \PP{tabularray}, |
| 3712 |
such as \CC{\usepackage{tabularray}[=2024-02-16]}. |
| 3713 |
|
| 3714 |
\subsection{Important changes in version 2025A} |
| 3715 |
|
| 3716 |
In version 2025A, there were several important changes: |
| 3717 |
|
| 3718 |
\begin{itemize}[nosep] |
| 3719 |
\item Inner key \KK{verb} (deprecated before) was removed; |
| 3720 |
it is better to use \CC{\fakeverb} command. |
| 3721 |
\item Support for end index in \CS{odd} and \CS{even} selectors was removed; |
| 3722 |
it is better to use \CS{every} selector. |
| 3723 |
\item Page breaks in the middle of multirow cells were disabled.%; |
| 3724 |
%use \CC{\lTblrCellBreakBool} to change it. |
| 3725 |
\item \CC{\DefTblrTemplate} was deprecated in favor of \CC{\DeclareTblrTemplate}. |
| 3726 |
\item \CC{\NewColumnType} was deprecated in favor of \CC{\NewTblrColumnType}. |
| 3727 |
\item \CC{\NewRowType} was deprecated in favor of \CC{\NewTblrRowType}. |
| 3728 |
\item \CC{\NewColumnRowType} was deprecated in favor of \CC{\NewTblrColumnRowType}. |
| 3729 |
\item \CC{\NewDashStyle} was deprecated in favor of \CC{\NewTblrDashStyle}. |
| 3730 |
\item \CC{\NewChildSelector} was deprecated in favor of \CC{\NewTblrChildSelector}. |
| 3731 |
\item \CC{\NewTableCommand} was deprecated in favor of \CC{\NewTblrTableCommand}. |
| 3732 |
%\item \CC{\NewContentCommand} was deprecated in favor of \CC{\NewTblrContentCommand}. |
| 3733 |
\item \CC{\tablewidth} was deprecated in favor of \CC{\lTblrTableWidthDim}. |
| 3734 |
%\item \CC{\g_tblr_level_int} was deprecated in favor of \CC{\gTblrLevelInt}. |
| 3735 |
\end{itemize} |
| 3736 |
|
| 3737 |
For your old documents, you can still rollback to version 2024 by \CC{\usepackage{tabularray}[=v2024]}. |
| 3738 |
|
| 3739 |
\subsection{Important changes in version 2022A} |
| 3740 |
|
| 3741 |
In version 2022A, there were several breaking changes: |
| 3742 |
|
| 3743 |
\begin{itemize}[nosep] |
| 3744 |
\item \CC{\multicolumn} command was removed; it is better to use \CC{\SetCell} command. |
| 3745 |
\item \CC{\multirow} command was removed; it is better to use \CC{\SetCell} command. |
| 3746 |
\item \CC{\firsthline} command was removed; it is better to use \KV{baseline=T} option. |
| 3747 |
\item \CC{\lasthline} command was removed; it is better to use \KV{baseline=B} option. |
| 3748 |
\end{itemize} |
| 3749 |
|
| 3750 |
For your old documents, you can still rollback to version 2021 by \CC{\usepackage{tabularray}[=v2021]}. |
| 3751 |
|
| 3752 |
\chapter{The Source Code} |
| 3753 |
|
| 3754 |
%\CodeHigh{lite} |
| 3755 |
\dochighinput[language=latex/latex3]{tabularray.sty} |
| 3756 |
|
| 3757 |
\end{document} |