Debian Codegraph @

texmf-dist/doc/latex/nicematrix/nicematrix.tex

raw
1 % -*- coding: utf-8 ; -*- This file should be compiled with LuaLaTeX only
2 \documentclass[dvipsnames]{article}
3
4 \hfuzz = 1pt
5
6 \usepackage{geometry}
7 \geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
8
9 \usepackage{nicematrix}
10
11 \usepackage{tikz}
12 \usetikzlibrary
13 {
14 fit,
15 patterns,
16 arrows.meta,
17 decorations.pathreplacing, % for \Hbrace and \Vbrace
18 decorations.pathmorphing, % for zigzag and random steps
19 calligraphy
20 }
21
22 \usepackage{enumitem}
23 \usepackage{siunitx}
24 \usepackage{verbatim}
25 \usepackage{caption}
26 \usepackage{tocloft}
27 \setlength{\cftsubsecnumwidth}{3em} % for the numbers of subsections of the TOC
28
29 % We use \MakeShortVerb of shortvrb and not \DefineShortVerb of fancyvrb
30 % because we don't want small elements in verbatim to be colored in gray
31 \usepackage{shortvrb}
32 \MakeShortVerb{\|}
33
34 \usepackage{fancyvrb}
35 \fvset{formatcom=\color{gray}}
36
37 \usepackage{titlesec}
38 \titlespacing*{\section}{0pt}{6.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}
39 \titlespacing*{\subsection}{0pt}{4.5ex plus 1ex minus .2ex}{2ex plus .2ex}
40
41
42 \def\interitem{\vspace{7mm plus 2 mm minus 3mm}}
43 \def\emphase{\bgroup\color{RoyalPurple}\let\next=}
44
45 \usepackage{footnote}
46 \usepackage{booktabs}
47 \usepackage{varwidth}
48 \usepackage{tcolorbox}
49 \usepackage{adjustbox}
50 \usepackage[auto-lang=false]{lipsum}
51
52 \NewDocumentEnvironment {scope} {} {} {}
53
54 \NewDocumentCommand {\pkg} {m} {\textsf{#1}}
55 \NewDocumentCommand {\cls} {m} {\textsf{#1}}
56
57 \setlength{\parindent}{0pt}
58 \skip \footins = 2 \bigskipamount
59
60
61 \NewDocumentCommand{\Definition}{m}
62 {{\setlength{\fboxsep}{1pt}\colorbox{gray!20}{\ttfamily \vphantom{gl}#1}}}
63
64 \NewDocumentCommand{\DefinitionCommand}{m}
65 {{\setlength{\fboxsep}{1pt}\colorbox{gray!20}{\ttfamily
66 \vphantom{gl}\textbackslash #1}}}
67
68
69 \usepackage{makeidx}
70 \makeindex
71
72
73 \usepackage{piton}
74 \let\myrlap\rlap
75 \PitonOptions{language = verbatim, detected-commands = {myrlap, emph,textsl}, splittable = 4}
76 \SetPitonStyle{ Number = , Comment = }
77
78 \ExplSyntaxOn
79
80 \dim_new:N \l__pantigny_width_dim
81
82 \keys_define:nn { pantigny }
83 {
84 width .dim_set:N = \l__pantigny_width_dim ,
85 annotation .code:n = \PitonOptions { annotation = #1 }
86 }
87
88 \NewPitonEnvironment { Code } { O { } }
89 {
90 \char_set_catcode_other:N |
91 \cs_set_eq:NN \emph \emphase
92 \dim_zero:N \l__pantigny_width_dim
93 \PitonOptions { annotation }
94 \keys_set:nn { pantigny } { #1 }
95 \color{gray}
96 \dim_compare:nNnT \l__pantigny_width_dim > \c_zero_dim
97 {
98 \PitonOptions { width = \l__pantigny_width_dim }
99 \begin{minipage}[c]{\l__pantigny_width_dim}
100 }
101 }
102 { \dim_compare:nNnT \l__pantigny_width_dim > \c_zero_dim
103 { \end{minipage} }
104 }
105
106
107 \ExplSyntaxOff
108
109
110 \NewDocumentCommand{\indexcommand}{m}{\index{#1@\texttt{\textbackslash #1}}}
111
112 \NewDocumentCommand{\indexenv}{m}{\index{#1@\texttt{\{#1\}}}}
113
114 \usepackage[hyperfootnotes = false]{hyperref}
115 \usepackage{bookmark}
116
117 \hypersetup
118 {
119 pdfinfo =
120 {
121 Title = The package 'nicematrix' ,
122 Subject = A LaTeX package ,
123 Author = F. Pantigny
124 }
125 }
126
127
128
129 \begin{document}
130
131 \UseName{VerbatimFootnotes}
132
133
134 \title{The package \pkg{nicematrix}\thanks{This document corresponds to the
135 version~\myfileversion\space of \pkg{nicematrix}, at the date of~\myfiledate.}}
136 \author{F. Pantigny \\ \texttt{[email protected]}}
137
138
139 \maketitle
140
141 \begin{abstract}
142 The LaTeX package \pkg{nicematrix} provides new environments similar to the
143 classical environments |{tabular}|, |{array}| and |{matrix}| of \pkg{array}
144 and \pkg{amsmath} but with extended features.
145 \end{abstract}
146
147
148
149
150 \vspace{1cm}
151 \hspace{1cm}
152 $\begin{bNiceArray}{cccc}[first-row,first-col,
153 code-for-first-col=\color{blue}\scriptstyle,
154 code-for-first-row=\color{blue}\scriptstyle,
155 columns-width = auto]
156 & C_1 & C_2 & \Cdots & C_n \\
157 L_1 & a_{11} & a_{12} & \Cdots & a_{1n} \\
158 L_2 & a_{21} & a_{22} & \Cdots & a_{2n} \\
159 \Vdots & \Vdots & \Vdots & \Ddots & \Vdots\\
160 L_n & a_{n1} & a_{n2} & \Cdots & a_{nn}
161 \end{bNiceArray}$\hspace{2cm}
162 \begin{NiceTabular}{lSSSS}[no-cell-nodes]
163 \CodeBefore
164 \rowcolor{red!15}{1-2}
165 \rowcolors{3}{blue!15}{}
166 \Body
167 \toprule
168 \Block[C]{2-1}{Product} & \multicolumn{3}{c}{dimensions (cm)}
169 & \Block[C]{2-1}{\rotate Price} \\
170 \cmidrule(rl){2-4}
171 & L & l & h \\
172 \midrule
173 small & 3 & 5.5 & 1 & 30 \\
174 standard & 5.5 & 8 & 1.5 & 50.5 \\
175 premium & 8.5 & 10.5 & 2 & 80 \\
176 extra & 8.5 & 10 & 1.5 & 85.5 \\
177 special & 12 & 12 & 0.5 & 70 \\
178 \bottomrule
179 \end{NiceTabular}
180
181 \vspace{1cm}
182 The package \pkg{nicematrix} is entirely contained in the file
183 |nicematrix.sty|. This file may be put in the current directory or in a
184 |texmf| tree. However, the best is to install \pkg{nicematrix} with a TeX
185 distribution such as MiKTeX, TeX Live or MacTeX.
186
187 \medskip
188 \emph{Remark}
189
190 \nobreak
191 If you use LaTeX via Internet with, for example, Overleaf or TeXPage, you
192 can upload the file |nicematrix.sty| in the repertory of your
193 project in order to take full advantage of the latest version de
194 \pkg{nicematrix}.\footnote{The latest version of the file
195 |nicematrix.sty| may be downloaded on the GitHub depot of \pkg{nicematrix}:\newline
196 \small
197 \url{https://github.com/fpantigny/nicematrix/releases}}
198
199 \medskip
200 This package can be used with |xelatex|, |lualatex|, |pdflatex| but also by
201 the classical workflow |latex|-|dvips|-|ps2pdf| (or Adobe Distiller).
202 \textsl{However, the file nicematrix.dtx of the present documentation should
203 be compiled with LuaLaTeX.}
204
205 \medskip
206 This package requires and \textbf{loads} the packages \pkg{array},
207 \pkg{amsmath}, \pkg{pgfcore} and the module \pkg{shapes} of \textsc{pgf}
208 (\pkg{tikz}, which is a layer over \textsc{pgf}, is \emph{not} loaded). The
209 final user only has to load the package with |\usepackage{nicematrix}|.
210
211
212 \medskip
213 The idea of \pkg{nicematrix} is to create \textsc{pgf} nodes under the cells and
214 the positions of the rules of the tabular created by \pkg{array} and to use
215 these nodes to develop new features. As usual with \textsc{pgf}, the coordinates
216 of these nodes are written in the |aux| file to be used on the next compilation and
217 that's why \pkg{nicematrix} may need \textbf{several compilations}\footnote{If
218 you use Overleaf, Overleaf will do automatically a sufficient number of
219 compilations (by using |latexmk|).}. One must not use the command |\nofiles|
220 (which prevents the creation of the |aux| file).
221
222 \medskip
223 Most features of \pkg{nicematrix} may be used without explicit use of
224 \textsc{pgf} or TikZ (which, in fact, is not loaded by default).
225
226 \medskip
227 \indexcommand{NiceMatrixOptions}
228 A command |\NiceMatrixOptions| is provided to fix the options (the
229 scope of the options fixed by this command is the current TeX group: they are
230 semi-global).
231
232 \newpage
233
234 \tableofcontents
235
236
237 \newpage
238
239 \section{The environments of this package}
240
241 The package \pkg{nicematrix} defines the following new environments.
242
243 \medskip
244 \begin{ttfamily}
245 \setlength{\tabcolsep}{3mm}
246 \begin{tabular}{lllll}
247 \{NiceTabular\} & \{NiceArray\} & \{NiceMatrix\} & \{NiceArrayWithDelims\} \\
248 \{NiceTabular*\} & \{pNiceArray\} & \{pNiceMatrix\} \\
249 \{NiceTabularX\} & \{bNiceArray\} & \{bNiceMatrix\} \\
250 & \{BNiceArray\} & \{BNiceMatrix\} \\
251 & \{vNiceArray\} & \{vNiceMatrix\} \\
252 & \{VNiceArray\} & \{VNiceMatrix\}
253 \end{tabular}
254 \end{ttfamily}
255
256 %
257 \medskip
258 The environments |{NiceArray}|, |{NiceTabular}| and |{NiceTabular*}| are
259 similar to the environments |{array}|, |{tabular}| and |{tabular*}| of the
260 package \pkg{array} (which is loaded by \pkg{nicematrix}).
261
262 \medskip
263 The environments |{pNiceArray}|, |{bNiceArray}|, etc. have no equivalent in
264 \pkg{array}.
265
266 \medskip
267 The environments |{NiceMatrix}|, |{pNiceMatrix}|, etc. are similar to the
268 corresponding environments of \pkg{amsmath} (which is loaded by
269 \pkg{nicematrix}): |{matrix}|, |{pmatrix}|, etc.
270
271 \medskip
272 The environment |{NiceTabularX}| is similar to the environment |{tabularx}| from
273 the eponymous package.\footnote{In fact, it's possible to use directly the |X|
274 columns in the environment |{NiceTabular}| (and the required width for the
275 tabular is fixed by the key |width|): cf.~\ref{X-columns},
276 p.~\pageref{X-columns}. Thus, it's possible to always avoid the environnement |{NiceTabularX}|}.
277
278 \medskip
279 The environment |\{NiceArrayWithDelims\}| is a generalisation of the environment
280 |{NiceArray}| and its variants (cf.~\ref{NiceArrayWithDelims}, p.~\pageref{NiceArrayWithDelims}).
281
282 \medskip
283 \textbf{It's recommended to use primarily the classical environments and to use
284 the environments of \pkg{nicematrix} only when some feature provided by these
285 environments is used (this will save memory and speed up the
286 compilation).}
287
288 \medskip
289 By the way, when using an environment of \pkg{nicematrix} it's often possible to
290 speed up the compilation by using the key \Definition{no-cell-nodes} (the
291 compilation time may be reduced by a factor of 3 or 4). Indeed, numerous
292 functionalities of \pkg{nicematrix} do not use the PGF/TikZ nodes created under
293 the contents of the cells (cf.~\ref{no-cell-nodes}, p.~\pageref{no-cell-nodes}) and the key
294 |no-cell-nodes| avoids their creation which is expensive (the creation of those
295 nodes can't be desactivated by \pkg{nicematrix} because \pkg{nicematrix} has no
296 way to know whether those nodes are used directly by the final user in an
297 environment |{tikzpicture}| after the environment of \pkg{nicematrix}).
298
299
300 \medskip
301 All the environments of the package \pkg{nicematrix} accept, between square
302 brackets, an optional list of \textsl{key=value} pairs. \textbf{There must be
303 no space before the opening bracket (|[|) of this list of options.}
304
305
306 \section{The vertical space between the rows}
307
308 \label{cell-space}
309 \index{cell-space-top-limit}
310 \index{cell-space-bottom-limit}
311 \index{cell-space-limits}
312
313
314 It's well known that some rows of the arrays created by default with LaTeX
315 are, by default, too close to each other. Here is a classical example.
316
317 \medskip
318 \begin{Code}[width=9cm]
319 $\begin{pmatrix}
320 \frac{1}{2} & -\frac{1}{2} \\
321 \frac{1}{3} & \frac{1}{4} \\
322 \end{pmatrix}$
323 \end{Code}
324 $\begin{pmatrix}
325 \frac{1}{2} & -\frac{1}{2} \\
326 \frac{1}{3} & \frac{1}{4} \\
327 \end{pmatrix}$
328
329 \bigskip
330 \index{cellspace@\pkg{cellspace} (package)}
331 Inspired by the package \pkg{cellspace} which deals with that problem, the
332 package \pkg{nicematrix} provides two keys \Definition{cell-space-top-limit}$^+$
333 and \Definition{cell-space-bottom-limit}$^+$ similar to the parameters of
334 \pkg{cellspace} called |\cellspacetoplimit| and
335 |\cellspacebottomlimit|.\footnote{One should remark that these parameters apply
336 also to the columns of type |S| of \pkg{siunitx} whereas the package
337 \pkg{cellspace} is not able to act on such columns of type~|S|.}
338
339 \smallskip
340 The initial values of these parameters is $0$~pt.
341
342 \smallskip
343 There is also a key \Definition{cell-space-limits}$^+$ to set both parameters at
344 once.
345
346 \smallskip
347 All these keys have a normal syntax but also an ``additive'' syntax. That means that it's
348 possible to write, for example, |cell-space-limits = 2pt| but also |cell-space-limits += 1pt|.
349
350
351 \medskip
352 \begin{Code}[width=9cm]
353 $\begin{pNiceMatrix}[\emph{cell-space-limits = 1pt}]
354 \frac12 & -\frac12 \\
355 \frac13 & \frac14 \\
356 \end{pNiceMatrix}$
357 \end{Code}
358 $\begin{pNiceMatrix}[no-cell-nodes,cell-space-limits = 1pt]
359 \frac12 & -\frac12 \\
360 \frac13 & \frac14 \\
361 \end{pNiceMatrix}$
362
363 \bigskip
364 It's also possible to change these parameters for only a few rows by using the
365 command |\RowStyle| provided by \pkg{nicematrix} (cf.~\ref{RowStyle}, p.~\pageref{RowStyle}).
366
367
368
369 \bigskip
370 \section{The vertical position of the arrays}
371
372 \index{baseline (key for an environment)}
373
374 The package \pkg{nicematrix} provides a option \Definition{baseline} for the
375 vertical position of the arrays. This option takes in as value an integer which
376 is the number of the row on which the array will be aligned.
377
378 \medskip
379 \begin{Code}[width=9cm]
380 $A = \begin{pNiceMatrix}[\emph{baseline=2}]
381 \frac{1}{\sqrt{1+p^2}} & p & 1-p \\
382 1 & 1 & 1 \\
383 1 & p & 1+p
384 \end{pNiceMatrix}$
385 \end{Code}
386 $A = \begin{pNiceMatrix}[baseline=2,no-cell-nodes]
387 \frac{1}{\sqrt{1+p^2}} & p & 1-p \\
388 1 & 1 & 1 \\
389 1 & p & 1+p
390 \end{pNiceMatrix}$
391
392
393 \medskip
394 It's also possible to use the option |baseline| with one of the special values
395 |t|, |c| or |b|. These letters may also be used absolutely like the option of
396 the environments |{tabular}| and |{array}| of \pkg{array}. The initial value
397 of |baseline| is~|c|.
398
399
400 \medskip
401 In the following example, we use the option |t| (equivalent to |baseline=t|)
402 immediately after an |\item| of list. One should remark that the presence of a
403 |\hline| at the beginning of the array doesn't prevent the alignment of the
404 baseline with the baseline of the first row (with |{tabular}| or |{array}| of
405 \pkg{array}, one must use |\firsthline|).
406
407 \medskip
408 \begin{Code}[width=9cm]
409 \begin{enumerate}
410 \item an item
411 \smallskip
412 \item \renewcommand{\arraystretch}{1.2}
413 $\begin{NiceArray}\emph{[t]}{lcccccc}
414 \hline
415 n & 0 & 1 & 2 & 3 & 4 & 5 \\
416 u_n & 1 & 2 & 4 & 8 & 16 & 32
417 \hline
418 \end{NiceArray}$
419 \end{enumerate}
420 \end{Code}
421 \begin{minipage}{5cm}
422 \begin{enumerate}
423 \item an item
424 \smallskip
425 \item \renewcommand{\arraystretch}{1.2}
426 $\begin{NiceArray}[t]{lcccccc}[no-cell-nodes]
427 \hline
428 n & 0 & 1 & 2 & 3 & 4 & 5 \\
429 u_n & 1 & 2 & 4 & 8 & 16 & 32 \\
430 \hline
431 \end{NiceArray}$
432 \end{enumerate}
433 \end{minipage}
434
435 \medskip
436 \clearpage
437 However, it's also possible to use the tools of
438 \pkg{booktabs}\footnote{The extension \pkg{booktabs} is \emph{not} loaded
439 by \pkg{nicematrix}.}: |\toprule|,
440 |\bottomrule|, |\midrule|, etc.
441
442 \nobreak
443 \smallskip
444 \begin{Code}[width=9cm]
445 \begin{enumerate}
446 \item an item
447 \smallskip
448 \item
449 $\begin{NiceArray}[t]{lcccccc}
450 \emph{\toprule}
451 n & 0 & 1 & 2 & 3 & 4 & 5 \\
452 \emph{\midrule}
453 u_n & 1 & 2 & 4 & 8 & 16 & 32
454 \emph{\bottomrule}
455 \end{NiceArray}$
456 \end{enumerate}
457 \end{Code}
458 \begin{minipage}{5cm}
459 \begin{enumerate}
460 \item an item
461 \smallskip
462 \item
463 $\begin{NiceArray}[t]{lcccccc}[no-cell-nodes]
464 \toprule
465 n & 0 & 1 & 2 & 3 & 4 & 5 \\
466 \midrule
467 u_n & 1 & 2 & 4 & 8 & 16 & 32 \\
468 \bottomrule
469 \end{NiceArray}$
470 \end{enumerate}
471 \end{minipage}
472
473 \bigskip
474 It's also possible to use the key |baseline| to align a matrix on an
475 horizontal rule (drawn by |\hline|). In this aim, one should give the value
476 |line-|\textsl{i} where \textsl{i} is the number of the row \emph{following} the
477 horizontal rule.
478
479 \smallskip
480 \begin{Verbatim}
481 \NiceMatrixOptions{cell-space-limits=1pt}
482 \end{Verbatim}
483
484 \smallskip
485 \begin{Code}[width=9cm]
486 $A=\begin{pNiceArray}{cc|cc}\emph{[baseline=line-3]}
487 \dfrac{1}{A} & \dfrac{1}{B} & 0 & 0 \\
488 \dfrac{1}{C} & \dfrac{1}{D} & 0 & 0 \\
489 \hline
490 0 & 0 & A & B \\
491 0 & 0 & D & D \\
492 \end{pNiceArray}$
493 \end{Code}
494 \begin{scope}
495 \NiceMatrixOptions{cell-space-limits=1pt}
496 \raisebox{-5mm}{$A=\begin{pNiceArray}{cc|cc}[baseline=line-3,no-cell-nodes]
497 \dfrac{1}{A} & \dfrac{1}{B} & 0 & 0 \\
498 \dfrac{1}{C} & \dfrac{1}{D} & 0 & 0 \\
499 \hline
500 0 & 0 & A & B \\
501 0 & 0 & D & D \\
502 \end{pNiceArray}$}
503 \end{scope}
504
505
506 \section{The blocks}
507 \label{Block}
508
509 \index{Blocks@\textbf{Blocks in the tabulars}|(}
510 \indexcommand{Block}
511
512
513 \subsection{General case}
514
515 In the environments of \pkg{nicematrix}, it's possible to use the command
516 \DefinitionCommand{Block} in order to place an element in the center of a
517 rectangle of merged cells of the array.\footnote{The spaces after a command |\Block| are deleted.}
518
519 The command |\Block| must be used in the upper leftmost cell of the cells of the
520 block with two mandatory arguments.
521
522 \begin{itemize}
523 \item The first argument is the size of the block with the syntax
524 $i$|-|$j$ where $i$ is the number of rows of the block and $j$ its number
525 of columns.
526
527 If this argument is empty, its default
528 value is |1-1|. If the number of rows is not specified, or equal to |*|, the
529 block extends until the last row (idem for the columns).
530
531 \item The second argument is the content of the block. In |{NiceTabular}|,
532 |{NiceTabular*}| and |{NiceTabularX}|, the content of the block is composed in
533 text mode whereas, in the other environments, it is composed in math mode.
534
535 Due to technical reasons of LaTeX, it's not possible to use |\color| at the
536 beginnning of the content of the block (but it's possible to use
537 |\textcolor|).\footnote{cf. \url{https://tex.stackexchange.com/questions/674788}}
538 \end{itemize}
539
540
541 \interitem
542 \clearpage
543 Here is an example of use of the command |\Block| in mathematical matrices.
544
545 \medskip
546 \begin{Code}[width=10.6cm]
547 $\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
548 \emph{\Block{3-3}{A}} & & & 0 \\
549 & & & \Vdots \\
550 & & & 0 \\
551 \hline
552 0 & \Cdots& 0 & 0
553 \end{bNiceArray}$
554 \end{Code}
555 $\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
556 \Block[C]{3-3}{A} & & & 0 \\
557 & & & \Vdots \\
558 & & & 0 \\
559 \hline
560 0 & \Cdots& 0 & 0
561 \end{bNiceArray}$
562
563 \bigskip
564 One may wish to raise the size of the ``$A$'' placed in the block of the
565 previous example. Since this element is composed in math mode, it's not
566 possible to use directly a command like |\large|, |\Large| and |\LARGE|.
567 That's why the command |\Block| provides an option between angle brackets to
568 specify some TeX code which will be inserted before the beginning of the
569 math mode.\footnote{This argument between angular brackets may also be used to
570 insert a command of font such as |\bfseries| when the command |\\| is used in
571 the content of the block. It's also possible to put in that optional argument
572 the command |\rotate| provided by \pkg{nicematrix} (cf.~\ref{rotate}, p.~\pageref{rotate}).}
573
574 \medskip
575 \begin{Code}[width=10.6cm]
576 $\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
577 \Block{3-3}\emph{<\Large>}{A} & & & 0 \\
578 0 & & & \Vdots \\
579 & & & 0 \\
580 \hline
581 0 & \Cdots& 0 & 0
582 \end{bNiceArray}$
583 \end{Code}
584 \begin{scope}
585 $\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
586 \Block[C]{3-3}<\Large>{A} & & & 0 \\
587 & & & \Vdots \\
588 & & & 0 \\
589 \hline
590 0 & \Cdots& 0 & 0
591 \end{bNiceArray}$
592 \end{scope}
593
594
595
596 \interitem
597 In fact, the command |\Block| accepts as first optional argument (between
598 square brackets) a list of pairs \textsl{key=value}.
599
600 First, there are keys which are quick tools to control the appearance of the block.
601
602 \begin{itemize}
603 \item \index{fill!key of \texttt{\textbackslash Block}}
604 the key \Definition{fill} takes in as value a color and fills the block
605 with that color;
606 \item \index{opacity!key of \texttt{\textbackslash Block}}
607 the key \Definition{opacity} sets the opacity of the filling color specified by
608 |fill|;\footnote{Caution: that feature creates instructions of
609 transparency in the \textsc{pdf} and some readers of \textsc{pdf} don't
610 support such instructions. The opacity is applied by using |\pgfsetfillopacity|.}
611 \item \index{draw (key of \texttt{\textbackslash Block})}
612 the key \Definition{draw} strokes the frame of the block with the current color
613 for the rules (however, it's possible to use another color by providing it
614 as value of the key |draw|);
615 \item \index{vlines!key of \texttt{\textbackslash Block}}
616 \index{hvlines!key of \texttt{\textbackslash Block}}
617 \index{hlines!key of \texttt{\textbackslash Block}}
618 the keys \Definition{hlines}, \Definition{vlines} and
619 \Definition{hvlines} draw all the corresponding rules in the
620 block;\footnote{However, the rules are not drawn in the sub-blocks of the
621 block, as always with \pkg{nicematrix}: the rules are not drawn in the blocks,
622 except when they have the key |transparent|
623 (cf.~\ref{rules} p.~\pageref{rules}).}
624 \item \index{rules/width (key of \texttt{\textbackslash Block})}
625 the key \Definition{rules/width} is the width of the rules (is relevant
626 only when one of the keys |draw|, |hvlines|, |vlines| and |hlines| is used);
627
628 \item \index{rules/color (key of \texttt{\textbackslash Block})}
629 the key \Definition{rules/width} is the width of the rules (is relevant
630 only when one of the keys |hvlines|, |vlines| and |hlines| is used);
631
632 \item \label{block-rounded-corners}
633 \index{rounded-corners!key of \texttt{\textbackslash Block}}
634 \index{Corners (rounded ---)!for a block} the key \Definition{rounded-corners}
635 requires rounded corners (for the frame drawn by |draw| and the shape drawn by
636 |fill|) with a radius equal to the value of that key (the default value is 4~pt,
637 which is the initial value of the \emph{rounded corners} of
638 TikZ)\footnote{There is also a key |rounded-corners| available for an
639 environment of \pkg{nicematrix} (cf.~\ref{tabular-rounded-corners}, p.~\pageref{tabular-rounded-corners}).} ;
640 \end{itemize}
641
642 \medskip
643 Sometimes, these tools are not sufficient to control the appearance of the
644 block. The following keys are more powerful but also more difficult to use.
645 Moreover, the require the loading of TikZ by the user (with
646 |\usepackage{tikz}|). By default, \pkg{nicematrix} does not load TikZ but only
647 \textsc{pgf}, which is a sublayer of TikZ.
648
649 \begin{itemize}
650 \item \index{borders (key of \texttt{\textbackslash Block})}
651 \index{tikzz@tikz!key of ``borders'' de \texttt{\textbackslash Block}}
652 The key \Definition{borders} provides the ability to draw only some
653 borders of the blocks; the value of that key is a (comma-separated) list of
654 elements covered by |left|, |right|, |top|, |bottom| and |all|; it's possible, in
655 fact, in the list which is the value of the key |borders|, to add an entry of
656 the form |tikz={|\textsl{list}|}| where \textsl{list} is a list of couples
657 \textsl{key=value} of TikZ specifying the graphical characteristics of the
658 lines that will be drawn (cf.~example~\ref{ex:borders}, p.~\pageref{ex:borders}). When the key
659 |borders| is used without value, it is equivalent to the key |draw| (without value).
660
661 \item \index{tikzz@tikz!key of \texttt{\textbackslash Block}}
662 When the key \Definition{tikz} is used, the TikZ path corresponding of
663 the rectangle which delimits the block is executed with TikZ\footnote{TikZ
664 should be loaded (by default, \pkg{nicematrix} only loads \textsc{pgf}) and,
665 if it's not, an error will be raised.} by using as options the value of that
666 key |tikz| (which must be a list of keys allowed for a TikZ path).
667
668 In fact, in the list of the keys provided by the user as value of |tikz|, it's
669 possible to put a key \Definition{offset}. That key is not provided by TikZ but
670 by \pkg{nicematrix}. It will narrow the rectangular frame corresponding to the
671 block by a margin (horizontally and vertically) equal to the value (of that key
672 |offset|). That new frame, a bit narrower, will be executed by TikZ with options
673 which are the other keys in the list of keys provided as value to the key |tikz|
674 of |\Block|.
675
676 For examples, cf.~\ref{tikz-key-examples}, p.~\pageref{tikz-key-examples}.
677 \end{itemize}
678
679
680 \medskip
681 There is also some technical keys:
682
683 \begin{itemize}
684 \item \index{name!key of \texttt{\textbackslash Block}}
685 the key \Definition{name} provides a name to the rectangular TikZ node
686 corresponding to the block; it's possible to use that name with TikZ in the
687 |\CodeAfter| of the environment (cf.~\ref{code-after}, p.~\pageref{code-after});
688 \item \index{respect-arraystretch (key of \texttt{\textbackslash Block})}
689 the key \Definition{respect-arraystretch} prevents the setting of
690 |\arraystretch| to $1$ at the beginning of the block (which is the behaviour
691 by default) ;
692 \item \index{transparent (key of \texttt{\textbackslash Block})}
693 By default, the rules are not drawn in the blocks (see the section about
694 the rules: section~\ref{rules}, p.~\pageref{rules}). However, if the key
695 \Definition{transparent} is used, the rules are drawn. For an example, see
696 section~\ref{tikz-key-examples}, p.~\pageref{tikz-key-examples}. Caution:
697 that key does not imply that the content of the block will be transparent!
698 \end{itemize}
699
700 There is also keys for the horizontal and vertical positions of the content of
701 the block: cf.~\ref{horizontal-block}, p.~\pageref{horizontal-block}.
702
703 \interitem
704 {\bfseries One must remark that, by default, the commands |\Blocks| don't create
705 space}. There is exception only for the blocks mono-column and the blocks
706 mono-row under some conditions as explained just below.
707
708 \medskip
709 In the following example, we have had to enlarge by hand the columns 2 and 3
710 (with the construction |w{c}{...}| of \pkg{array}).
711
712 \bigskip
713 \begin{Code}
714 \begin{NiceTabular}{cw{c}{2cm}w{c}{3cm}c}
715 rose & tulip & daisy & dahlia \\
716 violet
717 & \emph{\Block[C,draw=red,fill=[RGB]{204,204,255},rounded-corners]{2-2}
718 {\LARGE Some beautiful flowers}} & & marigold \\
719 & & marigold \\
720 iris & & & lis \\
721 arum & periwinkle & forget-me-not & hyacinth
722 \end{NiceTabular}
723 \end{Code}
724
725 \medskip
726 \begin{center}
727 \begin{NiceTabular}{cw{c}{2cm}w{c}{3cm}c}
728 rose & tulip & daisy & dahlia \\
729 violet & \Block[C,draw=red,fill=[RGB]{204,204,255},rounded-corners]{2-2}
730 {\LARGE Some beautiful flowers} & & marigold \\
731 iris & & & lis \\
732 arum & periwinkle & forget-me-not & hyacinth
733 \end{NiceTabular}
734 \end{center}
735
736 \subsection{The mono-column blocks}
737
738 The mono-column blocks have a special behaviour.
739
740 \begin{itemize}
741 \item The natural width of the contents of these blocks is taken into account
742 for the width of the current column.
743
744 In the columns with a fixed width (columns |w{...}{...}|, |W{...}{...}|,
745 |p{...}|, |b{...}|, |m{...}|, |V| and |X|), the content of the block is
746 formatted as a paragraph of that width.
747
748 \item The specification of the horizontal position provided by the type of
749 column (|c|, |r| or |l|) is taken into account for the blocks. For a block in a
750 column ot type |p{...}|, |b{...}|, |m{...}|, |V{...}| ou |X|, the alignment |c|
751 will be used by default. However, those types of columns may have an optional
752 argument for the horizontal alignment (eg: |p[l]{...}|) and, in that case, that
753 type of alignement is passed to the block.
754
755 Of course, the |\Block| may also have its own specification of alignment:
756 cf.~\ref{horizontal-block}, p.~\pageref{horizontal-block}.
757
758 \item The specifications of font specified for the column by a construction
759 |>{...}| in the preamble of the array are taken into account for the
760 mono-column blocks of that column (this behaviour is probably expected).
761 \end{itemize}
762
763
764 \bigskip
765 \begin{scope}
766 \hfuzz=10cm
767 \begin{Code}[width=12cm]
768 \begin{NiceTabular}{@{}>{\bfseries}lr@{}} \hline
769 \Block{2-1}{John} & 12 \\
770 & 13 \\ \hline
771 Steph & 8 \\ \hline
772 \Block{3-1}{Sarah} & 18 \\
773 & 17 \\
774 & 15 \\ \hline
775 Ashley & 20 \\ \hline
776 Henry & 14 \\ \hline
777 \Block{2-1}{Madison} & 15 \\
778 & 19 \\ \hline
779 \end{NiceTabular}
780 \end{Code}
781 \begin{NiceTabular}{@{}>{\bfseries}lr@{}}[baseline=c] \hline
782 \Block{2-1}{John} & 12 \\
783 & 13 \\ \hline
784 Steph & 8 \\ \hline
785 \Block{3-1}{Sarah} & 18 \\
786 & 17 \\
787 & 15 \\ \hline
788 Ashley & 20 \\ \hline
789 Henry & 14 \\ \hline
790 \Block{2-1}{Madison} & 15 \\
791 & 19 \\ \hline
792 \end{NiceTabular}
793 \end{scope}
794
795
796
797 \subsection{The mono-row blocks}
798
799 For the mono-row blocks, the natural height and depth are taken into account
800 for the height and depth of the current row (as does a standard |\multicolumn|
801 of LaTeX), except when an option of vertical position has been used for the block
802 (one of the keys |t|, |b|, |m|, |T| and |B| described in the part
803 \ref{vertical-pos-block}, p.~\pageref{vertical-pos-block}).
804
805 \subsection{The mono-cell blocks}
806
807 A mono-cell block inherits all the properties of the mono-row blocks and
808 mono-column blocks.
809
810 \medskip
811 At first sight, one may think that there is no point using a mono-cell block.
812 However, there are some good reasons to use such a block.
813 \begin{itemize}
814 \item It's possible to use the command |\\| in a (mono-cell) block.
815
816 \item It's possible to split the cell in several sub-cells with |&| when the
817 key |&-in-blocks| is in force (cf.~\ref{ampersand-in-blocks}, p.~\pageref{ampersand-in-blocks}).
818
819 \item It's possible to use the option of horizontal alignment of the block in
820 derogation of the type of column given in the preamble of the array.
821
822 \item It's possible do draw a frame around the cell with the key |draw| of the
823 command |\Block| and to fill the background with rounded corners with the keys
824 |fill| and |rounded-corners|.\footnote{If one simply wishes to color the
825 background of a unique cell, there is no point using the command |\Block|:
826 it's possible to use the command |\cellcolor|.}
827
828 \item It's possible to draw one or several borders of the cell with the key |borders|.
829 \end{itemize}
830
831
832
833 \subsection{Horizontal position of the content of the block}
834
835 \label{horizontal-block}
836
837 The command |\Block| accepts the keys \Definition{l}, \Definition{c} and
838 \Definition{r} for the horizontal position of its content.
839
840 \medskip
841 \begin{Code}[width=10.6cm]
842 $\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
843 \Block\emph{[r]}{3-3}<\LARGE>{A} & & & 0 \\
844 & & & \Vdots \\
845 & & & 0 \\
846 \hline
847 0 & \Cdots& 0 & 0
848 \end{bNiceArray}$
849 \end{Code}
850 $\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
851 \Block[r]{3-3}<\LARGE>{A} & & & 0 \\
852 & & & \Vdots \\
853 & & & 0 \\
854 \hline
855 0 & \Cdots& 0 & 0
856 \end{bNiceArray}$
857
858
859 \medskip
860 By default, the horizontal position of the content of a block is computed
861 by using the positions of the \emph{contents} of the columns implied in that
862 block. That's why, in the following example, the header ``First group'' is
863 correctly centered despite the instruction |!{\qquad}| in the preamble which
864 has been used to increase the space between the columns (this
865 is not the behaviour of |\multicolumn|).
866
867 \medskip
868 \begin{center}
869 \begin{Code}
870 \begin{NiceTabular}{@{}c!{\qquad}ccc\emph{!{\qquad}}ccc@{}}
871 \toprule
872 Rank & \emph{\Block{1-3}{First group}} & & & \Block{1-3}{Second group} \\
873 & 1A & 1B & 1C & 2A & 2B & 2C \\
874 \midrule
875 1 & 0.657 & 0.913 & 0.733 & 0.830 & 0.387 & 0.893\\
876 2 & 0.343 & 0.537 & 0.655 & 0.690 & 0.471 & 0.333\\
877 3 & 0.783 & 0.885 & 0.015 & 0.306 & 0.643 & 0.263\\
878 4 & 0.161 & 0.708 & 0.386 & 0.257 & 0.074 & 0.336\\
879 \bottomrule
880 \end{NiceTabular}
881 \end{Code}
882 \end{center}
883
884 \bigskip
885 \begin{center}
886 \begin{NiceTabular}{@{}c!{\qquad}ccc!{\qquad}ccc@{}}
887 \toprule
888 Rank & \Block{1-3}{First group} & & & \Block{1-3}{Second group} \\
889 & 1A & 1B & 1C & 2A & 2B & 2C \\
890 \midrule
891 1 & 0.657 & 0.913 & 0.733 & 0.830 & 0.387 & 0.893\\
892 2 & 0.343 & 0.537 & 0.655 & 0.690 & 0.471 & 0.333\\
893 3 & 0.783 & 0.885 & 0.015 & 0.306 & 0.643 & 0.263\\
894 4 & 0.161 & 0.708 & 0.386 & 0.257 & 0.074 & 0.336\\
895 \bottomrule
896 \end{NiceTabular}
897 \end{center}
898
899 \medskip
900 In order to have an horizontal positioning of the content of the block computed
901 with the limits of the columns of the LaTeX array (and not with the contents of
902 those columns), one may use the key \Definition{L}, \Definition{R} and
903 \Definition{C} of the command |\Block|.\footnote{Remark: The keys |L|, |C| and
904 |R| require less computations than the keys |l|, |c| and |r|. If you are
905 concernend about efficiency, you should use by default |\Block[C]|.}
906
907 \medskip
908 Here is the same example with the key |C| for the first block.
909
910 \medskip
911 \begin{center}
912 \begin{Code}
913 \begin{NiceTabular}{@{}c!{\qquad}ccc\emph{!{\qquad}}ccc@{}}
914 \toprule
915 Rank & \emph{\Block[C]{1-3}{First group}} & & & \Block{1-3}{Second group} \\
916 & 1A & 1B & 1C & 2A & 2B & 2C \\
917 \midrule
918 1 & 0.657 & 0.913 & 0.733 & 0.830 & 0.387 & 0.893\\
919 2 & 0.343 & 0.537 & 0.655 & 0.690 & 0.471 & 0.333\\
920 3 & 0.783 & 0.885 & 0.015 & 0.306 & 0.643 & 0.263\\
921 4 & 0.161 & 0.708 & 0.386 & 0.257 & 0.074 & 0.336\\
922 \bottomrule
923 \end{NiceTabular}
924 \end{Code}
925 \end{center}
926
927 \bigskip
928 \begin{center}
929 \begin{NiceTabular}{@{}c!{\qquad}ccc!{\qquad}ccc@{}}[no-cell-nodes]
930 \toprule
931 Rank & \Block[C]{1-3}{First group} & & & \Block{1-3}{Second group} \\
932 & 1A & 1B & 1C & 2A & 2B & 2C \\
933 \midrule
934 1 & 0.657 & 0.913 & 0.733 & 0.830 & 0.387 & 0.893\\
935 2 & 0.343 & 0.537 & 0.655 & 0.690 & 0.471 & 0.333\\
936 3 & 0.783 & 0.885 & 0.015 & 0.306 & 0.643 & 0.263\\
937 4 & 0.161 & 0.708 & 0.386 & 0.257 & 0.074 & 0.336\\
938 \bottomrule
939 \end{NiceTabular}
940 \end{center}
941
942 \bigskip
943 The command |\Block| supports also the keys |p| and |j|. With the key \Definition{p}, the
944 content of the block is formatted like a paragraph (as in a column of type |p|).
945 That key may be used in conjunction with a key |l|, |c| or |r|, and, in that
946 case, the paragraph is formatted with |\raggedright|, |\centering| or
947 |\raggedleft| (or |\RaggedRight|, |\Centering| and |\RaggedLeft| when \pkg{ragged2e}
948 is loaded). With the key \Definition{j} (which inforces the key |p|), the paragraph is
949 justified.
950
951 \bigskip
952 It's possible to put an environment |{itemize}| or |{enumerate}| in a block
953 which uses the key~|p| or |j| (in the other case, you will have a LaTeX error:
954 |Not allowed in LR mode|). For the following example, we have loaded the package
955 \pkg{enumitem} (for the key |left| of the environment |{itemize}|).
956
957 \smallskip
958 \begin{Verbatim}[formatcom = \footnotesize\color{gray}]
959 \usepackage{enumitem} % in the preamble
960 \end{Verbatim}
961
962 \smallskip
963 \begin{Code}
964 \begin{NiceTabular}[hvlines]{ccc}
965 one & two two & three three \\
966 one &
967 \Block\emph{[p]}{*-2}{%
968 \begin{itemize}[\emph{left=0pt}]
969 \item one two three four five
970 \item two
971 \item three
972 \end{itemize}
973 } \\
974 one & \\
975 one & \\
976 one & \\
977 one & \\
978 one & \\
979 one & \\
980 \end{NiceTabular}
981 \end{Code}
982
983
984 \begin{center}
985 \begin{NiceTabular}[hvlines]{ccc}
986 one & two two & three three \\
987 one &
988 \Block[p]{*-2}{%
989 \begin{itemize}[left=0pt]
990 \item one two three four five
991 \item two
992 \item three
993 \end{itemize}
994 } \\
995 one & \\
996 one & \\
997 one & \\
998 one & \\
999 one & \\
1000 one & \\
1001 \end{NiceTabular}
1002 \end{center}
1003
1004
1005 \subsection{Vertical position of the content of the block}
1006
1007 \label{vertical-pos-block}
1008
1009 For the vertical position, the command |\Blocks| supports the keys |m|, |t|,
1010 |b|, |T| and |B|.
1011
1012
1013 \begin{itemize}
1014 \item \index{v-center (key of \texttt{\textbackslash Block})} With the key
1015 \Definition{m}\footnote{That key has an alias: |v-center|.}, the content of the
1016 block is vertically centered.
1017 \item With the key \Definition{t}, the baseline of the content of the block is aligned
1018 with the baseline of the first row concerned by the block.
1019 \item with the key \Definition{b}, the baseline of the last row of the content of the
1020 block (we recall that the content of a block may contain several lines of text
1021 separated by |\\|) is aligned with the baseline of the last of the rows of the
1022 array involved in the block.
1023 \item With the key \Definition{T}, the content of the block is set upwards.
1024
1025 No vertical margin is added. However, the contents of the block is (always)
1026 composed by \pkg{nicematrix} in a |{minipage}|, a |{tabular}| or an |{array}|
1027 and, hence, there will still remain a margin (in most cases). If needed, it's
1028 always possible to add a |\strut|...
1029
1030 \item With the key \Definition{B}, the content of the block is set downwards.
1031 \end{itemize}
1032
1033 When no key is given, the key |m| applies (except in the mono-row blocks).
1034
1035
1036
1037 \medskip
1038 \begin{scope}
1039 \NiceMatrixOptions{rules/color=[gray]{0.75}, hvlines}
1040
1041 \begin{BVerbatim}
1042 \NiceMatrixOptions{rules/color=[gray]{0.75}, hvlines}
1043 \end{BVerbatim}
1044
1045 \bigskip
1046
1047 \begin{Code}[width=10cm]
1048 \begin{NiceTabular}{ccc}
1049 \Block[fill=red!10,\emph{t},l]{4-2}{two\\lines}
1050 & & \Huge Un\\
1051 & & deux \\
1052 & & trois \\
1053 & & \Huge quatre \\
1054 text & text \\
1055 \end{NiceTabular}
1056 \end{Code}
1057 \begin{NiceTabular}{ccc}
1058 \Block[fill=red!10,t,l]{4-2}{two\\lines}
1059 & & \Huge Un\\
1060 & & deux \\
1061 & & trois \\
1062 & & \Huge quatre \\
1063 text & text \\
1064 \end{NiceTabular}
1065
1066
1067 \bigskip
1068 \begin{Code}[width=10cm]
1069 \begin{NiceTabular}{ccc}
1070 \Block[fill=red!10,\emph{b},r]{4-2}{two\\lines}
1071 & & \Huge Un\\
1072 & & deux \\
1073 & & trois \\
1074 & & \Huge quatre \\
1075 text & text \\
1076 \end{NiceTabular}
1077 \end{Code}
1078 \begin{NiceTabular}{ccc}
1079 \Block[fill=red!10,b,r]{4-2}{two\\lines}
1080 & & \Huge Un\\
1081 & & deux \\
1082 & & trois \\
1083 & & \Huge quatre \\
1084 text & text \\
1085 \end{NiceTabular}
1086
1087 \bigskip
1088 \begin{Code}[width=10cm]
1089 \begin{NiceTabular}{ccc}
1090 \Block[fill=red!10,\emph{T},\emph{L}]{4-2}{two\\lines}
1091 & & \Huge Un\\
1092 & & deux \\
1093 & & trois \\
1094 & & \Huge quatre \\
1095 text & text \\
1096 \end{NiceTabular}
1097 \end{Code}
1098 \begin{NiceTabular}{ccc}
1099 \Block[fill=red!10,T,L]{4-2}{two\\lines}
1100 & & \Huge Un\\
1101 & & deux \\
1102 & & trois \\
1103 & & \Huge quatre \\
1104 text & text \\
1105 \end{NiceTabular}
1106
1107
1108 \bigskip
1109 \begin{Code}[width=10cm]
1110 \begin{NiceTabular}{ccc}
1111 \Block[fill=red!10,\emph{B},\emph{R}]{4-2}{two\\lines}
1112 & & \Huge Un\\
1113 & & deux \\
1114 & & trois \\
1115 & & \Huge quatre \\
1116 text & text \\
1117 \end{NiceTabular}
1118 \end{Code}
1119 \begin{NiceTabular}{ccc}
1120 \Block[fill=red!10,B,R]{4-2}{two\\lines}
1121 & & \Huge Un\\
1122 & & deux \\
1123 & & trois \\
1124 & & \Huge quatre \\
1125 text & text \\
1126 \end{NiceTabular}
1127
1128
1129 \end{scope}
1130
1131 \subsection{\texttt{\textbackslash\textbackslash} and \texttt{\&} in the blocks}
1132
1133 \label{ampersand-in-blocks}
1134 \index{ampersand-in-blocks}
1135 \index{\&-in-blocks}
1136
1137 \medskip
1138 The extension \pkg{nicematrix} provides the ability to use |\\| and |&| directly
1139 in the content of a block (in order to format its contents) but there is some
1140 rectrictions.
1141
1142 \begin{itemize}
1143 \item One must not use both |\\| and |&| in the same block.
1144
1145 \item For |\\|, there is no other restriction. It's possible to use |\\| in a
1146 block to format a text on several lines.
1147
1148 \item In order to use |&|, the key \Definition{ampersand-in-blocks} (alias:
1149 \Definition{\&-in-blocks}) must been activated\footnote{Otherwise, the use
1150 of~|&| in the command |\Block|
1151 will raise a TeX error :\\
1152 |! Extra alignment tab has been changed to \cr.|}. Then, the block is divided
1153 in sub-blocks as illustrated below. Be careful: when |ampersand-in-blocks| is in
1154 force, the (main) argument of the command |\Block| is syntactically divided into
1155 sub-blocks by splitting on the ampersands~|&|, the ampersands between curly
1156 braced are protected but not those in an environment.\footnote{It's not possible
1157 to write |\Block[ampersand-in-blocks]{}{\begin{array}{cc}1&2\end{array}}|. Of
1158 course, it's possible without the key |ampersand-in-blocks|.}
1159 \end{itemize}
1160
1161
1162 \bigskip
1163 With the ampersand |&|, it's possible to divide horizontally a block in
1164 sub-blocks of \emph{the same size}.
1165
1166 \medskip
1167 \begin{Code}[width=90mm]
1168 \begin{NiceTabular}{ll}%
1169 [hvlines,\emph{ampersand-in-blocks}]
1170 & the five first naturels numbers \\
1171 3 & \Block{}{one & two & three} \\
1172 4 & \Block{}{one& two & three & four} \\
1173 5 & \Block{}{one & two & three & four & five} \\
1174 \end{NiceTabular}
1175 \end{Code}
1176 %
1177 \begin{NiceTabular}{ll}%
1178 [hvlines,ampersand-in-blocks,no-cell-nodes]
1179 & the five first naturels numbers \\
1180 3 & \Block{}{one & two & three} \\
1181 4 & \Block{}{one& two & three & four} \\
1182 5 & \Block{}{one & two & three & four & five} \\
1183 \end{NiceTabular}
1184
1185
1186 As we can see, the blocks (which was are in fact mono-cell blocks) are divided
1187 into sub-blocks of the \emph{same size}. However, maybe the following code would
1188 be prefered.
1189
1190 \medskip
1191 \begin{Code}[width=90mm]
1192 \begin{NiceTabular}{lccccc}%
1193 [hvlines,\emph{ampersand-in-blocks}]
1194 & \Block{1-5}{the five first
1195 natural numbers} \\
1196 3 & \Block{1-5}{one & two & three} \\
1197 4 & \Block{1-5}{one& two &
1198 \cellcolor{red!15} three & four} \\
1199 5 & one & two & three & four & five \\
1200 \end{NiceTabular}
1201 \end{Code}
1202 %
1203 \begin{NiceTabular}{lccccc}%
1204 [hvlines,ampersand-in-blocks,no-cell-nodes]
1205 & \Block{1-5}{the five first natural numbers} \\
1206 3 & \Block{1-5}{one & two & three} \\
1207 4 & \Block{1-5}{one& two & \cellcolor{red!15} three & four} \\
1208 5 & one & two & three & four & five \\
1209 \end{NiceTabular}
1210
1211 \medskip
1212 In this code, we have blocks of size |1-5| which are divided into three or four
1213 sub-blocks.
1214
1215 \smallskip
1216 We have illustrated the fact that it's possible to color the background of a subcell
1217 of the block by using the key |\cellcolor|.
1218
1219
1220 \subsection{The key create-blocks-in-col}
1221 \index{create-blocks-in-col}
1222 \label{create-blocks-in-col}
1223
1224 The key \Definition{create-blocks-in-col} takes in as argument a list of numbers of columns
1225 and, for each of those columns, creates within that column a block for each non-empty cell
1226 (that block will enclose that non-empty cell and all the following empty cells in the column).
1227
1228 These blocks will be, as all the blocks, taken into account for the rules (drawn by |vlines|,
1229 |hlines|, etc.: cf.~\ref{rules}, p.~\pageref{rules}) and the commands that color the
1230 background of the cells (cf.~\ref{color-in-code-before}, p.~\pageref{color-in-code-before}).
1231 That the point using the key |create-blocks-in-col|.
1232
1233 \bigskip
1234 \begin{scope}
1235 \hfuzz=10cm
1236 \begin{Code}[width=11cm]
1237 \begin{NiceTabular}{lr}[hvlines,\emph{create-blocks-in-col=1}]
1238 \rowcolors{blue!10}{}[respect-blocks]
1239 John & 12 \\
1240 & 13 \\
1241 Steph & 8 \\
1242 Sarach & 18 \\
1243 & 17 \\
1244 & 15 \\
1245 Ashley & 20 \\
1246 Henry & 14 \\
1247 Madison & 15 \\
1248 & 19
1249 \end{NiceTabular}
1250 \end{Code}
1251 \begin{NiceTabular}{lr}[hvlines,baseline=c,create-blocks-in-col=1]
1252 \rowcolors{blue!10}{}[respect-blocks]
1253 John & 12 \\
1254 & 13 \\
1255 Steph & 8 \\
1256 Sarah & 18 \\
1257 & 17 \\
1258 & 15 \\
1259 Ashley & 20 \\
1260 Henry & 14 \\
1261 Madison & 15 \\
1262 & 19
1263 \end{NiceTabular}
1264 \end{scope}
1265
1266
1267
1268 \index{Blocks@\textbf{Blocks in the tabulars}|)}
1269
1270
1271 \section{The rules}
1272
1273 \label{rules}
1274 \index{Rules@\textbf{Rules in the tabulars}|(}
1275 \index{Lines in the tabulars|see{Rules}}
1276
1277 The usual techniques for the rules may be used in the environments of
1278 \pkg{nicematrix} (except |\vline|). However, there is some small differences
1279 with the classical environments.
1280
1281 \bigskip
1282 \subsection{Some differences with the classical environments}
1283
1284 \subsubsection{The vertical rules}
1285
1286 In the environments of \pkg{nicematrix}, the vertical rules specified by
1287 \verb+|+ in the preambles of the environments are never broken, even by an
1288 incomplete row or by a double horizontal rule specified by |\hline\hline|
1289 (there is no need to use the package~\pkg{hhline}).
1290
1291 \bigskip
1292 \begin{Code}[width=10cm]
1293 \begin{NiceTabular}{|c|c|} \hline
1294 First & Second \\ \emph{\hline\hline}
1295 Peter \\ \hline
1296 Mary & George\\ \hline
1297 \end{NiceTabular}
1298 \end{Code}
1299 \begin{NiceTabular}{|c|c|}[c] \hline
1300 First & Second \\ \hline\hline
1301 Peter \\ \hline
1302 Mary & George \\ \hline
1303 \end{NiceTabular}
1304
1305 \bigbreak
1306 However, the vertical rules are not drawn in the blocks (created by |\Block|:
1307 cf.~\ref{Block}, p.~\pageref{Block}) nor in the corners (created by the key |corner|:
1308 cf.~\ref{corners}, p.~\pageref{corners}) nor in the potential exterior rows (created by the
1309 keys |first-row| and |last-row|: cf.~\ref{exterior}, p.~\pageref{exterior}).
1310
1311 \medskip
1312 If you use |\multicolumn| there is no need to add the potential \verb+|+ or
1313 \verb+||+ at the end of the little preamble (but it's recommanded to use the
1314 command |\Block| in the environments of \pkg{nicematrix}).
1315
1316 \bigbreak
1317 \index{booktabs@\pkg{booktabs} (package)}
1318 If you use \pkg{booktabs} (which provides |\toprule|, |\midrule|,
1319 |\bottomrule|, etc.) and if you actually want to add vertical rules (which is
1320 not in the spirit of \pkg{booktabs}), you should notice that the vertical rules
1321 drawn by \pkg{nicematrix} are compatible with \pkg{booktabs}. Remark that
1322 \pkg{nicematrix} does \emph{not} load \pkg{booktabs}.
1323
1324 \medskip
1325 \begin{Code}[width=10.5cm]
1326 $\begin{NiceArray}{\emph{c|ccc}} \toprule
1327 a & b & c & d \\ \midrule
1328 1 & 2 & 3 & 4 \\
1329 1 & 2 & 3 & 4 \\ \bottomrule
1330 \end{NiceArray}$
1331 \end{Code}
1332 $\begin{NiceArray}{c|ccc}[no-cell-nodes]
1333 \toprule
1334 a & b & c & d \\
1335 \midrule
1336 1 & 2 & 3 & 4 \\
1337 1 & 2 & 3 & 4 \\
1338 \bottomrule
1339 \end{NiceArray}$
1340
1341 \bigskip
1342 However, it's still possible to define a specifier (named, for instance, |I|)
1343 to draw vertical rules with the standard behaviour of \pkg{array}. In this aim, we use
1344 the standard command |\newcolumntype| of \pkg{array}.
1345
1346 \medskip
1347 \begin{Code}[width=10cm]
1348 \emph{\newcolumntype{I}{!{\vrule}}}
1349 \begin{NiceTabular}{IcIcI} \hline
1350 First & Second \\ \hline\hline
1351 Peter & \\ \hline
1352 Mary & George\\ \hline
1353 Premier & Deuxième \\ \hline\hline
1354 Paul & \\ \hline
1355 Marie & Pauline \\ \hline
1356 \end{NiceTabular}
1357 \end{Code}
1358 %
1359 \begin{scope}
1360 \newcolumntype{I}{!{\vrule}}
1361 \begin{NiceTabular}{IcIcI} \hline
1362 First & Second \\ \hline\hline
1363 Peter & \\ \hline
1364 Mary & George\\ \hline
1365 Premier & Deuxième \\ \hline\hline
1366 Paul & \\ \hline
1367 Marie & Pauline \\ \hline
1368 \end{NiceTabular}
1369 \end{scope}
1370
1371 \medskip
1372 Of course, in this case, there is no point using |{NiceTabular}| and it's better
1373 to use the standard environment |{tabular}| but maybe we will have to use other
1374 functionalities provided by \pkg{nicematrix}. One should also consider the
1375 command |\EmptyRow| in the |\CodeBefore| (cf.~\ref{EmptyRow}, p.~\pageref{EmptyRow}).
1376
1377 \bigskip
1378 \subsubsection{The command \texttt{\textbackslash cline}}
1379
1380 \label{remark-cline}
1381 \index{cline@\texttt{\textbackslash cline} (LaTeX command)}
1382
1383 The horizontal and vertical rules drawn by |\hline| and the specifier
1384 ``\verb+|+'' make the array larger or wider by a quantity equal to the width
1385 of the rule (with \pkg{array} and also with \pkg{nicematrix}).
1386
1387 \smallskip
1388 For historical reasons, this is not the case with the command |\cline|, as
1389 shown by the following example.
1390
1391 \medskip
1392 \begin{Code}[width=10cm]
1393 \setlength{\arrayrulewidth}{2pt}
1394 \begin{tabular}{cccc} \hline
1395 A&B&C&D \\ \emph{\cline{2-2}}
1396 A&B&C&D \\ \hline
1397 \end{tabular}
1398 \end{Code}
1399 \begin{scope}
1400 \setlength{\arrayrulewidth}{2pt}
1401 \begin{tabular}[c]{cccc}
1402 \hline
1403 A&B&C&D \\
1404 \cline{2-2}
1405 A&B&C&D \\
1406 \hline
1407 \end{tabular}
1408 \end{scope}
1409
1410 \medskip
1411 \index{standard-cline}
1412 In the environments of \pkg{nicematrix}, this situation is corrected (it's
1413 still possible to go to the standard behaviour of |\cline| with the key
1414 \Definition{standard-cline}).
1415
1416 \medskip
1417 \begin{Code}[width=10cm]
1418 \setlength{\arrayrulewidth}{2pt}
1419 \begin{NiceTabular}{cccc} \hline
1420 A&B&C&D \\ \emph{\cline{2}}
1421 A&B&C&D \\ \hline
1422 \end{NiceTabular}
1423 \end{Code}
1424 \begin{scope}
1425 \setlength{\arrayrulewidth}{2pt}
1426 \begin{NiceTabular}[c]{cccc}[no-cell-nodes]
1427 \hline
1428 A&B&C&D \\ \cline{2}
1429 A&B&C&D \\ \hline
1430 \end{NiceTabular}
1431 \end{scope}
1432
1433 \medskip
1434 In the environments of \pkg{nicematrix}, an instruction |\cline{|\textsl{\texttt{i}}|}|
1435 is equivalent to |\cline{|\textsl{\texttt{i}}|-|\textsl{\texttt{i}}|}|.
1436
1437
1438 \subsection{The thickness and the color of the rules}
1439
1440 \indexcommand{arrayrulewidth}
1441 \index{Colour!of the rules}
1442 \index{width!subkey of ``rules''}
1443 \index{rules (key for an environment)}
1444
1445 The environments of \pkg{nicematrix} provide a key \Definition{rules/width} to
1446 set the width (in fact the thickness) of the rules in the current environment.
1447 In fact, this key merely sets the value of the standard LaTeX length
1448 |\arrayrulewidth|.
1449
1450 \smallskip
1451 It's well known that \pkg{colortbl} provides the command |\arrayrulecolor| in
1452 order to specify the color of the rules.
1453
1454 \smallskip
1455 \indexcommand{arrayrulecolor}
1456 With \pkg{nicematrix}, it's possible to specify the color of the rules even when
1457 \pkg{colortbl} is not loaded. For sake of compatibility, the command is also
1458 named |\arrayrulecolor|. However, \pkg{nicematrix} also provides a key
1459 \Definition{rules/color}, available in |\NiceMatrixOptions| or in an individual
1460 environment, to fix the color of the rules. This key sets the value locally
1461 (whereas |\arrayrulecolor| acts globally!) and should be preferred.
1462
1463 \medskip
1464 \begin{Code}[width=15cm]
1465 \begin{NiceTabular}{|ccc|}[\emph{rules/color=[gray]{0.9},rules/width=1pt}]
1466 \hline
1467 rose & tulipe & lys \\
1468 arum & iris & violette \\
1469 muguet & dahlia & souci \\
1470 \hline
1471 \end{NiceTabular}
1472 \end{Code}
1473 \hspace{-5cm}
1474 \begin{NiceTabular}{|ccc|}%
1475 [rules/color=[gray]{0.9},rules/width=1pt,no-cell-nodes]
1476 \hline
1477 rose & tulipe & lys \\
1478 arum & iris & violette \\
1479 muguet & dahlia & souci \\
1480 \hline
1481 \end{NiceTabular}
1482
1483
1484 \medskip
1485 In fact, in that example, instead of |\hline|, it would have a better choice to
1486 use |\Hline|, provided by \pkg{nicematrix} and described just below, because it
1487 ensures a better output in the PDF viewers at the low levels of zoom.
1488
1489 \subsection{The tools of \texorpdfstring{\pkg{nicematrix}}{nicematrix} for the rules}
1490
1491 Here are the tools provided by \pkg{nicematrix} for the rules.
1492 \begin{itemize}
1493 \item the keys |hlines|, |vlines|, |hvlines| and |hvlines-except-borders|;
1494 \item the specifier ``\verb+|+'' in the preamble (for the environments with
1495 preamble);
1496 \item \indexcommand{Hline}
1497 the command |\Hline|.
1498 \end{itemize}
1499
1500 \medskip
1501 \textbf{All these tools don't draw the rules in the blocks nor in the
1502 empty corners (when the key |corners| is used), nor in the exterior rows and
1503 columns.}
1504 \begin{itemize}
1505 \item These blocks are:
1506 \begin{itemize}
1507 \item the blocks created by the command |\Block|\footnote{And also the command |\multicolumn| but
1508 it's recommended to use instead |\Block| in the environments of
1509 \pkg{nicematrix}.} (cf.~\ref{Block}, p.~\pageref{Block});
1510 \item the blocks createad by the key |create-blocks-in-col|:
1511 (cf.~\ref{create-blocks-in-col}, p.~\pageref{create-blocks-in-col});
1512 \item the blocks implicitly delimited by the dotted leaders created
1513 by |\Cdots|, |\Vdots|, etc. (cf.~\ref{Cdots}, p.~\pageref{Cdots}).
1514 \end{itemize}
1515 \item The corners are created by the key |corners| explained below (cf.~\ref{corners},
1516 p.~\pageref{corners}).
1517 \item For the exterior rows and columns, cf.~\ref{exterior}, p.~\pageref{exterior}.
1518 \end{itemize}
1519
1520 In particular, this remark exhibits a first difference between the standard
1521 command |\hline| and the command |\Hline| provided by \pkg{nicematrix}.
1522
1523 Moreover, the key |\Hline| takes in an optional argument (between square
1524 brackets) which is a list of \textsl{key=value} pairs. For the description of
1525 those keys, see |custom-line|, in the section~\ref{custom-line}, p.~\pageref{custom-line}.\footnote{Technical
1526 remark: If the user wants to write a command over the command |\Hline|, it
1527 shall be ensured that this new command is expandable in the TeX sens (by
1528 using, for instance, |\NewExpandableDocumentCommand| of LaTeX3, |\newcommand|
1529 of LaTeX or |\def| of TeX). Example:
1530 |\NewExpandableDocumentCommand}{}{\Hline[color=red]}|}
1531
1532
1533 \bigskip
1534 As well as the command |\Hline|, the specifier ``\verb+|+'' supports an optional
1535 argument between square brackets for the characteristics of the rule.
1536
1537 \medskip
1538 \begin{Code}[width=10cm]
1539 \begin{NiceTabular}{ | c \emph{|[color=blue]} c |}
1540 \Hline
1541 a & b \\
1542 \emph{\Hline[color=red]}
1543 c & d \\
1544 \Hline
1545 \end{NiceTabular}
1546 \end{Code}
1547 %
1548 \begin{NiceTabular}{|c|[color=blue]c|}[no-cell-nodes]
1549 \Hline
1550 a & b \\
1551 \Hline[color=red]
1552 c & d \\
1553 \Hline
1554 \end{NiceTabular}
1555
1556
1557
1558 \subsubsection{The keys hlines and vlines}
1559
1560 \index{hlines|see{Rules}}
1561 \index{hlines!key for an environment}
1562 \index{vlines|see{Rules}}
1563 \index{vlines!key for an environment}
1564
1565 The keys \Definition{hlines} and \Definition{vlines} draw horizontal and vertical rules.
1566
1567 If no value is provided, all the rules are drawn.
1568
1569 \medskip
1570 When a value is provided, it should be a comma-separated list of numbers (corresponding
1571 to the rules which will be drawn).
1572 \begin{itemize}
1573 \item It's possible to put some intervals of integers with the syntax $i$|-|$j$
1574
1575 \item It's possible to put negative numbers (which are counted from the end).
1576 \end{itemize}
1577
1578 In fact, for the environments with delimiters (such as |{pNiceMatrix}| or
1579 |{bNiceArray}|), the key |vlines| don't draw the exterior rules (this is
1580 certainly the expected behaviour).
1581
1582 \medskip
1583 \begin{Code}[width=10.6cm]
1584 $\begin{pNiceMatrix}[\emph{vlines},rules/width=0.2pt]
1585 1 & 2 & 3 & 4 & 5 & 6 \\
1586 1 & 2 & 3 & 4 & 5 & 6 \\
1587 1 & 2 & 3 & 4 & 5 & 6
1588 \end{pNiceMatrix}$
1589 \end{Code}
1590 $\begin{pNiceMatrix}[vlines,rules/width=0.2pt,no-cell-nodes]
1591 1 & 2 & 3 & 4 & 5 & 6 \\
1592 1 & 2 & 3 & 4 & 5 & 6 \\
1593 1 & 2 & 3 & 4 & 5 & 6
1594 \end{pNiceMatrix}$
1595
1596
1597 \medskip
1598 When the key |hlines| is in force, it's still possible to use |\Hline\Hline| to
1599 put a double horizontal rule. As well, it's possible to put \verb+||+ in the
1600 preamble (of an environment with preamble) to put a double vertical rule, even
1601 when the key |vlines| is in force.
1602
1603 \medskip
1604 \begin{Code}[width=10.6cm]
1605 $\begin{NiceArray}{c\emph{||}ccccc}[hlines,vlines]
1606 & a & b & c & d & e \\ \emph{\Hline\Hline}
1607 x & 0 & 0 & 0 & 0 & 0 \\
1608 y & 0 & 0 & 0 & 0 & 0 \\
1609 z & 0 & 0 & 0 & 0 & 0 \\
1610 \end{NiceArray}$
1611 \end{Code}
1612 $\begin{NiceArray}{c||ccccc}[hvlines,no-cell-nodes]
1613 & a & b & c & d & e \\ \Hline\Hline
1614 x & 0 & 0 & 0 & 0 & 0 \\
1615 y & 0 & 0 & 0 & 0 & 0 \\
1616 z & 0 & 0 & 0 & 0 & 0 \\
1617 \end{NiceArray}$
1618
1619
1620
1621 \subsubsection{The keys hvlines, hlines-except-borders and hvlines-except-borders}
1622 \label{hvlines}
1623
1624 \index{hvlines|see{Rules}}
1625 \index{hvlines!key for an environment}
1626 \index{hvlines-except-borders}
1627 \index{hlines-except-borders}
1628
1629
1630 The key \Definition{hvlines} (no value) is the conjunction of the keys |hlines|
1631 and |vlines|.
1632
1633 \smallskip
1634 \begin{Code}
1635 \begin{NiceTabular}{cccc}[\emph{hvlines},rules={color=blue,width=1pt}]
1636 rose & tulip & sunflower & lily \\
1637 violet & \Block[C,draw=red]{2-2}{\LARGE flowers} & & orchid \\
1638 carnation & & & lys \\
1639 daisy & peony & jasmine & magnolia
1640 \end{NiceTabular}
1641 \end{Code}
1642
1643 \begin{center}
1644 \setlength{\arrayrulewidth}{1pt}
1645 \begin{NiceTabular}{cccc}[hvlines,rules={color=blue,width=1pt}]
1646 rose & tulip & sunflower & lily \\
1647 violet & \Block[C,draw=red]{2-2}{\LARGE flowers} & & orchid \\
1648 carnation & & & lys \\
1649 daisy & peony & jasmine & magnolia
1650 \end{NiceTabular}
1651 \end{center}
1652
1653 \bigskip
1654 It's worth noting that, when the key |rounded-corners| is used for the
1655 environment |{NiceTabular}|, the key |hvlines| draws rounded corners for the
1656 exterior frame of the tabular (cf.~\ref{tabular-rounded-corners},
1657 p.~\pageref{tabular-rounded-corners}).
1658
1659 \bigskip
1660 The key \Definition{hlines-except-borders} is similar to the key |hlines| but
1661 does not draw the rules on the horizontal borders of the array. The key
1662 \Definition{hvlines-except-borders} is similar to the key |hvlines| but does not
1663 draw the rules on the horizontal and vertical borders of the array. For an
1664 example of use of that key, see the part ``Use with tcolorbox''
1665 (\ref{tcolorbox}, p.~\pageref{tcolorbox}).
1666
1667 \subsubsection{The (empty) corners}
1668
1669 \label{corners}
1670 \index{Corners (the empty ---)}
1671 \index{corners (key of an environment)}
1672
1673 The four |corners| of an array will be designed by |NW|, |SW|, |NE| and |SE|
1674 (\emph{north west}, \emph{south west}, \emph{north east} and \emph{south east}).
1675
1676 For each of these corners, we will call \emph{empty corner} (or simply
1677 \emph{corner}) the reunion of all the empty rectangles starting from the cell
1678 actually in the corner of the array.\footnote{For sake of completeness, we
1679 should also say that a cell contained in a block (even an empty cell) is not
1680 taken into account for the determination of the corners. That behaviour is
1681 natural. The precise definition of a ``non-empty cell'' is given below (cf.~\ref{empty-cells},
1682 p.~\pageref{empty-cells}).}
1683
1684 However, it's possible, for a cell without content, to require \pkg{nicematrix}
1685 to consider that cell as not empty with the command |\NotEmpty|.
1686
1687 \bigskip
1688 \begin{minipage}{9cm}
1689 In the example on the right (where B is in the center of a block of size
1690 $2\times2$), we have colored in blue the four (empty) corners of the array.
1691 \end{minipage}\hspace{2cm}%
1692 \begin{NiceTabular}
1693 [cell-space-top-limit=3pt,
1694 hvlines,
1695 rules={color=white,width=0.1pt} ,
1696 no-cell-nodes
1697 ]
1698 {*{6}{c}}
1699 \CodeBefore
1700 \rectanglecolor{blue!10}{1-1}{4-2}
1701 \rectanglecolor{blue!10}{1-1}{1-4}
1702 \rectanglecolor{blue!10}{1-6}{3-6}
1703 \rectanglecolor{blue!10}{7-1}{9-1}
1704 \rectanglecolor{blue!10}{7-5}{9-6}
1705 \Body
1706 & & & & A \\
1707 & & A & A & A \\
1708 & & & A \\
1709 & & A & A & A & A \\
1710 A & A & A & A & A & A \\
1711 A & A & A & A & A & A \\
1712 & A & A & A \\
1713 & \Block{2-2}{B} & & A \\
1714 & & & A \\
1715 \end{NiceTabular}
1716
1717 \bigskip
1718 When the key \Definition{corners}\footnote{The key |corners| that we describe now
1719 has no direct link with the key |rounded-corners| described in the part
1720 \ref{tabular-rounded-corners}, p.~\pageref{tabular-rounded-corners}.} is used,
1721 \pkg{nicematrix} computes the (empty) corners and these corners will be taken
1722 into account by the tools for drawing the rules (the rules won't be drawn in
1723 the corners).
1724
1725 \bigskip
1726 \begin{Code}[width=11cm]
1727 \NiceMatrixOptions{cell-space-top-limit=3pt}
1728 \begin{NiceTabular}{*{6}{c}}[\emph{corners},hvlines]
1729 & & & & A \\
1730 & & A & A & A \\
1731 & & & A \\
1732 & & A & A & A & A \\
1733 A & A & A & A & A & A \\
1734 A & A & A & A & A & A \\
1735 & A & A & A \\
1736 & \Block[C]{2-2}{B} & & A \\
1737 & & & A \\
1738 \end{NiceTabular}
1739 \end{Code}
1740 \begin{NiceTabular}{*{6}{c}}%
1741 [
1742 corners,
1743 hvlines,
1744 cell-space-top-limit=3pt
1745 ]
1746 & & & & A \\
1747 & & A & A & A \\
1748 & & & A \\
1749 & & A & A & A & A \\
1750 A & A & A & A & A & A \\
1751 A & A & A & A & A & A \\
1752 & A & A & A \\
1753 & \Block[C]{2-2}{B} & & A \\
1754 & & & A \\
1755 \end{NiceTabular}
1756
1757
1758 \bigskip
1759 It's also possible to provide to the key |corners| a (comma-separated) list of
1760 corners (designed by |NW|, |SW|, |NE| and |SE|).
1761
1762 \medskip
1763 \begin{Code}[width=11cm]
1764 \NiceMatrixOptions{cell-space-top-limit=3pt}
1765 \begin{NiceTabular}{*{6}{c}}[\emph{corners=NE},hvlines]
1766 1\\
1767 1&1\\
1768 1&2&1\\
1769 1&3&3&1\\
1770 1&4&6&4&1\\
1771 & & & & &1
1772 \end{NiceTabular}
1773 \end{Code}
1774 \begin{NiceTabular}{*{6}{c}}%
1775 [c,corners=NE,hvlines,cell-space-top-limit=3pt]
1776 1\\
1777 1&1\\
1778 1&2&1\\
1779 1&3&3&1\\
1780 1&4&6&4&1\\
1781 & & & & &1
1782 \end{NiceTabular}
1783
1784
1785 \medskip
1786 $\triangleright$ The corners are also taken into account by the tools provided
1787 by \pkg{nicematrix} to color cells, rows and columns. These tools don't color
1788 the cells which are in the corners (cf.~\ref{color-in-code-before},
1789 p.~\pageref{color-in-code-before}). The command |\TikzEveryCell| available in
1790 the |\CodeBefore| and the |\CodeAfter| (cf.~\ref{TikzEveryCell},
1791 p.~\pageref{TikzEveryCell}) takes also into account the empty corners.
1792
1793 \subsubsection{The command \texttt{\textbackslash diagbox}}
1794
1795 \indexcommand{diagbox}
1796
1797 The command \DefinitionCommand{diagbox} (inspired by the package \pkg{diagbox}),
1798 allows, when it is used in a cell, to slash that cell diagonally downwards.
1799
1800 \medskip
1801 \begin{Code}[width=10cm]
1802 $\begin{NiceArray}{*{5}{c}}[hvlines]
1803 \emph{\diagbox{x}{y}} & e & a & b & c \\
1804 e & e & a & b & c \\
1805 a & a & e & c & b \\
1806 b & b & c & e & a \\
1807 c & c & b & a & e
1808 \end{NiceArray}$
1809 \end{Code}
1810 $\begin{NiceArray}{*{5}{c}}[hvlines,no-cell-nodes]
1811 \diagbox{x}{y} & e & a & b & c \\
1812 e & e & a & b & c \\
1813 a & a & e & c & b \\
1814 b & b & c & e & a \\
1815 c & c & b & a & e
1816 \end{NiceArray}$
1817
1818 \medskip
1819 It's possible to use the command |\diagbox| in a |\Block|.
1820
1821 \medskip
1822 \begin{Code}[width=10cm]
1823 $\begin{NiceArray}{*{5}{c}}[hvlines]
1824 \emph{\Block{2-2}{\diagbox{x}{y}}} & & a & b & c \\
1825 & & a & b & c \\
1826 a & a & e & c & b \\
1827 b & b & c & e & a \\
1828 c & c & b & a & e
1829 \end{NiceArray}$
1830 \end{Code}
1831 $\begin{NiceArray}{*{5}{c}}[hvlines,no-cell-nodes]
1832 \Block{2-2}{\diagbox{x}{y}} & & a & b & c \\
1833 & & a & b & c \\
1834 a & a & e & c & b \\
1835 b & b & c & e & a \\
1836 c & c & b & a & e
1837 \end{NiceArray}$
1838
1839 \medskip
1840 But it's also possible to use |\diagbox| for the diagonal rule only (and the
1841 labels are put but the usual way, that is to say in the cells of the tabular).
1842
1843 \medskip
1844 \begin{Code}[width=10cm]
1845 $\begin{NiceArray}{*{5}{c}}[hvlines]
1846 \emph{\Block{2-2}{\diagbox{}{}}} & y & a & b & c \\
1847 x & & a & b & c \\
1848 a & a & e & c & b \\
1849 b & b & c & e & a \\
1850 c & c & b & a & e
1851 \end{NiceArray}$
1852 \end{Code}
1853 $\begin{NiceArray}{*{5}{c}}[hvlines,no-cell-nodes]
1854 \Block{2-2}{\diagbox{}{}} & y & a & b & c \\
1855 x & & a & b & c \\
1856 a & a & e & c & b \\
1857 b & b & c & e & a \\
1858 c & c & b & a & e
1859 \end{NiceArray}$
1860
1861 \medskip
1862 Nevertheless, it's always possible to draw whatever rule we wish with TikZ in
1863 the |\CodeAfter| (or the |\CodeBefore|) by using the PGF/TikZ nodes created by
1864 \pkg{nicematrix}: cf.~\ref{PGF-nodes}, p.~\pageref{PGF-nodes}.
1865
1866
1867 \subsubsection{Commands for customized rules}
1868
1869 \label{custom-line}
1870 \index{command (key of ``custom-line'')}
1871 \index{ccommand (key of ``custom-line'')}
1872 \index{letter (key of ``custom-line'')}
1873 \index{custom-line|(}
1874
1875
1876 It's also possible to define commands and letters for customized rules with the
1877 key \Definition{custom-line} available in |\NiceMatrixOptions| and in the
1878 options of individual environments. That key takes in as argument a list of
1879 \textsl{key=value} pairs. First, there is three keys to define the tools which
1880 will be used to use that new type of rule.
1881
1882 \begin{itemize}
1883 \item the key \Definition{command} is the name (\emph{with} or \emph{without}
1884 the backslash) of a command that will be created by \pkg{nicematrix} and that
1885 will be available for the final user in order to draw horizontal rules
1886 (similarly to |\hline|);
1887
1888 \item the key \Definition{ccommand} is the name (\emph{with} or \emph{without}
1889 the backslash) of a command that will be created by \pkg{nicematrix} and that
1890 will be available for the final user to order to draw partial horizontal rules
1891 (similarly to |\cline|, hence the name |ccommand|): the argument of that command
1892 will be list of intervals of columns specified by the syntax~$i$ or
1893 $i$-$j$.\footnote{It's recommended to use such commands only once in a row
1894 because each use will create space between the rows corresponding to the total
1895 width of the rule. Likewise, it's possible to draw several rules with only one
1896 use of the command.}
1897
1898 \item the key \Definition{letter} takes in as argument a letter\footnote{The following
1899 letters are forbidden: \verb+lcrpmbVX|()[]!@<>+} that the user will use in
1900 the preamble of an environment with preamble (such as |{NiceTabular}| in order
1901 to specify a vertical rule.
1902 \end{itemize}
1903
1904 \bigskip
1905 We will now speak of the keys which describe the rule itself. Those keys may
1906 also be used in the (optional) argument of an individual command |\Hline| or in
1907 the (optional) argument of a specifier ``\verb+|+'' in the preamble of an
1908 environment.
1909
1910 \bigskip
1911 There are four possibilities:
1912 \begin{itemize}[beginpenalty=10000]
1913 \item the basic rules, which may be drawn by using (for example) \pkg{colortbl}:
1914 these are simple or multiple rules, with color and a color between the rules;
1915 \item the dashed rules (key |dashed|);
1916 \item the dotted rules (key |dotted|);
1917 \item all the rules which may be draw with TikZ (key |tikz|).
1918 \end{itemize}
1919
1920
1921 \bigskip
1922 We will now describe these four kinds of rules.
1923 \begin{itemize}[beginpenalty=10000]
1924 \item \emph{First possibility}
1925
1926 \nobreak
1927 It's possible to specify composite rules, with a color and a color for the
1928 inter-rule space (as possible with \pkg{colortbl} for instance).
1929
1930 \begin{itemize}
1931 \index{multiplicity (key of ``custom-line'')}
1932 \index{color!key of ``custom-line''}
1933 \index{sep-color (key of ``custom-line'')}
1934 \item the key \Definition{multiplicity} is the number of consecutive rules that
1935 will be drawn: for instance, a value of $2$ will create double rules such those
1936 created by |\hline\hline| or \verb+||+ in the preamble of an environment;
1937
1938 \item the key \Definition{color} sets the color of the rules ;
1939
1940 \item the key \Definition{sep-color} sets the color between two successive rules
1941 (should be used only in conjunction with |multiplicity|). The name of that key
1942 is inspired by the command |\doublerulesepcolor| of \pkg{colortbl}.
1943 \end{itemize}
1944
1945 \medskip
1946 That system may be used, in particular, for the definition of commands and
1947 letters to draw rules with a specific color (and those rules will respect the
1948 blocks and corners as do all the rules of \pkg{nicematrix}).
1949
1950 \medskip
1951 \begin{Code}
1952 \begin{NiceTabular}{lcIcIc}\emph{[custom-line = {letter=I, color=red}]}
1953 \Hline
1954 & \Block{1-3}{dimensions} \\
1955 & L & l & h \\
1956 \Hline
1957 Product A & 3 & 1 & 2 \\
1958 Product B & 1 & 3 & 4 \\
1959 Product C & 5 & 4 & 1 \\
1960 \Hline
1961 \end{NiceTabular}
1962 \end{Code}
1963
1964
1965 \begin{center}
1966 \begin{NiceTabular}{lcIcIc}[custom-line = {letter=I, color=red},no-cell-nodes]
1967 \Hline
1968 & \Block[C]{1-3}{dimensions} \\
1969 & L & l & H \\
1970 \Hline
1971 Product A & 3 & 1 & 2 \\
1972 Product B & 1 & 3 & 4 \\
1973 Product C & 5 & 4 & 1 \\
1974 \Hline
1975 \end{NiceTabular}
1976 \end{center}
1977
1978
1979 \bigskip
1980 The key |sep-color| with the value |white| may also be used in case of an
1981 horizontal double-rule on the top of a colored cell (if we want the space
1982 between both rules above the cell not colored by the color of the cell).
1983
1984 \begin{scope}
1985 \NiceMatrixOptions
1986 {
1987 custom-line =
1988 {
1989 command = \DoubleRule ,
1990 multiplicity = 2 ,
1991 sep-color = white
1992 }
1993 }
1994
1995
1996 \begin{Code}[width=10cm]
1997 \NiceMatrixOptions
1998 {
1999 custom-line =
2000 {
2001 command = \DoubleRule ,
2002 multiplicity = 2 ,
2003 \emph{sep-color = white}
2004 }
2005 }
2006
2007 \begin{NiceTabular}{ccc}
2008 one & two & three \\
2009 \emph{\DoubleRule}
2010 four & \cellcolor{yellow} five & six \\
2011 \end{NiceTabular}
2012 \end{Code}
2013 \begin{NiceTabular}{ccc}
2014 one & two & three \\
2015 \DoubleRule
2016 four & \cellcolor{yellow} five & six \\
2017 \end{NiceTabular}
2018
2019 \end{scope}
2020
2021
2022 \bigskip
2023 \item \emph{Second possibilité} : the key \Definition{dashed}
2024
2025 \indexcommand{hdashedline}
2026 \indexcommand{cdashedline}
2027
2028 \nobreak
2029 \smallskip
2030 The extension \pkg{nicematrix} provides the commands
2031 \DefinitionCommand{hdashedline} and \DefinitionCommand{cdashedline} and the
2032 letter «|;|» for dashed rules. They are available when TikZ is loaded because
2033 it's merely a line of TikZ with the style
2034 |dash pattern = on 4 pt off 2pt|. In fact, when the TikZ library \pkg{decorations}
2035 is loaded (with |\usetikzlibrary{decorations}|), the key |dash expand off| is added
2036 for a better output.
2037
2038 \bigskip
2039 Thus, it's possible to use the commands |\hdashedline| and |\cdashedline|
2040 to draw horizontal dashed rules.
2041
2042 \medskip
2043 \begin{Verbatim}[formatcom = \footnotesize \color{gray}]
2044 \usepackage{tikz} % in the preamble
2045 \usetikzlibrary{decorations} % in the preamble
2046 \end{Verbatim}
2047
2048 \smallskip
2049 \begin{Code}[width=9.5cm]
2050 \begin{pNiceMatrix}
2051 1 & 2 & 3 & 4 & 5 \\
2052 \emph{\hdashedline}
2053 6 & 7 & 8 & 9 & 10 \\
2054 \emph{\cdashedline{1,4-5}}
2055 11 & 12 & 13 & 14 & 15
2056 \end{pNiceMatrix}
2057 \end{Code}
2058 $\begin{pNiceMatrix}[no-cell-nodes]
2059 1 & 2 & 3 & 4 & 5 \\
2060 \hdashedline
2061 6 & 7 & 8 & 9 & 10 \\
2062 \cdashedline{1,4-5}
2063 11 & 12 & 13 & 14 & 15
2064 \end{pNiceMatrix}$
2065
2066
2067 \medskip
2068 In the environments with an explicit preamble (like |{NiceTabular}|, |{NiceArray}|, etc.),
2069 it's possible to draw a vertical dashed rule with the specifier ``|;|''.
2070
2071 \medskip
2072 \begin{Code}[width=9.5cm]
2073 \begin{pNiceArray}{cccc\emph{;}c}
2074 1 & 2 & 3 & 4 & 5 \\
2075 6 & 7 & 8 & 9 & 10 \\
2076 11 & 12 & 13 & 14 & 15
2077 \end{pNiceArray}
2078 \end{Code}
2079 $\begin{pNiceArray}{cccc;c}[no-cell-nodes]
2080 1 & 2 & 3 & 4 & 5 \\
2081 6 & 7 & 8 & 9 & 10 \\
2082 11 & 12 & 13 & 14 & 15
2083 \end{pNiceArray}$
2084
2085 \medskip
2086 If you wish a more important reservation of space for those rules, you should
2087 define, with |custom-line|, some new commands by using the key |dashed| in conjonction
2088 with the key |total-width|.
2089
2090 \smallskip
2091 \begin{Code}
2092 \NiceMatrixOptions
2093 {
2094 custom-line =
2095 {
2096 command = \myhdashedline ,
2097 ccommand = \mycdashedline ,
2098 dashed,
2099 \emph{total-width = 10 pt}
2100 }
2101 }
2102 \end{Code}
2103
2104
2105 \NiceMatrixOptions
2106 {
2107 custom-line =
2108 {
2109 command = \myhdashedline ,
2110 ccommand = \mycdashedline ,
2111 dashed,
2112 total-width = 10 pt
2113 }
2114 }
2115
2116
2117 \smallskip
2118 \begin{Code}[width=9.5cm]
2119 \begin{pNiceMatrix}
2120 1 & 2 & 3 & 4 & 5 \\
2121 \emph{\myhdashedline}
2122 6 & 7 & 8 & 9 & 10 \\
2123 \emph{\mycdashedline{1,4-5}}
2124 11 & 12 & 13 & 14 & 15
2125 \end{pNiceMatrix}
2126 \end{Code}
2127 $\begin{pNiceMatrix}[no-cell-nodes]
2128 1 & 2 & 3 & 4 & 5 \\
2129 \myhdashedline
2130 6 & 7 & 8 & 9 & 10 \\
2131 \mycdashedline{1,4-5}
2132 11 & 12 & 13 & 14 & 15
2133 \end{pNiceMatrix}$
2134
2135
2136
2137
2138
2139 \bigskip
2140 \item \emph{Troisième possibilité} : the key \Definition{dotted}
2141
2142 \label{dotted}
2143 \index{dotted (clé de «custom-line»)}
2144 \indexcommand{hdottedline}
2145 \indexcommand{cdottedline}
2146
2147 \nobreak
2148 \smallskip
2149 The extension \pkg{nicematrix} provides the commands
2150 \DefinitionCommand{hdottedline} and \DefinitionCommand{cdottedline} and
2151 the letter «|:|» for dotted lines. For these lines, \pkg{nicematrix} does not use TikZ
2152 but an internal system. In fact, it's the same as the system used by the commands
2153 |\Cdots|, |\Vdots|, etc. (cf.~\ref{Cdots}, p.~\pageref{Cdots}).
2154
2155 \bigskip
2156 Thus, it's possible to use the commands |\hdottedline| and |\cdottedline|
2157 to draw horizontal dotted rules.
2158
2159
2160 \smallskip
2161 \begin{Code}[width=9.5cm]
2162 \begin{pNiceMatrix}
2163 1 & 2 & 3 & 4 & 5 \\
2164 \emph{\hdottedline}
2165 6 & 7 & 8 & 9 & 10 \\
2166 \emph{\cdottedline{1,4-5}}
2167 11 & 12 & 13 & 14 & 15
2168 \end{pNiceMatrix}
2169 \end{Code}
2170 $\begin{pNiceMatrix}[no-cell-nodes]
2171 1 & 2 & 3 & 4 & 5 \\
2172 \hdottedline
2173 6 & 7 & 8 & 9 & 10 \\
2174 \cdottedline{1,4-5}
2175 11 & 12 & 13 & 14 & 15
2176 \end{pNiceMatrix}$
2177
2178
2179 \medskip
2180 \medskip
2181 In the environments with an explicit preamble (like |{NiceTabular}|, |{NiceArray}|, etc.),
2182 it's possible to draw a vertical dotted rule with the specifier ``|:|''.
2183
2184 \medskip
2185 \begin{Code}[width=9.5cm]
2186 \begin{pNiceArray}{cccc\emph{:}c}
2187 1 & 2 & 3 & 4 & 5 \\
2188 6 & 7 & 8 & 9 & 10 \\
2189 11 & 12 & 13 & 14 & 15
2190 \end{pNiceArray}
2191 \end{Code}
2192 $\begin{pNiceArray}{cccc:c}[no-cell-nodes]
2193 1 & 2 & 3 & 4 & 5 \\
2194 6 & 7 & 8 & 9 & 10 \\
2195 11 & 12 & 13 & 14 & 15
2196 \end{pNiceArray}$
2197
2198 \medskip
2199 Like with the key |dashed| described previously, it's possible to use this
2200 key in conjunction with the key |total-width|.
2201
2202
2203 \bigskip
2204 \item \emph{Fourth possibility} : the key \Definition{tikz}
2205
2206 \index{tikzz@tikz!key of ``custom-line''}
2207 \index{total-width (key of ``custom-line'')}
2208
2209 \nobreak
2210 It's possible to use the key |tikz| (if TikZ is loaded). In that
2211 case, the rule is drawn directly with TikZ by using as parameters the value of
2212 the key |tikz| which must be a list of \textsl{key=value} pairs which may be
2213 applied to a TikZ path.
2214
2215 By default, no space is reserved for the rule that will be drawn with TikZ. It
2216 is possible to specify a reservation (horizontal for a vertical rule and
2217 vertical for an horizontal one) with the key \Definition{total-width}. That
2218 value of that key, is, in some ways, the width of the rule that will be drawn
2219 (\pkg{nicematrix} does not compute that width from the characteristics of the
2220 rule specified in |tikz|).
2221
2222 \bigskip
2223 \begin{Verbatim}[formatcom = \footnotesize \color{gray}]
2224 \usepackage{tikz} % in the preamble
2225 \usetikzlibrary{decorations.pathmorphing} % in the preamble
2226 \end{Verbatim}
2227
2228
2229 \begin{Code}[width=9.1cm]
2230 \NiceMatrixOptions
2231 {
2232 custom-line =
2233 {
2234 letter = I ,
2235 \emph{tikz = { decorate, decoration = zigzag } ,
2236 total-width = 6 pt}
2237 }
2238 }
2239
2240 \begin{NiceTabular}{cIcIc}
2241 one & two & three \\
2242 four & five & six \\
2243 seven & eight & nine
2244 \end{NiceTabular}
2245 \end{Code}
2246 \begin{scope}
2247 \NiceMatrixOptions
2248 {
2249 custom-line =
2250 {
2251 letter = I ,
2252 tikz = { decorate, decoration = zigzag } ,
2253 total-width = 6 pt
2254 }
2255 }
2256 \begin{NiceTabular}{cIcIc}[no-cell-nodes]
2257 one & two & three \\
2258 four & five & six \\
2259 seven & eight & nine
2260 \end{NiceTabular}
2261 \end{scope}
2262 \end{itemize}
2263
2264 \vspace{1cm}
2265 \index{start (key for the rules)}
2266 \index{end (key for the rules)}
2267
2268 As we have said, the previous keys may be used in the optional argument
2269 of an individual command |\Hline| and in the optional argument of a specifier
2270 ``\verb+|+'' in the preamble of an environment (for instance |{NiceTabular}|).
2271
2272 However, in that case, it's also possible to use two other keys, \Definition{start}
2273 and \Definition{end}, which specify the extremities of the rule.
2274
2275 \medskip
2276 \begin{Code}[width=9.5cm]
2277 \begin{NiceTabular}{cc\emph{|[color=blue,start=2]}ccc}
2278 one & two & three & four
2279 \emph{\Hline[start=2,end=3]}
2280 five & six & seven & eight \\
2281 nine & ten & eleven & twelve
2282 \end{NiceTabular}
2283 \end{Code}
2284 \begin{NiceTabular}{cc|[color=blue,start=2]cc}
2285 one & two & three & four \\
2286 \Hline[start=2,end=3]
2287 five & six & seven & eight \\
2288 nine & ten & eleven & twelve
2289 \end{NiceTabular}
2290
2291
2292
2293 \subsubsection{The key fix-vertex}
2294
2295 \index{fix-vertex (subkey of rules)}
2296
2297 \colorbox{yellow!50}{\bfseries New 7.9}
2298
2299 \nobreak
2300 \smallskip
2301 Assume that we have defined a command |\RandomLine| for a line which zigzags randomly:
2302
2303 \medskip
2304 \begin{Verbatim}[formatcom = \footnotesize \color{gray}]
2305 \usepackage{tikz} % in the preamble
2306 \usetikzlibrary{decorations.pathmorphing} % in the preamble
2307 \end{Verbatim}
2308
2309 \medskip
2310 \begin{footnotesize}
2311 \begin{Code}
2312 \NiceMatrixOptions
2313 {
2314 custom-line =
2315 {
2316 command = \emph{\RandomLine} ,
2317 tikz =
2318 {
2319 decorate ,
2320 decoration = { random steps, segment length = 5pt, amplitude = 3pt }
2321 }
2322 }
2323 }
2324 \end{Code}
2325 \end{footnotesize}
2326
2327 \NiceMatrixOptions
2328 {
2329 custom-line =
2330 {
2331 command = \RandomLine ,
2332 tikz =
2333 {
2334 decorate ,
2335 decoration = { random steps, segment length = 5pt, amplitude = 3pt }
2336 }
2337 }
2338 }
2339
2340 \clearpage
2341 \medskip
2342 Let's consider the following tabular, with |\RandomLine| used at the end:
2343
2344 \medskip
2345 \pgfmathsetseed{47}
2346 \begin{Code}[width=9.5cm]
2347 \begin{NiceTabular}{ccc}[vlines]
2348 \Hline
2349 Name & First name & Age \\
2350 \Hline
2351 Dubourg & Claude & 88 \\
2352 Challa & Remy & 72 \\
2353 Ducar & Estelle & 75 \\
2354 Migaud & Sophie & 18 \\[1mm]
2355 \emph{\RandomLine}
2356 \end{NiceTabular}
2357 \end{Code}
2358 \begin{NiceTabular}{ccc}[vlines]
2359 \Hline
2360 Name & First name & Age \\
2361 \Hline
2362 Dubourg & Claude & 88 \\
2363 Challa & Remy & 72 \\
2364 Ducar & Estelle & 75 \\
2365 Migaud & Sophie & 18 \\[1mm]
2366 \RandomLine
2367 \end{NiceTabular}
2368
2369 \bigskip
2370 The internal vertical rules won't always stop exactly at the bottom line
2371 since that line goes randomly from the bottom left corner to the bottom right one.
2372
2373 In order to address this problem, \pkg{nicematrix} provides the key
2374 \Definition{rules/fix-vertex}. When that key is in force, the rules are divided
2375 in segments between the vertices and those segments are drawn independently of each other.
2376
2377 \nobreak
2378 \medskip
2379 \begin{Code}[width=9.5cm]
2380 \begin{NiceTabular}{ccc}[vlines,\emph{rules/fix-vertex}]
2381 \Hline
2382 Name & First name & Age \\
2383 \Hline
2384 Dubourg & Claude & 88 \\
2385 Challa & Remy & 72 \\
2386 Ducar & Estelle & 75 \\
2387 Migaud & Sophie & 18 \\[1mm]
2388 \emph{\RandomLine}
2389 \end{NiceTabular}
2390 \end{Code}
2391 \begin{NiceTabular}{ccc}[vlines,rules/fix-vertex]
2392 \Hline
2393 Name & First name & Age \\
2394 \Hline
2395 Dubourg & Claude & 88 \\
2396 Challa & Remy & 72 \\
2397 Ducar & Estelle & 75 \\
2398 Migaud & Sophie & 18 \\[1mm]
2399 \RandomLine
2400 \end{NiceTabular}
2401
2402
2403
2404
2405 \index{custom-line|)}
2406
2407
2408 \subsubsection{The key default-line}
2409
2410 \index{default-line}
2411
2412 \colorbox{yellow!50}{\bfseries New 7.9}
2413
2414 \nobreak
2415 \smallskip
2416 The package \pkg{nicematrix} provides the key \Definition{default-line} which
2417 sets the style of all the rules that will be drawn by the command |\Hline|, the
2418 specifier \verb+|+ in the preambles of the environments and the keys |hvlines|,
2419 |vlines|, |hlines|, etc. The different ways for the specification of the rules
2420 are the sames as those for the key |custom-line| (cf.~\ref{custom-line},
2421 p.~\pageref{custom-line}).
2422
2423
2424 \bigskip
2425 \begin{Verbatim}[formatcom = \footnotesize \color{gray}]
2426 \usepackage{tikz} % in the preamble
2427 \usetikzlibrary{decorations.pathmorphing} % in the preamble
2428 \end{Verbatim}
2429
2430
2431 \begin{footnotesize}
2432 \begin{Code}
2433 \NiceMatrixOptions
2434 {
2435 \emph{default-line} =
2436 {
2437 tikz =
2438 {
2439 decorate ,
2440 decoration = { random steps, segment length = 3pt, amplitude = 1pt }
2441 }
2442 }
2443 }
2444 \end{Code}
2445 \end{footnotesize}
2446
2447 \bigskip
2448 \begin{scope}
2449 \NiceMatrixOptions
2450 {
2451 default-line =
2452 {
2453 tikz =
2454 {
2455 decorate ,
2456 decoration = { random steps, segment length = 3pt, amplitude = 1pt }
2457 }
2458 }
2459 }
2460
2461 \renewcommand{\arraystretch}{1.3}%
2462
2463 \begin{Code}[width=11cm]
2464 \renewcommand{\arraystretch}{1.3}
2465 \begin{NiceTabular}{ccc}[\emph{hvlines,rules/fix-vertex}]
2466 one & two & three \\
2467 four & five & six \\
2468 seven & \Block{1-2}{eight} \\
2469 \end{NiceTabular}
2470 \end{Code}
2471 \begin{NiceTabular}{ccc}[hvlines,rules/fix-vertex,no-cell-nodes]
2472 one & two & three \\
2473 four & five & six \\
2474 seven & \Block{1-2}{eight} \\
2475 \end{NiceTabular}
2476
2477 \end{scope}
2478
2479
2480
2481 \index{Rules@\textbf{Rules in the tabulars}|)}
2482
2483
2484 \section{The color of the background of the rows and columns}
2485
2486 \index{Colour!of the cells}
2487
2488 \subsection{Use of \texorpdfstring{\pkg{colortbl}}{colortbl}}
2489
2490 \index{colortbl@\pkg{colortbl} (package)}
2491
2492 We recall that the package \pkg{colortbl} can be loaded directly with
2493 |\usepackage{colortbl}| or by loading \pkg{xcolor} with the key |table|:
2494 |\usepackage[table]{xcolor}|.
2495
2496 \medskip
2497 However, there is two drawbacks:
2498 \begin{itemize}
2499 \item The package \pkg{colortbl} patches \pkg{array}, leading to some
2500 incompatibilities (for instance with the command |\hdotsfor|).
2501
2502 \item The package \pkg{colortbl} constructs the array row by row, alterning
2503 colored rectangles, rules and contents of the cells. The resulting
2504 \textsc{pdf} is difficult to interpret by some \textsc{pdf} viewers and may
2505 lead to artefacts on the screen.
2506 \begin{itemize}
2507 \item Some rules seem to disappear. This is because many PDF viewers give
2508 priority to graphical element drawn posteriorly (which is in the spirit of the
2509 ``painting model'' of PostScript and PDF). Concerning this problem, MuPDF
2510 (which is used, for instance, by SumatraPDF) gives better results than Adobe
2511 Reader.
2512 \item A thin white line may appear between two cells of the same color. This
2513 phenomenon occurs when each cell is colored with its own instruction |fill|
2514 (the PostScript operator |fill| noted |f| in PDF). This is the case with
2515 \pkg{colortbl}: each cell is colored on its own, even when |\columncolor| or
2516 |\rowcolor| is used.
2517
2518 As for this phenomenon, Adobe Reader gives better results than MuPDF
2519 (however, it seems, that, in recent versions of MuPDF, the problem has
2520 been solved...).
2521 \end{itemize}
2522
2523 The package \pkg{nicematrix} provides tools to avoid both problems.
2524 \end{itemize}
2525
2526 \subsection{The tools of \texorpdfstring{\pkg{nicematrix}}{nicematrix} in the \texttt{\textbackslash CodeBefore}}
2527
2528 \label{color-in-code-before}
2529 \index{code-before!key for an environment}
2530 \index{CodeBefore@\texttt{\textbackslash CodeBefore}...\texttt{\textbackslash Body}}
2531 \index{Body@\texttt{\textbackslash Body}|see{\texttt{\textbackslash CodeBefore}}}
2532
2533 The package \pkg{nicematrix} provides some tools to draw the colored panels
2534 first, and, then, the content of the cells and the rules. This strategy is more
2535 conform to the ``painting model'' of the formats PostScript and \textsc{pdf} and
2536 is more suitable for the \textsc{pdf} viewers. However, it requires several
2537 compilations.\footnote{If you use Overleaf, Overleaf will do automatically a
2538 sufficient number of compilations.}
2539
2540 \medskip
2541 The extension \pkg{nicematrix} provides a key |code-before| for some code that
2542 will be executed before the drawing of the tabular.
2543
2544 \medskip
2545 An alternative syntax is provided: it's possible to put the content of that
2546 |code-before| between the keywords |\CodeBefore| and |\Body| at the beginning
2547 of the environment.
2548
2549 \smallskip
2550 \begin{Code}
2551 \begin{pNiceArray}{\textsl{preamble}}
2552 \emph{\CodeBefore [\textsl{options}]}
2553 \textsl{instructions of the code-before}
2554 \emph{\Body}
2555 \textsl{contents of the environment}
2556 \end{pNiceArray}
2557 \end{Code}
2558
2559 \smallskip
2560 The optional argument between square brackets is a list of \textsl{key=value}
2561 pairs which will be presented progressively in this
2562 documentation.\footnote{The available keys are |create-cell-nodes|,
2563 |sub-matrix| (and its subkeys) and \texttt{delimiters-color}.}
2564
2565 \medskip
2566 New commands are available in that |\CodeBefore|: |\cellcolor|,
2567 |\rectanglecolor|, |\rowcolor|, |\columncolor|, |\rowcolors|,
2568 |\rowlistcolors|, |\chessboardcolors| and |\arraycolor|.\footnote{Remark that,
2569 in the |\CodeBefore|, PGF/TikZ nodes of the form ``\verb+(i-|j)+'' are
2570 also available to indicate the position to the potential rules:
2571 cf.~\ref{nodes-i}, p.~\pageref{nodes-i}.}
2572 \label{code-before}
2573
2574 \index{cellcolor@\texttt{\textbackslash cellcolor}!command of
2575 \texttt{\textbackslash CodeBefore}}
2576 \index{rectanglecolor@\texttt{\textbackslash rectanglecolor} (in
2577 \texttt{\textbackslash CodeBefore})}
2578 \index{rowcolor@\texttt{\textbackslash rowcolor}!command of \texttt{\textbackslash CodeBefore}}
2579 \index{columncolor@\texttt{\textbackslash columncolor}!command of
2580 \texttt{\textbackslash CodeBefore}}
2581 \index{rowcolors@\texttt{\textbackslash rowcolors} (command of \texttt{\textbackslash CodeBefore})}
2582 \index{rowlistcolor@\texttt{\textbackslash rowlistcolors} (command of
2583 \texttt{\textbackslash CodeBefore})}
2584 \index{chessboardcolors@\texttt{\textbackslash chessboardcolors}!(commande
2585 du \texttt{\textbackslash CodeBefore})}
2586 \index{arraycolor@\texttt{\textbackslash arraycolor} (command of \texttt{\textbackslash
2587 CodeBefore)}}
2588
2589 The names of these commands are inspired by the names of the commands provided
2590 by \pkg{colortbl}.
2591
2592
2593 \medskip
2594 These commands don't color the cells which are in the ``corners'' if the key
2595 |corners| is used (cf.~\ref{corners}, p.~\pageref{corners}).
2596
2597 \medskip
2598 These commands respect the rounded corners if the key |rounded-corners|
2599 (cf.~\ref{tabular-rounded-corners}, p.~\pageref{tabular-rounded-corners}) has been used.
2600
2601 \medskip
2602 All these commands accept an optional argument, between square brackets and
2603 in first position. That optional argument may contain two elements (separated
2604 by a comma)
2605 \begin{itemize}
2606 \item the colorimetric space (|RGB|, |rgb|, |HTML|, etc) as specified by the
2607 the extension \pkg{xcolor};
2608 \item \index{opacity!key of commands such as\newline \texttt{\textbackslash rowcolor}, etc.}
2609 a specification of opacity of the form \texttt{opacity =
2610 \textsl{value}}.\footnote{Caution: that feature creates instructions of
2611 transparency in the \textsc{pdf} and some readers of \textsc{pdf} don't
2612 support such instructions. The opacity is applied by using |\pgfsetfillopacity|
2613 of \textsc{pgf}.}
2614 \end{itemize}
2615
2616 \bigskip
2617
2618 We describe now in detail those commands.
2619
2620 \medskip
2621 \begin{itemize}
2622 \item The command \Definition{\textbackslash cellcolor} takes its name from
2623 the command |\cellcolor| of \pkg{colortbl}.
2624
2625 This command takes in as mandatory arguments a color and a \textbf{list of cells}, each
2626 of which with the format $i$-$j$ where $i$ is the number of the row and $j$ the
2627 number of the column of the cell. In fact, despite its name, this command may
2628 be used to color a whole row (with the syntax $i$-) or a whole column (with the
2629 syntax -$j$).
2630
2631 \medskip
2632 \begin{scope}
2633 \hfuzz=10cm
2634 \begin{Code}[width=10cm]
2635 \begin{NiceTabular}{ccc}[hvlines]
2636 \CodeBefore
2637 \emph{\cellcolor[HTML]{FFFF88}{3-1,2-2,-3}}
2638 \Body
2639 a & b & c \\
2640 e & f & g \\
2641 h & i & j \\
2642 \end{NiceTabular}
2643 \end{Code}
2644 \begin{NiceTabular}{ccc}[hvlines,no-cell-nodes]
2645 \CodeBefore
2646 \cellcolor[HTML]{FFFF88}{3-1,2-2,-3}
2647 \Body
2648 a & b & c \\
2649 e & f & g \\
2650 h & i & j \\
2651 \end{NiceTabular}
2652 \end{scope}
2653
2654 \bigskip
2655 \item The command \Definition{\textbackslash rectanglecolor} takes three
2656 mandatory arguments. The first is the color. The second is the upper-left cell
2657 of the rectangle and the third is the lower-right cell of the rectangle.
2658
2659 \medskip
2660 \begin{scope}
2661 \hfuzz=10cm
2662 \begin{Code}[width=10cm]
2663 \begin{NiceTabular}{ccc}[hvlines]
2664 \CodeBefore
2665 \emph{\rectanglecolor{blue!15}{2-2}{3-3}}
2666 \Body
2667 a & b & c \\
2668 e & f & g \\
2669 h & i & j \\
2670 \end{NiceTabular}
2671 \end{Code}
2672 \begin{NiceTabular}{ccc}[hvlines,no-cell-nodes]
2673 \CodeBefore
2674 \rectanglecolor{blue!15}{2-2}{3-3}
2675 \Body
2676 a & b & c \\
2677 e & f & g \\
2678 h & i & j \\
2679 \end{NiceTabular}
2680 \end{scope}
2681
2682 \bigskip
2683 \item The command \Definition{\textbackslash arraycolor} takes in as mandatory
2684 argument a color and color the whole tabular with that color (except the
2685 potential exterior rows and columns: cf.~\ref{exterior}, p.~\pageref{exterior}).
2686 It's only a particular case of |\rectanglecolor|.
2687
2688
2689 \bigskip
2690 \item The command \Definition{\textbackslash chessboardcolors} takes in as
2691 mandatory arguments two colors and it colors the cells of the tabular in
2692 quincunx with these colors.
2693
2694 \medskip
2695 \begin{scope}
2696 \hfuzz=10cm
2697 \begin{Code}[width=9cm]
2698 $\begin{pNiceMatrix}[r,margin]
2699 \CodeBefore
2700 \emph{\chessboardcolors{red!15}{blue!15}}
2701 \Body
2702 1 & -1 & 1 \\
2703 -1 & 1 & -1 \\
2704 1 & -1 & 1
2705 \end{pNiceMatrix}$
2706 \end{Code}
2707 $\begin{pNiceMatrix}[r,baseline=1, margin,no-cell-nodes]
2708 \CodeBefore
2709 \chessboardcolors{red!15}{blue!15}
2710 \Body
2711 1 & -1 & 1 \\
2712 -1 & 1 & -1 \\
2713 1 & -1 & 1
2714 \end{pNiceMatrix}$
2715 \end{scope}
2716
2717 \medskip
2718 We have used the key |r| which aligns all the columns rightwards (cf.~\ref{columns-width},
2719 p.~\pageref{columns-width}).
2720
2721
2722 \bigskip
2723 \item The command \Definition{\textbackslash rowcolor} takes its name from the
2724 command |\rowcolor| of \pkg{colortbl}. Its first mandatory argument is the
2725 color and the second is a comma-separated list of rows or interval of rows
2726 with the form $a$-$b$ (an interval of the form $a$- represent all the rows
2727 from the row $a$ until the end).
2728
2729 \medskip
2730 \begin{scope}
2731 \hfuzz = 10cm
2732 \begin{Code}[width=9cm]
2733 $\begin{NiceArray}{lll}[hvlines]
2734 \CodeBefore
2735 \emph{\rowcolor{red!15}{1,3-5,8-}}
2736 \Body
2737 a_1 & b_1 & c_1 \\
2738 a_2 & b_2 & c_2 \\
2739 a_3 & b_3 & c_3 \\
2740 a_4 & b_4 & c_4 \\
2741 a_5 & b_5 & c_5 \\
2742 a_6 & b_6 & c_6 \\
2743 a_7 & b_7 & c_7 \\
2744 a_8 & b_8 & c_8 \\
2745 a_9 & b_9 & c_9 \\
2746 a_{10} & b_{10} & c_{10} \\
2747 \end{NiceArray}$
2748 \end{Code}
2749 $\begin{NiceArray}{lll}[baseline=4,hvlines,no-cell-nodes]
2750 \CodeBefore
2751 \rowcolor{red!15}{1,3-5,8-}
2752 \Body
2753 a_1 & b_1 & c_1 \\
2754 a_2 & b_2 & c_2 \\
2755 a_3 & b_3 & c_3 \\
2756 a_4 & b_4 & c_4 \\
2757 a_5 & b_5 & c_5 \\
2758 a_6 & b_6 & c_6 \\
2759 a_7 & b_7 & c_7 \\
2760 a_8 & b_8 & c_8 \\
2761 a_9 & b_9 & c_9 \\
2762 a_{10} & b_{10} & c_{10} \\
2763 \end{NiceArray}$
2764 \end{scope}
2765
2766
2767 \bigskip
2768 \item The command \Definition{\textbackslash columncolor} takes its name from
2769 the command |\columncolor| of \pkg{colortbl}. Its syntax is similar to the
2770 syntax of |\rowcolor|.
2771
2772 \bigskip
2773 \item The command \Definition{\textbackslash rowcolors} (with a \emph{s})
2774 takes its name from the command |\rowcolors| of \pkg{colortbl}. The \emph{s}
2775 emphasizes the fact that there is \emph{two} colors. This command colors
2776 alternately the rows of the tabular with the two colors (provided in second
2777 and third argument), beginning with the row whose number is given in first
2778 (mandatory) argument. One of the arguments of color may be empty (no color is
2779 applied in the corresponding rows).
2780
2781 In fact, the first (mandatory) argument is, more generally, a comma separated
2782 list of intervals describing the rows involved in the action of |\rowcolors|
2783 (an interval of the form $i$|-| describes in fact the interval of all the rows
2784 of the tabular, beginning with the row~$i$).
2785
2786
2787 \bigskip
2788 The last argument of |\rowcolors| is an optional list of pairs
2789 \textsl{key=value} (the optional argument in the first position corresponds to
2790 the colorimetric space). The available keys are |cols|, |restart| and
2791 |respect-blocks|.
2792
2793 \index{cols (key of \texttt{\textbackslash rowcolors} of \texttt{\textbackslash CodeBefore})}
2794 \index{restart (key of \texttt{\textbackslash rowcolors} of \texttt{\textbackslash CodeBefore})}
2795 \index{respect-blocks (key of \texttt{\textbackslash rowcolors} du\newline \texttt{\textbackslash CodeBefore})}
2796
2797 \begin{itemize}
2798 \item The key \Definition{cols} describes a set of columns. The command
2799 |\rowcolors| will color only the cells of these columns. The value is a
2800 comma-separated list of intervals of the form $i$-$j$ (where $i$ or $j$ may be
2801 replaced by |*|).
2802 \item With the key \Definition{restart}, each interval of rows (specified by the
2803 first mandatory argument) begins with the same color.\footnote{Otherwise, the color
2804 of a given row relies only upon the parity of its absolute number.}
2805 \item With the key \Definition{respect-blocks} the ``rows'' alternately colored
2806 may extend over several rows if they have to incorporate blocks (created with
2807 the command |\Block|: cf.~\ref{Block}, p.~\pageref{Block}).
2808 \end{itemize}
2809
2810 \medskip
2811 \begin{scope}
2812 \hfuzz=10cm
2813 \begin{Code}[width=10cm]
2814 \begin{NiceTabular}{clr}[hvlines]
2815 \CodeBefore
2816 \emph{\rowcolors[gray]{2}{0.8}{}[cols=2-3,restart]}
2817 \Body
2818 \Block{1-*}{Results} \\
2819 John & 12 \\
2820 Stephen & 8 \\
2821 Sarah & 18 \\
2822 Ashley & 20 \\
2823 Henry & 14 \\
2824 Madison & 15
2825 \end{NiceTabular}
2826 \end{Code}
2827 \begin{NiceTabular}{clr}[hvlines,baseline=2,no-cell-nodes]
2828 \CodeBefore
2829 \rowcolors[gray]{2}{0.8}{}[cols=2-3,restart]
2830 \Body
2831 \Block{1-*}{Results} \\
2832 \Block{2-1}{A}& John & 12 \\
2833 & Stephen & 8 \\
2834 \Block{4-1}{B}& Sarah & 18 \\
2835 & Ashley & 20 \\
2836 & Henry & 14 \\
2837 & Madison & 15
2838 \end{NiceTabular}
2839 \end{scope}
2840
2841
2842
2843
2844
2845 \bigskip
2846 \item The extension \pkg{nicematrix} provides also a command
2847 \Definition{\textbackslash rowlistcolors}. This command generalises the
2848 command |\rowcolors|: instead of two successive arguments for the colors, this
2849 command takes in an argument which is a (comma-separated) list of colors. In
2850 that list, the symbol |=| represents a color identical to the previous one.
2851
2852 \smallskip
2853 \begin{Code}[width=10cm]
2854 \begin{NiceTabular}{c}[rounded-corners]
2855 \CodeBefore
2856 \emph{\rowlistcolors{1}{red!15,blue!15,green!15}}
2857 \Body
2858 Peter \\
2859 James \\
2860 Abigail \\
2861 Elisabeth \\
2862 Claudius \\
2863 Jane \\
2864 Alexandra \\
2865 \end{NiceTabular}
2866 \end{Code}
2867 \begin{NiceTabular}{c}[rounded-corners,no-cell-nodes]
2868 \CodeBefore
2869 \rowlistcolors{1}{red!15,blue!15,green!15}
2870 \Body
2871 Peter \\
2872 James \\
2873 Abigail \\
2874 Elisabeth \\
2875 Claudius \\
2876 Jane \\
2877 Alexandra \\
2878 \end{NiceTabular}
2879
2880 \bigskip
2881 It's also possible to use in the command |\rowlistcolors| a color series
2882 defined by the command |\definecolorseries| of \pkg{xcolor} (and initialized
2883 with the command |\resetcolorseries|\footnote{For the initialization, in the
2884 following example, you have used the LaTeX counter |iRow| (which corresponds to the
2885 internal TeX counter |\c@iRow|) which, when used in the
2886 |\CodeBefore| (and in the |\CodeAfter|) corresponds to the number of rows of
2887 the array: cf.~\ref{iRow},~p.~\pageref{iRow}. That leads to an adjustment of the gradation
2888 of the colors to the size of the tabular.}).
2889
2890 \index{definecolorseries@\texttt{\textbackslash definecolorseries} (command of \pkg{xcolor})}
2891 \index{resetcolorseries@\texttt{\textbackslash resetcolorseries} (command of \pkg{xcolor})}
2892
2893 \smallskip
2894 \begin{Code}[width=12.5cm]
2895 \begin{NiceTabular}{c}
2896 \CodeBefore
2897 \emph{\definecolorseries{BlueWhite}{rgb}{last}{blue}{white}
2898 \resetcolorseries[\value{iRow}]{BlueWhite}
2899 \rowlistcolors{1}{BlueWhite!!+}}
2900 \Body
2901 Peter \\
2902 James \\
2903 Abigail \\
2904 Elisabeth \\
2905 Claudius \\
2906 Jane \\
2907 Alexandra \\
2908 \end{NiceTabular}
2909 \end{Code}
2910 \hspace{-1cm}
2911 \begin{NiceTabular}{c}[no-cell-nodes]
2912 \CodeBefore
2913 \definecolorseries{BlueWhite}{rgb}{last}{blue}{white}
2914 \resetcolorseries[\value{iRow}]{BlueWhite}
2915 \rowlistcolors{1}{BlueWhite!!+}
2916 \Body
2917 Peter \\
2918 James \\
2919 Abigail \\
2920 Elisabeth \\
2921 Claudius \\
2922 Jane \\
2923 Alexandra \\
2924 \end{NiceTabular}
2925 \end{itemize}
2926
2927 \vspace{1cm}
2928 We recall that all the color commands that we have described don't color the cells
2929 which are in the ``corners''. In the following example, we use the key
2930 |corners| to require the determination of the corner \emph{north east} (NE).
2931
2932 \medskip
2933 \index{corners (key of an environment)|textit}
2934 \begin{Code}[width=15cm]
2935 \begin{NiceTabular}{ccccccc}[\emph{corners=NE},margin,hvlines,first-row,first-col]
2936 \CodeBefore
2937 \emph{\rowlistcolors{1}{blue!15, }}
2938 \Body
2939 & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\
2940 0 & 1 \\
2941 1 & 1 & 1 \\
2942 2 & 1 & 2 & 1 \\
2943 3 & 1 & 3 & 3 & 1 \\
2944 4 & 1 & 4 & 6 & 4 & 1 \\
2945 5 & 1 & 5 & 10 & 10 & 5 & 1 \\
2946 6 & 1 & 6 & 15 & 20 & 15 & 6 & 1 \\
2947 \end{NiceTabular}
2948 \end{Code}
2949 \hspace{-6cm}
2950 \begin{NiceTabular}{ccccccc}%
2951 [corners=NE,margin,hvlines,first-row,first-col]
2952 \CodeBefore
2953 \rowlistcolors{1}{blue!15, }
2954 \Body
2955 & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\
2956 0 & 1 \\
2957 1 & 1 & 1 \\
2958 2 & 1 & 2 & 1 \\
2959 3 & 1 & 3 & 3 & 1 \\
2960 4 & 1 & 4 & 6 & 4 & 1 \\
2961 5 & 1 & 5 & 10 & 10 & 5 & 1 \\
2962 6 & 1 & 6 & 15 & 20 & 15 & 6 & 1 \\
2963 \end{NiceTabular}
2964
2965 \medskip
2966 The previous example uses the keys |first-row| and |first-col| which are
2967 described in the chapter concerning the ``exterior'' rows and columns
2968 (cf.~\ref{exterior}, p.~\pageref{exterior}).
2969
2970 As one can see, \emph{by default}, the coloring commands that we have described
2971 don't apply in those exterior rows and columns.
2972
2973 However, it may still be possible to color in those rows and columns by
2974 providing explicitly the numbers of those rows and columns.
2975
2976 In the following example, we require a color in the column~$0$ (which is the
2977 ``first column'' and which exists because the key |first-col| has been used).
2978
2979 \medskip
2980 \begin{Code}[width=15cm]
2981 \begin{NiceTabular}{ccccccc}[\emph{corners=NE},margin,hvlines,first-row,first-col]
2982 \CodeBefore
2983 \rowlistcolors{1}{blue!15, }
2984 \emph{\columncolor{red!15}{0}}
2985 \Body
2986 & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\
2987 0 & 1 \\
2988 1 & 1 & 1 \\
2989 2 & 1 & 2 & 1 \\
2990 3 & 1 & 3 & 3 & 1 \\
2991 4 & 1 & 4 & 6 & 4 & 1 \\
2992 5 & 1 & 5 & 10 & 10 & 5 & 1 \\
2993 6 & 1 & 6 & 15 & 20 & 15 & 6 & 1 \\
2994 \end{NiceTabular}
2995 \end{Code}
2996 \hspace{-6cm}
2997 \begin{NiceTabular}{ccccccc}%
2998 [corners=NE,margin,hvlines,first-row,first-col]
2999 \CodeBefore
3000 \rowlistcolors{1}{blue!15, }
3001 \columncolor{red!15}{0}
3002 \Body
3003 & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\
3004 0 & 1 \\
3005 1 & 1 & 1 \\
3006 2 & 1 & 2 & 1 \\
3007 3 & 1 & 3 & 3 & 1 \\
3008 4 & 1 & 4 & 6 & 4 & 1 \\
3009 5 & 1 & 5 & 10 & 10 & 5 & 1 \\
3010 6 & 1 & 6 & 15 & 20 & 15 & 6 & 1 \\
3011 \end{NiceTabular}
3012
3013
3014
3015 \bigskip
3016 One should remark that all the previous commands are compatible with the
3017 commands of \pkg{booktabs} (|\toprule|, |\midrule|, |\bottomrule|, etc).
3018 However, \pkg{booktabs} is \emph{not} loaded by \pkg{nicematrix}.
3019
3020 \medskip
3021 \index{rotate@\texttt{\textbackslash rotate}|textit}
3022 \begin{scope}
3023 \hfuzz=10cm
3024 \begin{Code}[width=8.5cm]
3025 \begin{NiceTabular}[c]{lSSSS}[no-cell-nodes] \myrlap{% no-cell-nodes is optional}
3026 \CodeBefore
3027 \rowcolor{red!15}{1-2}
3028 \rowcolors{3}{blue!15}{}
3029 \Body
3030 \emph{\toprule}
3031 \Block[C]{2-1}{Product} &
3032 \Block{1-3}{dimensions (cm)} & & &
3033 \Block{2-1}{\rotate Price} \\
3034 \emph{\cmidrule(rl){2-4}}
3035 & L & l & h \\
3036 \emph{\midrule}
3037 small & 3 & 5.5 & 1 & 30 \\
3038 standard & 5.5 & 8 & 1.5 & 50.5 \\
3039 premium & 8.5 & 10.5 & 2 & 80 \\
3040 extra & 8.5 & 10 & 1.5 & 85.5 \\
3041 special & 12 & 12 & 0.5 & 70 \\
3042 \emph{\bottomrule}
3043 \end{NiceTabular}
3044 \end{Code}
3045 \begin{NiceTabular}[c]{lSSSS}[no-cell-nodes]
3046 \CodeBefore
3047 \rowcolor{red!15}{1-2}
3048 \rowcolors{3}{blue!15}{}
3049 \Body
3050 \toprule
3051 \Block[C]{2-1}{Product} &
3052 \Block{1-3}{dimensions (cm)} & & &
3053 \Block{2-1}{\rotate Price} \\
3054 \cmidrule(rl){2-4}
3055 & L & l & h \\
3056 \midrule
3057 small & 3 & 5.5 & 1 & 30 \\
3058 standard & 5.5 & 8 & 1.5 & 50.5 \\
3059 premium & 8.5 & 10.5 & 2 & 80 \\
3060 extra & 8.5 & 10 & 1.5 & 85.5 \\
3061 special & 12 & 12 & 0.5 & 70 \\
3062 \bottomrule
3063 \end{NiceTabular}
3064 \end{scope}
3065
3066 \index{S (the columns S of \pkg{siunitx})|textit}
3067 \medskip
3068 We have used the type of column |S| of \pkg{siunitx} (which should be loaded by
3069 the user).
3070
3071
3072 \bigskip
3073 \label{EmptyRow}
3074 \index{EmptyRow@\texttt{\textbackslash EmptyRow} (command of \texttt{\textbackslash CodeBefore})}
3075 \index{EmptyColumn@\texttt{\textbackslash EmptyColumn} (command of \texttt{\textbackslash CodeBefore})}
3076
3077 It's also possible, in the |\CodeBefore|, to use the commands
3078 \DefinitionCommand{EmptyColumn} and \DefinitionCommand{EmptyRow}. The command
3079 |\EmptyColumn| takes in as argument a (comma-separated) list of numbers of
3080 columns and requires that no rule nor background colors will be drawn in the
3081 corresponding columns. The command |\EmptyRow| is similar for the rows.
3082
3083 \medskip
3084 \begin{Code}[width=10cm]
3085 \begin{NiceTabular}{ccccc}[hvlines,no-cell-nodes] \myrlap{% no-cell-nodes is optional}
3086 \CodeBefore
3087 \rowcolor{blue!15}{1}
3088 \emph{\EmptyColumn{3}}
3089 \Body
3090 one & two && three & four \\
3091 one & \Block{}{two\\ rows} && three & four \\
3092 \end{NiceTabular}
3093 \end{Code}
3094 \begin{NiceTabular}{ccccc}[hvlines,no-cell-nodes]
3095 \CodeBefore
3096 \rowcolor{blue!15}{1}
3097 \EmptyColumn{3}
3098 \Body
3099 one & two && three & four \\
3100 one & \Block{}{two\\ rows} && three & four \\
3101 \end{NiceTabular}
3102
3103
3104
3105
3106 \subsection{Color tools to be used inside the tabular}
3107
3108 \index{cellcolor@\texttt{\textbackslash cellcolor}!command in tabular}
3109 \index{rowcolor@\texttt{\textbackslash rowcolor}!command in tabular}
3110 \index{columncolor@\texttt{\textbackslash columncolor}!command in the preamble
3111 of an environment}
3112
3113 The extension \pkg{nicematrix} also provides commands to be used directly in the
3114 tabular (as does \pkg{colortbl}).
3115
3116 These available commands are the following ones (the first three ones are
3117 inspired by the similar commands of \pkg{colortbl}).
3118 \begin{itemize}
3119 \item \DefinitionCommand{cellcolor} which colorizes a cell;\footnote{That
3120 command |\cellcolor| will delete the following spaces (which does not the
3121 command |\cellcolor| of \pkg{colortbl}). Moreover, if one wishes to define a
3122 command above that command |\cellcolor|, it must be protected in the TeX sens
3123 (whereas, if it were the command |\cellcolor| of \pkg{colortbl}, one should,
3124 on the contrary, write a \emph{fully expandable} command).}
3125 \item \DefinitionCommand{rowcolor} which must be used in a cell and which
3126 colorizes the end of the row;\footnote{If you want a command to color the
3127 following $n$~rows, consider the command |\RowStyle| and its key |fillcolor|:
3128 cf.~\ref{RowStyle}, p.~\pageref{RowStyle}}
3129 \item \DefinitionCommand{columncolor} which must be used in the preamble of the
3130 environment with the same syntax as the corresponding command of \pkg{colortbl}
3131 (however, unlike the command |\columncolor| of \pkg{colortbl}, this command
3132 |\columncolor| can appear within another command, itself used in the preamble of
3133 the array; on the other hand, the two final optional arguments for fixing offset
3134 are not supported);
3135 \item \DefinitionCommand{rowcolors} which takes in as arguments two colors and
3136 color the rest of the tabular with those colors (must be used after a potential
3137 |\hline|, |\Hline| or |\toprule|!) ;
3138 \item \DefinitionCommand{rowlistcolors} which takes in as argument a color and
3139 color the rest of the tabular with the colors of that list of
3140 colors.\footnote{When the command |\rowlistcolors| (or the command |\rowcolors|)
3141 is used in a cell of the column~$j$ of the array, the command applies only on
3142 the columns above~$j$ (by design).}
3143 \end{itemize}
3144 These commands are compatible with the commands for the overlays of Beamer
3145 (|\only|, etc.)
3146
3147 \smallskip
3148 \begin{Code}
3149 \NewDocumentCommand { \Blue } { } { \emph{\columncolor{blue!15}} }
3150 \begin{NiceTabular}{>{\Blue}c>{\Blue}cc}
3151 \toprule
3152 \emph{\rowcolor{red!15}}
3153 Last name & First name & Birth day \\
3154 \midrule
3155 Achard & Jacques & 5 juin 1962 \\
3156 Lefebvre & Mathilde & 23 mai 1988 \\
3157 Vanesse & Stephany & 30 octobre 1994 \\
3158 Dupont & Chantal & 15 janvier 1998 \\
3159 \bottomrule
3160 \end{NiceTabular}
3161 \end{Code}
3162
3163
3164 \begin{center}
3165 \NewDocumentCommand { \Blue } { } { \columncolor{blue!15} }
3166 \begin{NiceTabular}{>{\Blue}c>{\Blue}cc}[no-cell-nodes]
3167 \toprule
3168 \rowcolor{red!15}
3169 Last name & First name & Birth day \\
3170 \midrule
3171 Achard & Jacques & 5 juin 1962 \\
3172 Lefebvre & Mathilde & 23 mai 1988 \\
3173 Vanesse & Stephany & 30 octobre 1994 \\
3174 Dupont & Chantal & 15 janvier 1998 \\
3175 \bottomrule
3176 \end{NiceTabular}
3177 \end{center}
3178
3179 \bigskip
3180 Each use of the |\rowlistcolors| (or |\rowcolors|, which is, in fact, a
3181 special case of |\rowlistcolors|) stops the potential coloring
3182 schemes\footnote{We say \emph{schemes} in plural form because it's possible to
3183 start simultaneously several coloring schemes if they apply on different
3184 columns.} specified by a previous command |\rowlistcolors|. In particular,
3185 it's possible to start coloring the rows with |\rowlistcolors{...}| and stop
3186 coloring by a command |\rowlistcolors| with an empty argument.
3187
3188 \bigskip
3189 \begin{Code}[width=10cm]
3190 \begin{NiceTabular}{c}[hvlines]
3191 one \\
3192 two \\
3193 \emph{\rowlistcolors{red!15}}
3194 three \\
3195 four \\
3196 five \\
3197 \emph{\rowlistcolors{}}
3198 six \\
3199 seven \\
3200 \end{NiceTabular}
3201 \end{Code}
3202 \begin{NiceTabular}{c}[hvlines]
3203 one \\
3204 two \\
3205 \rowlistcolors{red!15}
3206 three \\
3207 four \\
3208 five \\
3209 \rowlistcolors{}
3210 six \\
3211 seven \\
3212 \end{NiceTabular}
3213
3214
3215
3216 \bigskip
3217 Here is an example of use of |\rowcolors| in conjunction with |create-blocks-in-col|.
3218
3219
3220 \begin{scope}
3221 \hfuzz=10cm
3222 \begin{Code}[width=11cm]
3223 \begin{NiceTabular}{lr}[hvlines,create-blocks-in-col=1]
3224 \emph{\rowcolors{blue!10}{}[respect-blocks]}
3225 John & 12 \\
3226 & 13 \\
3227 Steph & 8 \\
3228 Sarach & 18 \\
3229 & 17 \\
3230 & 15 \\
3231 Ashley & 20 \\
3232 Henry & 14 \\
3233 Madison & 15 \\
3234 & 19
3235 \end{NiceTabular}
3236 \end{Code}
3237 \begin{NiceTabular}{lr}[hvlines,baseline=c,create-blocks-in-col=1]
3238 \rowcolors{blue!10}{}[respect-blocks]
3239 John & 12 \\
3240 & 13 \\
3241 Steph & 8 \\
3242 Sarah & 18 \\
3243 & 17 \\
3244 & 15 \\
3245 Ashley & 20 \\
3246 Henry & 14 \\
3247 Madison & 15 \\
3248 & 19
3249 \end{NiceTabular}
3250 \end{scope}
3251
3252
3253 \subsection{The special color ``nocolor''}
3254
3255 \index{nocolor}
3256
3257 The extension \pkg{nicematrix} provides the special color \Definition{nocolor}
3258 which may be used in all the coloring commands provided by \pkg{nicematrix} (in
3259 the |\CodeBefore| or in the array itself).
3260
3261 The cells marked by this color won't be colored, whatever the other instructions
3262 of coloring which may apply to these cells.
3263
3264 Therefore, the color |nocolor| is an easy way to add an exception to a more
3265 general coloring command.
3266
3267 \section{The command \texttt{\textbackslash RowStyle}}
3268
3269 \label{RowStyle}
3270 \indexcommand{RowStyle}
3271 \index{cell-space-top-limit}
3272 \index{cell-space-bottom-limit}
3273 \index{cell-space-limits}
3274
3275 The command \DefinitionCommand{RowStyle} takes in as argument some formatting
3276 instructions that will be applied to each cell on the rest of the current row.
3277
3278 \medskip
3279 That command also takes in as optional argument (between square brackets)
3280 a list of \textsl{key=value} pairs.
3281 \begin{itemize}
3282 \item \index{nb-rows (key of \texttt{\textbackslash RowStyle})}
3283 The key \Definition{nb-rows} sets the number of rows to which the specifications of
3284 the current command will apply (with the special value |*|, it will apply to all
3285 the following rows).
3286 \item The keys \Definition{cell-space-top-limit}$^+$, \Definition{cell-space-bottom-limit}$^+$
3287 and \Definition{cell-space-limits}$^+$ are available with the same meaning that the
3288 corresponding global keys (cf.~\ref{cell-space}, p.~\pageref{cell-space}).
3289 \item \index{rowcolor (key of \texttt{\textbackslash RowStyle})}
3290 \index{fill!key of \texttt{\textbackslash RowStyle}}
3291 \index{opacity!key of \texttt{\textbackslash RowStyle}}
3292 \index{rounded-corners!key of \texttt{\textbackslash RowStyle}}
3293 The key \Definition{fill} (alias: \Definition{rowcolor}) sets the color of the
3294 background and \Definition{opacity}\footnote{Caution: that feature creates instructions of
3295 transparency in the \textsc{pdf} and some readers of \textsc{pdf} don't
3296 support such instructions. The opacity is applied by using |\pgfsetfillopacity|.}
3297 sets its opacity.
3298
3299 \medskip
3300 These commands have a normal syntax but also an ``additive'' syntax. That means that it's
3301 possible to write, for example, |cell-space-limits = 2pt| but also |cell-space-limits += 1pt|.
3302
3303
3304 \item If the key \Definition{rounded-corners} is used, that background will have
3305 rounded corners.
3306
3307 \item
3308 \index{color!key of \texttt{\textbackslash RowStyle}}
3309 The key \Definition{color} sets the color of the text.\footnote{The key
3310 |color| uses the command |\color| but also inserts an instruction
3311 |\leavevmode| before. This instruction prevents an extra vertical space in the
3312 cells which belong to columns of type |p|, |b|, |m| and |X| (which start in
3313 vertical mode of LaTeX). For the columns |V| (of \pkg{varwidth}), that's not
3314 enough, except when LuaLaTeX is used with the package \pkg{luacolor} (see
3315 question 460489 on TeX StackExchange).}
3316 \item \index{bold (key of \texttt{\textbackslash RowStyle})} The key
3317 \Definition{bold} enforces bold characters for the cells of the row, both in
3318 math and text mode.
3319 \end{itemize}
3320
3321 \medskip
3322 \begin{Code}[width=12cm]
3323 \begin{NiceTabular}{cccc}
3324 \hline
3325 \emph{\RowStyle[cell-space-limits=3pt]{\rotate}}
3326 first & second & third & fourth \\
3327 \emph{\RowStyle[nb-rows=2,fill=blue!50,color=white]{\sffamily}}
3328 1 & 2 & 3 & 4 \\
3329 I & II & III & IV
3330 \end{NiceTabular}
3331 \end{Code}
3332 \index{rotate@\texttt{\textbackslash rotate}|textit}
3333 \begin{NiceTabular}{cccc}[no-cell-nodes]
3334 \hline
3335 \RowStyle[cell-space-limits=3pt]{\rotate}
3336 first & second & third & fourth \\
3337 \RowStyle[nb-rows=2,fill=blue!50,color=white]{\sffamily}
3338 1 & 2 & 3 & 4 \\
3339 I & II & III & IV \\
3340 \end{NiceTabular}
3341
3342 \medskip
3343 The command |\rotate| is described in the section~\ref{rotate}, p.~\pageref{rotate}.
3344
3345 \section{The width of the columns}
3346
3347 \label{width}
3348 \index{width@\textbf{Width of the columns}|(}
3349
3350 \subsection{Basic tools}
3351
3352 In the environments with an explicit preamble (like |{NiceTabular}|,
3353 |{NiceArray}|, etc.), it's possible to fix the width of a given column with
3354 the standard letters |w|, |W|, |p|, |b| and |m| of the package \pkg{array}
3355 (which is loaded by \pkg{nicematrix}).
3356
3357 \medskip
3358 \begin{Code}[width=9cm]
3359 \begin{NiceTabular}{\emph{W{c}{2cm}}cc}[hvlines]
3360 Paris & New York & Madrid \\
3361 Berlin & London & Roma \\
3362 Rio & Tokyo & Oslo
3363 \end{NiceTabular}
3364 \end{Code}
3365 \begin{NiceTabular}{W{c}{2cm}cc}[hvlines,no-cell-nodes]
3366 Paris & New York & Madrid \\
3367 Berlin & London & Roma \\
3368 Rio & Tokyo & Oslo
3369 \end{NiceTabular}
3370
3371
3372 \bigskip
3373 \index{columns-width} In the environments of \pkg{nicematrix}, it's also
3374 possible to fix the \emph{minimal} width of all the columns (except the
3375 potential exterior columns: cf.~\ref{exterior}, p.~\pageref{exterior}) directly
3376 with the key \Definition{columns-width}.
3377
3378 \medskip
3379 \begin{Code}[width=10cm]
3380 $\begin{pNiceMatrix}[\emph{columns-width = 1cm}]
3381 1 & 12 & -123 \\
3382 12 & 0 & 0 \\
3383 4 & 1 & 2
3384 \end{pNiceMatrix}$
3385 \end{Code}
3386 $\begin{pNiceMatrix}[columns-width = 1cm,no-cell-nodes]
3387 1 & 12 & -123 \\
3388 12 & 0 & 0 \\
3389 4 & 1 & 2
3390 \end{pNiceMatrix}$
3391
3392 \medskip
3393 Note that the space inserted between two columns (equal to 2 |\tabcolsep| in
3394 |{NiceTabular}| and to 2 |\arraycolsep| in the other environments)
3395 is not suppressed (of course, it's possible to suppress this space by setting
3396 |\tabcolsep| or |\arraycolsep| equal to $0$~pt before the environment).
3397
3398 \bigskip
3399 It's possible to give the special value \Definition{auto} to the option
3400 |columns-width|: all the columns of the array will have a width equal to the
3401 widest cell of the array.\footnote{The result is achieved with only one
3402 compilation (but PGF/TikZ will have written information in the |aux| file and
3403 a message requiring a second compilation will appear).}
3404
3405 \nobreak
3406 \medskip
3407 \begin{Code}[width=10cm]
3408 $\begin{pNiceMatrix}[\emph{columns-width = auto}]
3409 1 & 12 & -123 \\
3410 12 & 0 & 0 \\
3411 4 & 1 & 2
3412 \end{pNiceMatrix}$
3413 \end{Code}
3414 $\begin{pNiceMatrix}[columns-width = auto,no-cell-nodes]
3415 1 & 12 & -123 \\
3416 12 & 0 & 0 \\
3417 4 & 1 & 2
3418 \end{pNiceMatrix}$
3419
3420 \bigskip
3421 Without surprise, it's possible to fix the minimal width of the columns of all
3422 the arrays of a current scope with the command
3423 |\NiceMatrixOptions|.
3424
3425 \nobreak
3426 \medskip
3427 \begin{Code}[width=8.5cm]
3428 \emph{\NiceMatrixOptions{columns-width=10mm}}
3429 $\begin{pNiceMatrix}
3430 a & b \\ c & d
3431 \end{pNiceMatrix}
3432 =
3433 \begin{pNiceMatrix}
3434 1 & 1245 \\ 345 & 2
3435 \end{pNiceMatrix}$
3436 \end{Code}
3437 \begin{scope}
3438 \NiceMatrixOptions{columns-width=10mm}
3439 $\begin{pNiceMatrix}
3440 a & b \\
3441 c & d
3442 \end{pNiceMatrix}
3443 =
3444 \begin{pNiceMatrix}
3445 1 & 1245 \\
3446 345 & 2
3447 \end{pNiceMatrix}$
3448 \end{scope}
3449
3450
3451 \bigskip
3452 \index{NiceMatrixBlock@\texttt{\{NiceMatrixBlock\}}}
3453 \index{auto-columns-width!(key of \texttt{\{NiceMatrixBlock\}})}
3454 It's also possible to fix a zone where all the matrices will have their
3455 columns of the same width, equal to the widest cell of all the matrices. This
3456 construction uses the environment |{NiceMatrixBlock}| with the option
3457 |auto-columns-width|\footnote{At this time, this is the only usage of the
3458 environment |{NiceMatrixBlock}| but it may have other usages in the future.}.
3459 The environment |{NiceMatrixBlock}| has no direct link with the command
3460 |\Block| presented previously in this document (cf.~\ref{Block}, p.~\pageref{Block}).
3461
3462 \medskip
3463 \begin{Code}[width=8.5cm]
3464 \emph{\begin{NiceMatrixBlock}[auto-columns-width]}
3465 $\begin{array}{c}
3466 \begin{bNiceMatrix}
3467 9 & 17 \\ -2 & 5
3468 \end{bNiceMatrix} \\ \\
3469 \begin{bNiceMatrix}
3470 1 & 1245345 \\ 345 & 2
3471 \end{bNiceMatrix} \\
3472 \end{array}$
3473 \emph{\end{NiceMatrixBlock}}
3474 \end{Code}
3475 \begin{NiceMatrixBlock}[auto-columns-width]
3476 $\begin{array}{c}
3477 \begin{bNiceMatrix}
3478 9 & 17 \\ -2 & 5
3479 \end{bNiceMatrix} \\ \\
3480 \begin{bNiceMatrix}
3481 1 & 1245345 \\ 345 & 2
3482 \end{bNiceMatrix} \\
3483 \end{array}$
3484 \end{NiceMatrixBlock}
3485
3486 \subsection{The columns V of \texorpdfstring{\pkg{varwidth}}{varwidth}}
3487
3488 \label{varwidth}
3489 \index{varwidth@\pkg{varwidth} (package)}
3490 \index{V (the columns V of \pkg{varwidth})}
3491
3492
3493 Let's recall first the behaviour of the environment |{varwidth}| of the
3494 eponymous package \pkg{varwidth}. That environment is similar to the classical
3495 environment |{minipage}| but the width provided in the argument is only the
3496 \emph{maximal} width of the created box. In the general case, the width of the
3497 box constructed by an environment |{varwidth}| is the natural width of its
3498 contents.
3499
3500 \medskip
3501 That point is illustrated on the following examples.
3502
3503 \medskip
3504 \begin{Code}[width=6cm]
3505 \fbox{%
3506 \begin{\emph{varwidth}}{8cm}
3507 \begin{itemize}
3508 \item first item
3509 \item second item
3510 \end{itemize}
3511 \end{\emph{varwidth}}}
3512 \end{Code}
3513 \fbox{\begin{varwidth}{8cm}
3514 \begin{itemize}
3515 \item first item
3516 \item second item
3517 \end{itemize}
3518 \end{varwidth}}
3519
3520 \bigskip
3521 \begin{Code}[width=6cm]
3522 \fbox{%
3523 \begin{\emph{minipage}}{8cm}
3524 \begin{itemize}
3525 \item first item
3526 \item second item
3527 \end{itemize}
3528 \end{\emph{minipage}}}
3529 \end{Code}
3530 \fbox{\begin{minipage}{8cm}
3531 \begin{itemize}
3532 \item first item
3533 \item second item
3534 \end{itemize}
3535 \end{minipage}}
3536
3537
3538 \bigskip
3539 The package \pkg{varwidth} provides also the column type |V|. A column of type
3540 |V{|$\langle$\textsl{dim}$\rangle$|}| encapsulates all its cells in a
3541 |{varwidth}| with the argument $\langle$\textsl{dim}$\rangle$ (and does also some tuning).
3542
3543 \smallskip
3544 When the package \pkg{varwidth} is loaded, the columns |V| of \pkg{varwidth}
3545 are supported by \pkg{nicematrix}.
3546
3547 \medskip
3548 \begin{Code}
3549 \begin{NiceTabular}[corners=NW,hvlines]{\emph{V{3cm}V{3cm}V{3cm}}}
3550 & some text & some very very very long text \\
3551 some very very very long text \\
3552 some very very very long text
3553 \end{NiceTabular}
3554 \end{Code}
3555
3556 \medskip
3557 \begin{center}
3558 \begin{NiceTabular}[corners=NW,hvlines]{V{3cm}V{3cm}V{3cm}}
3559 & some text & some very very very long text \\
3560 some very very very long text \\
3561 some very very very long text
3562 \end{NiceTabular}
3563 \end{center}
3564
3565 \bigskip
3566 Concerning \pkg{nicematrix}, one of the benefits of this type of columns is
3567 that, for a cell of a column of type~|V|, the PGF/TikZ node created by
3568 \pkg{nicematrix} for the content of that cell has a width adjusted to the
3569 content of the cell : cf.~\ref{node-V}, p.~\pageref{node-V}.
3570
3571
3572 \bigskip
3573 The columns |V| of \pkg{nicematrix} supports the keys |t|, |p|, |m|, |b|, |l|,
3574 |c| and |r| also supported by the columns~|X|: see their description in the
3575 section~\ref{X-columns}, p.~\pageref{X-columns}.
3576
3577 \bigskip
3578 One should remark that the extension \pkg{varwidth} (at least in its version
3579 0.92) has some problems: for instance, with LuaLaTeX, it does not work when
3580 the content begins with |\color|. Moreover, \pkg{varwidth} must be loaded after
3581 the package \pkg{array} (itself loaded by \pkg{nicematrix}).
3582
3583
3584 \subsection{The columns X}
3585
3586 \label{X-columns}
3587 \index{tabularx@\pkg{tabularx} (package)}
3588 \index{NiceTabularX@\texttt{\{NiceTabularX\}}}
3589 \index{X (the columns X)}
3590 \index{width!key of \texttt{\{NiceTabular\}}}
3591
3592 The environment |{NiceTabular}| provides |X| columns similar to those provided
3593 by the environment |{tabularx}| of the eponymous package.\footnote{The
3594 environment |{tabularx}| catches its body as an argument and typesets it
3595 several times during a LaTeX run in order to compute the width of the columns.
3596 On its side, |{NiceTabular}| does not catch its body as an argument (except
3597 when the key |light-syntax| is in force) and typesets the tabular only once but writes
3598 informations on the |aux| file, and requires several compilations.}
3599
3600 The required width of the tabular may be specified with the key
3601 \Definition{width} (in |{NiceTabular}| or in |\NiceMatrixOptions|). The initial
3602 value of this parameter is the parameter |\linewidth| of LaTeX (and not
3603 |\textwidth|).
3604
3605 For sake of similarity with the environment |{tabularx}|, \pkg{nicematrix} also
3606 provides an environment \Definition{\{NiceTabularX\}} with a syntax similar to
3607 the syntax of |{tabularx}|, that is to say with a first mandatory argument which
3608 is the width of the tabular.
3609
3610 \medskip
3611 The specifier |X| takes in an optional argument (between square brackets) which
3612 is a list of keys.
3613 \begin{itemize}
3614 \item It's possible to give a weight for the column by providing a positive number
3615 directly as argument of the specifier |X|. For example, a column |X[0.5]| will
3616 have a width equal to the half of the width of a column~|X| (which has a weight
3617 equal to $1$).
3618 \item It's possible to specify an horizontal alignment with one of the
3619 letters |l|, |c| and |r| (which insert respectively |\raggedright|,
3620 |\centering| and |\raggedleft| followed by |\arraybackslash|).\footnote{In fact,
3621 when \pkg{ragged2e} is loaded, \pkg{nicematrix} uses the commands
3622 |\RaggedRight|, |\Centering| and |\RaggedLeft| of \pkg{ragged2e} instead of the
3623 commands |\raggedright|, |\centering| and |\raggedleft|. That ensures a better output.}
3624 \item It's possible to specify a vertical alignment with one of the keys
3625 |t| (alias |p|), |m| and |b| (which construct respectively columns of type
3626 |p|, |m| and |b|). The initial value is |t|.
3627
3628 \item It's possible to use the key |V| in a column of type |X|. When that key is used,
3629 the column~|X| behaves in fact like a column~|V| of the extension \pkg{varwidth}
3630 (which must have been loaded by the user). Henece, the width of the columns, as
3631 computed by the |X|~process, is in fact the \emph{maximal} width of the column.
3632 \end{itemize}
3633
3634 \begin{Code}
3635 \begin{NiceTabular}\emph{[width=9cm]{X[c,m]X[0.5,c,m]}}[hvlines]
3636 a rather long text which fits on several lines
3637 & a rather long text which fits on several lines \\
3638 a shorter text & a shorter text
3639 \end{NiceTabular}
3640 \end{Code}
3641
3642 \begin{center}
3643 \begin{NiceTabular}[width=9cm]{X[c,m]X[0.5,c,m]}[hvlines]
3644 a rather long text which fits on several lines
3645 & a rather long text which fits on several lines \\
3646 a shorter text & a shorter text
3647 \end{NiceTabular}
3648 \end{center}
3649
3650
3651
3652 \index{width@\textbf{Width of the columns}|)}
3653
3654
3655 \bigskip
3656 \section{The exterior rows and columns}
3657
3658 \index{first-row}
3659 \index{last-row}
3660 \index{first-col}
3661 \index{last-col}
3662
3663 The keys \Definition{first-row}, \Definition{last-row},
3664 \Definition{first-col} and \Definition{last-col} allow the composition of
3665 exterior rows and columns in the environments of \pkg{nicematrix}. It's
3666 particularly interesting for the (mathematical) matrices.
3667 \label{exterior}
3668
3669 A potential ``first row'' (exterior) has the number $0$ (and not $1$). Idem
3670 for the potential ``first column''.
3671
3672 \smallskip
3673 \begin{Code}
3674 $\begin{pNiceMatrix}[\emph{first-row,last-row,first-col,last-col},xdots/nullify]
3675 & C_1 & \Cdots & & C_4 & \\
3676 L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\
3677 \Vdots & a_{21} & a_{22} & a_{23} & a_{24} & \Vdots \\
3678 & a_{31} & a_{32} & a_{33} & a_{34} & \\
3679 L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\
3680 & C_1 & \Cdots & & C_4 &
3681 \end{pNiceMatrix}$
3682 \end{Code}
3683
3684 \[\begin{pNiceMatrix}[first-row,last-row,first-col,last-col,xdots/nullify]
3685 & C_1 & \Cdots & & C_4 & \\
3686 L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\
3687 \Vdots & a_{21} & a_{22} & a_{23} & a_{24} & \Vdots \\
3688 & a_{31} & a_{32} & a_{33} & a_{34} & \\
3689 L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\
3690 & C_1 & \Cdots & & C_4 &
3691 \end{pNiceMatrix}\]
3692
3693 \medskip
3694 The dotted lines of this example have been drawn with the tools presented in the
3695 section~\ref{Cdots}, p.~\pageref{Cdots}.
3696
3697 \bigskip
3698 We have several remarks to do.
3699 \begin{itemize}[beginpenalty=10000]
3700 \item For the environments with an explicit preamble (i.e. |{NiceTabular}|,
3701 |{NiceArray}| and its variants), no letter must be given in that preamble for
3702 the potential first column and the potential last column: they will
3703 automatically (and necessarily) be of type |r| for the first column and |l|
3704 for the last one.\footnote{The users wishing exterior columns with another
3705 type of alignment should consider the command |\SubMatrix| available in the
3706 |\CodeAfter| and in the |\CodeBefore| (cf.~\ref{sub-matrix}, p.~\pageref{sub-matrix}) or try to put
3707 delimiter directly in the preamble of the array (cf.~\ref{delimiters-in-preamble}, p.~\pageref{delimiters-in-preamble}).}
3708 \item One may wonder how \pkg{nicematrix} determines the number of rows and
3709 columns which are needed for the composition of the ``last row'' and ``last
3710 column''.
3711 \begin{itemize}
3712 \item For the environments with explicit preamble, like |{NiceTabular}| and
3713 |{pNiceArray}|, the number of columns can obviously be computed from the
3714 preamble.
3715
3716 \item When the option |light-syntax| (cf.~\ref{light-syntax}, p.~\pageref{light-syntax}) is used,
3717 \pkg{nicematrix} has, in any case, to load the whole body of the environment
3718 (and that's why it's not possible to put verbatim material in the array with
3719 the option |light-syntax|). The analysis of this whole body gives the number
3720 of rows and the number of columns.
3721
3722 \item In the other cases, \pkg{nicematrix} compute the number of rows and
3723 columns during the first compilation and write the result in the |aux| file
3724 for the next run.
3725
3726 \textsl{However, it's possible to provide the number of the last row and the
3727 number of the last column as values of the options |last-row| and |last-col|,
3728 tending to an acceleration of the whole compilation of the document.} That's
3729 what we will do throughout the rest of the document.
3730 \end{itemize}
3731 \end{itemize}
3732
3733 \bigskip
3734 \index{code-for-first-row}
3735 \index{code-for-first-col}
3736 \index{code-for-last-row}
3737 \index{code-for-last-col}
3738 It's possible to control the appearance of these rows and columns with options
3739 \Definition{code-for-first-row}$^+$, \Definition{code-for-last-row}$^+$,
3740 \Definition{code-for-first-col}$^+$ and \Definition{code-for-last-col}$^+$. These
3741 options specify tokens that will be inserted before each cell of the
3742 corresponding row or column.
3743
3744
3745 Those keys have a normal syntax but also an ``additive'' syntax. For example, it's
3746 possible to write |code-for-first-row = \color{blue}| but also
3747 |code-for-first-row += \color{blue}| (in the latter case, the tokens are appended on the
3748 right of the current value of the parameter).
3749
3750 \bigskip
3751 \begin{Code}
3752 \NiceMatrixOptions{\emph{code-for-first-row = \color{red},
3753 code-for-first-col = \color{blue},
3754 code-for-last-row = \color{green},
3755 code-for-last-col = \color{magenta}}}
3756 \begin{displaymath}
3757 \begin{pNiceArray}{cc|cc}[first-row,last-row=5,first-col,last-col,xdots/nullify]
3758 & C_1 & \multicolumn1c{\Cdots} & & C_4 & \\
3759 L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\
3760 \Vdots & a_{21} & a_{22} & a_{23} & a_{24} & \Vdots \\
3761 \hline
3762 & a_{31} & a_{32} & a_{33} & a_{34} & \\
3763 L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\
3764 & C_1 & \multicolumn1c{\Cdots} & & C_4 &
3765 \end{pNiceArray}
3766 \end{displaymath}
3767 \end{Code}
3768
3769 \begin{scope}
3770 \NiceMatrixOptions{code-for-first-row = \color{red},
3771 code-for-first-col = \color{blue},
3772 code-for-last-row = \color{green},
3773 code-for-last-col = \color{magenta}}
3774 \begin{displaymath}
3775 \begin{pNiceArray}{cc|cc}[first-row,last-row=5,first-col,last-col,xdots/nullify]
3776 & C_1 & \multicolumn1c{\Cdots} & & C_4 & \\
3777 L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1 \\
3778 \Vdots & a_{21} & a_{22} & a_{23} & a_{24} & \Vdots \\
3779 \hline
3780 & a_{31} & a_{32} & a_{33} & a_{34} & \\
3781 L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\
3782 & C_1 & \multicolumn1c{\Cdots} & & C_4 &
3783 \end{pNiceArray}
3784 \end{displaymath}
3785 \end{scope}
3786
3787
3788 \emph{Remarks}
3789 \begin{itemize}[beginpenalty=10000]
3790 \item As shown in the previous example, the horizontal and vertical rules
3791 don't extend in the exterior rows and columns. This remark also applies to the
3792 customized rules created by the key |custom-line|
3793 (cf.~\ref{custom-line}, p.~\pageref{custom-line}).
3794
3795 \item A specification of color present in |code-for-first-row| also applies to
3796 a dotted line drawn in that exterior ``first row'' (except if a value has
3797 been given to |xdots/color|). Idem for the other exterior rows and columns.
3798
3799 \item Logically, the potential option |columns-width| (cf.~\ref{width},
3800 p.~\pageref{width}) doesn't apply to the ``first column'' and ``last column''.
3801
3802 \item For technical reasons, it's not possible to use the option of the
3803 command |\\| after the ``first row'' or before the ``last row''. The placement
3804 of the delimiters would be wrong. If you are looking for a workaround,
3805 consider the command |\SubMatrix| in the |\CodeAfter| (and the |\CodeBefore|)
3806 described in the section~\ref{sub-matrix}, p.~\pageref{sub-matrix}.
3807 \end{itemize}
3808
3809
3810
3811
3812
3813 \section{Dotted leaders in the matrices}
3814
3815 \label{Cdots}
3816 \index{dotted@\textbf{Dotted lines}|(}
3817 \indexcommand{Ldots}
3818 \indexcommand{Cdots}
3819 \index{Ddots@\texttt{\textbackslash Ddots}|textbf}
3820 \index{Iddots@\texttt{\textbackslash Iddots}|textbf}
3821 \indexcommand{Vdots}
3822 \index{mathdots@\pkg{mathdots} (package)}
3823 \index{xdots (and its subkeys)}
3824
3825 Inside the environments of the package \pkg{nicematrix}, new commands are
3826 defined: \DefinitionCommand{Ldots}, \DefinitionCommand{Cdots},
3827 \DefinitionCommand{Vdots}, \DefinitionCommand{Ddots} and
3828 \DefinitionCommand{Iddots}. These commands are intended to be used in place of
3829 |\dots|, |\cdots|, |\vdots|, |\ddots| and |\iddots|.\footnote{The command |\iddots|, defined in \pkg{nicematrix}, is a
3830 variant of |\ddots| with dots going forward. If |mathdots| is loaded, the
3831 version of |mathdots| is used. It corresponds to the command |\adots| of
3832 \pkg{unicode-math}.}
3833 \newcounter{fniddots}
3834 \setcounter{fniddots}{\thefootnote}
3835
3836 \smallskip
3837 Each of them must be used alone in the cell of the array and it draws a dotted
3838 line as leader between the first non-empty cells\footnote{The precise definition of a
3839 ``non-empty cell'' is given below (cf.~\ref{empty-cells}, p.~\pageref{empty-cells}).} on both
3840 sides of the current cell. Of course, for |\Ldots| and |\Cdots|, it's an
3841 horizontal line; for |\Vdots|, it's a vertical line and for |\Ddots| and
3842 |\Iddots| diagonal ones. It's possible to change the color of these lines
3843 with the option |color|.\footnote{It's also possible to change the color of
3844 all these dotted lines with the option |xdots/color| (\textsl{xdots} to
3845 remind that it works for |\Cdots|, |\Ldots|, |\Vdots|, etc.):
3846 cf.~\ref{customisation}, p.~\pageref{customisation}.}
3847
3848 \nobreak
3849 \bigskip
3850 \begin{Code}[width=10cm]
3851 \begin{bNiceMatrix}
3852 a_1 & \Cdots & & & a_1 \\
3853 \Vdots & a_2 & \Cdots & & a_2 \\
3854 & \Vdots & \Ddots[color=red] \\
3855 \\
3856 a_1 & a_2 & & & a_n
3857 \end{bNiceMatrix}
3858 \end{Code}
3859 $\begin{bNiceMatrix}
3860 a_1 & \Cdots & & & a_1 \\
3861 \Vdots & a_2 & \Cdots & & a_2 \\
3862 & \Vdots & \Ddots[color=red] \\
3863 \\
3864 a_1 & a_2 & & & a_n
3865 \end{bNiceMatrix}$
3866
3867 \interitem In order to represent the null matrix, one can use the following
3868 code:
3869
3870 \nobreak
3871 \bigskip
3872 \begin{Code}[width=10cm]
3873 \begin{bNiceMatrix}
3874 0 & \Cdots & 0 \\
3875 \Vdots & & \Vdots \\
3876 0 & \Cdots & 0
3877 \end{bNiceMatrix}
3878 \end{Code}
3879 $\begin{bNiceMatrix}
3880 0 & \Cdots & 0 \\
3881 \Vdots & & \Vdots \\
3882 0 & \Cdots & 0
3883 \end{bNiceMatrix}$
3884
3885 \bigskip
3886 However, one may prefer a larger matrix. Usually, in such a case, the users of
3887 LaTeX add a new row and a new column. It's possible to use the same method
3888 with \pkg{nicematrix}:
3889
3890 \nobreak
3891 \bigskip
3892 \begin{Code}[width=10cm]
3893 \begin{bNiceMatrix}
3894 0 & \Cdots & \Cdots & 0 \\
3895 \Vdots & & & \Vdots \\
3896 \Vdots & & & \Vdots \\
3897 0 & \Cdots & \Cdots & 0
3898 \end{bNiceMatrix}
3899 \end{Code}
3900 $\begin{bNiceMatrix}
3901 0 & \Cdots & & 0 \\
3902 \Vdots & & & \\
3903 & & & \Vdots \\
3904 0 & & \Cdots & 0
3905 \end{bNiceMatrix}$
3906
3907 \bigskip
3908 In the first column of this example, there are two instructions |\Vdots| but,
3909 of course, only one dotted line is drawn.
3910
3911 \bigskip
3912 In fact, in this example, it would be possible to draw the same matrix more
3913 easily with the following code:
3914
3915 \nobreak
3916 \bigskip
3917 \begin{Code}[width=10cm]
3918 \begin{bNiceMatrix}
3919 0 & \Cdots & & 0 \\
3920 \Vdots & & & \\
3921 & & & \Vdots \\
3922 0 & & \Cdots & 0
3923 \end{bNiceMatrix}
3924 \end{Code}
3925 $\begin{bNiceMatrix}
3926 0 & \Cdots & & 0 \\
3927 \Vdots & & & \\
3928 & & & \Vdots \\
3929 0 & & \Cdots & 0
3930 \end{bNiceMatrix}$
3931
3932 \bigskip
3933 There are also other means to change the size of the matrix. Someone might
3934 want to use the optional argument of the command~|\\| for the vertical
3935 dimension and a command~|\hspace*| in a cell for the horizontal
3936 dimension.\footnote{In \pkg{nicematrix}, one should use |\hspace*| and not
3937 |\hspace| for such an usage because \pkg{nicematrix} loads \pkg{array}. One
3938 may also remark that it's possible to fix the width of a column by using the
3939 environment |{NiceArray}| (or one of its variants) with a column of type~|w|
3940 or~|W|: cf.~\ref{width}, p.~\pageref{width}}
3941
3942 \indexcommand{Hspace}
3943 However, a command~|\hspace*| might interfere with the construction of the
3944 dotted lines. That's why the package \pkg{nicematrix} provides a
3945 command~\DefinitionCommand{Hspace} which is a variant of |\hspace| transparent
3946 for the dotted lines of \pkg{nicematrix}.
3947
3948 \nobreak
3949 \bigskip
3950 \begin{Code}[width=10cm]
3951 $\begin{bNiceMatrix}
3952 0 & \Cdots & \emph{\Hspace*{1cm}} & 0 \\
3953 \Vdots & & & \Vdots \\[1cm]
3954 0 & \Cdots & & 0
3955 \end{bNiceMatrix}$
3956 \end{Code}
3957 $\begin{bNiceMatrix}
3958 0 & \Cdots & \Hspace*{1cm} & 0 \\
3959 \Vdots & & & \Vdots \\[1cm]
3960 0 & \Cdots & & 0
3961 \end{bNiceMatrix}$
3962
3963
3964
3965 \subsection{The option xdots/nullify}
3966
3967 \index{nullify-dots}
3968 \label{nullify-dots}
3969
3970 Consider the following matrix composed classicaly with the environment
3971 |{pmatrix}| of \pkg{amsmath}.
3972
3973
3974 \nobreak
3975 \medskip
3976 \begin{Code}[width=10cm]
3977 $A = \begin{pmatrix}
3978 h & i & j & k & l & m \\
3979 x & & & & & x
3980 \end{pmatrix}$
3981 \end{Code}
3982 $A = \begin{pmatrix}
3983 h & i & j & k & l & m \\
3984 x & & & & & x
3985 \end{pmatrix}$
3986
3987
3988 \bigskip
3989 If we add |\ldots| instructions in the second row, the geometry of the
3990 matrix is modified.
3991
3992 \nobreak
3993 \medskip
3994 \begin{Code}[width=10cm]
3995 $B = \begin{pmatrix}
3996 h & i & j & k & l & m \\
3997 x & \ldots & \ldots & \ldots & \ldots & x
3998 \end{pmatrix}$
3999 \end{Code}
4000 $B = \begin{pmatrix}
4001 h & i & j & k & l & m \\
4002 x & \ldots & \ldots & \ldots & \ldots & x
4003 \end{pmatrix}$
4004
4005 \bigskip
4006 By default, with \pkg{nicematrix}, if we replace |{pmatrix}| by
4007 |{pNiceMatrix}| and |\ldots| by |\Ldots|, the geometry of the matrix is not
4008 changed.
4009
4010 \nobreak
4011 \medskip
4012 \begin{Code}[width=10cm]
4013 $C = \begin{pNiceMatrix}
4014 h & i & j & k & l & m \\
4015 x & \Ldots & \Ldots & \Ldots & \Ldots & x
4016 \end{pNiceMatrix}$
4017 \end{Code}
4018 $C = \begin{pNiceMatrix}
4019 h & i & j & k & l & m \\
4020 x & \Ldots & \Ldots & \Ldots & \Ldots & x
4021 \end{pNiceMatrix}$
4022
4023 \bigskip
4024 However, one may prefer the geometry of the first matrix $A$ and would like to
4025 have such a geometry with a dotted line in the second row. It's possible by
4026 using the option \Definition{xdots/nullify}\footnote{The key |xdots/nullify| has
4027 an alias, which is |nullify-dots|.} (and only one instruction |\Ldots| is
4028 necessary).
4029
4030 \nobreak
4031 \medskip
4032 \begin{Code}[width=10cm]
4033 $D = \begin{pNiceMatrix}[\emph{xdots/nullify}]
4034 h & i & j & k & l & m \\
4035 x & \Ldots & & & & x
4036 \end{pNiceMatrix}$
4037 \end{Code}
4038 $D = \begin{pNiceMatrix}[xdots/nullify]
4039 h & i & j & k & l & m \\
4040 x & \Ldots & & & & x
4041 \end{pNiceMatrix}$
4042
4043 \medskip
4044 The option |xdots/nullify| smashes the instructions |\Ldots| (and the variants)
4045 horizontally but also vertically.
4046
4047 \medskip
4048 \textbf{Caution}: the key |xdots/nullify| has a name that may be confusing; that
4049 key does not imply that the dotted rules won't be drawn!
4050
4051
4052
4053 \subsection{The commands \texttt{\textbackslash Hdotsfor} and \texttt{\textbackslash Vdotsfor}}
4054
4055 \indexcommand{Hdotsfor}
4056 \indexcommand{Vdotsfor}
4057
4058 Some people commonly use the command |\hdotsfor| of \pkg{amsmath} in order to
4059 draw horizontal dotted lines in a matrix. In the environments of
4060 \pkg{nicematrix}, one should use instead \DefinitionCommand{Hdotsfor} in order
4061 to draw dotted lines similar to the other dotted lines drawn by |\Cdots|, |\Vdots|, etc.
4062
4063
4064 As with the other commands of \pkg{nicematrix} (like |\Cdots|, |\Ldots|,
4065 |\Vdots|, etc.), the dotted line drawn with |\Hdotsfor| extends until the
4066 contents of the cells on both sides.
4067
4068 \medskip
4069 \begin{Code}[width=7cm]
4070 $\begin{pNiceMatrix}
4071 1 & 2 & 3 & 4 & 5 \\
4072 1 & \emph{\Hdotsfor{3}} & 5 \\
4073 1 & 2 & 3 & 4 & 5 \\
4074 1 & 2 & 3 & 4 & 5
4075 \end{pNiceMatrix}$
4076 \end{Code}
4077 $\begin{pNiceMatrix}
4078 1 & 2 & 3 & 4 & 5 \\
4079 1 & \Hdotsfor{3} & 5 \\
4080 1 & 2 & 3 & 4 & 5 \\
4081 1 & 2 & 3 & 4 & 5
4082 \end{pNiceMatrix}$
4083
4084 \bigskip
4085 However, if these cells are empty, the dotted line extends only in the cells
4086 specified by the argument of |\Hdotsfor| (by design).
4087
4088 \medskip
4089 \begin{Code}[width=7cm]
4090 $\begin{pNiceMatrix}
4091 1 & 2 & 3 & 4 & 5 \\
4092 & \emph{\Hdotsfor{3}} \\
4093 1 & 2 & 3 & 4 & 5 \\
4094 1 & 2 & 3 & 4 & 5
4095 \end{pNiceMatrix}$
4096 \end{Code}
4097 $\begin{pNiceMatrix}
4098 1 & 2 & 3 & 4 & 5 \\
4099 & \Hdotsfor{3} \\
4100 1 & 2 & 3 & 4 & 5 \\
4101 1 & 2 & 3 & 4 & 5
4102 \end{pNiceMatrix}$
4103
4104 \medskip
4105 Remark: Unlike the command |\hdotsfor| of \pkg{amsmath}, the command |\Hdotsfor|
4106 may be used even when the package \pkg{colortbl}\footnote{We recall that when
4107 \pkg{xcolor} is loaded with the option |table|, the package \pkg{colortbl} is
4108 loaded.} is loaded (however, with \pkg{nicematrix}, loading \pkg{colortbl} is
4109 rather point-less since \pkg{nicematrix} provides its own coloring tools: cf.~\ref{color-in-code-before},
4110 p.~\pageref{color-in-code-before}).
4111
4112 \bigskip
4113 The package \pkg{nicematrix} also provides a command
4114 \DefinitionCommand{Vdotsfor} similar to |\Hdotsfor| but for the vertical dotted
4115 lines.
4116
4117 \bigskip
4118 The following example uses both |\Hdotsfor| and |\Vdotsfor|:
4119
4120 \smallskip
4121 \begin{scope}
4122 \small
4123 \begin{Code}
4124 \begin{bNiceMatrix}
4125 C[a_1,a_1] & \Cdots & C[a_1,a_n]
4126 & \hspace*{20mm} & C[a_1,a_1^{(p)}] & \Cdots & C[a_1,a_n^{(p)}] \\
4127 \Vdots & \Ddots & \Vdots
4128 & \emph{\Hdotsfor{1}} & \Vdots & \Ddots & \Vdots \\
4129 C[a_n,a_1] & \Cdots & C[a_n,a_n]
4130 & & C[a_n,a_1^{(p)}] & \Cdots & C[a_n,a_n^{(p)}] \\
4131 \rule{0pt}{15mm}\NotEmpty & \emph{\Vdotsfor{1}} & & \Ddots & & \emph{\Vdotsfor{1}} \\
4132 C[a_1^{(p)},a_1] & \Cdots & C[a_1^{(p)},a_n]
4133 & & C[a_1^{(p)},a_1^{(p)}] & \Cdots & C[a_1^{(p)},a_n^{(p)}] \\
4134 \Vdots & \Ddots & \Vdots
4135 & \emph{\Hdotsfor{1}} & \Vdots & \Ddots & \Vdots \\
4136 C[a_n^{(p)},a_1] & \Cdots & C[a_n^{(p)},a_n]
4137 & & C[a_n^{(p)},a_1^{(p)}] & \Cdots & C[a_n^{(p)},a_n^{(p)}]
4138 \end{bNiceMatrix}
4139 \end{Code}
4140 \end{scope}
4141
4142
4143 \[\begin{bNiceMatrix}
4144 C[a_1,a_1] & \Cdots & C[a_1,a_n] & \hspace*{20mm} & C[a_1,a_1^{(p)}] & \Cdots & C[a_1,a_n^{(p)}] \\
4145 \Vdots & \Ddots & \Vdots & \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
4146 C[a_n,a_1] & \Cdots & C[a_n,a_n] & & C[a_n,a_1^{(p)}] & \Cdots & C[a_n,a_n^{(p)}] \\
4147 \rule{0pt}{15mm}\NotEmpty & \Vdotsfor{1} & & \Ddots & & \Vdotsfor{1} \\
4148 C[a_1^{(p)},a_1] & \Cdots & C[a_1^{(p)},a_n] & & C[a_1^{(p)},a_1^{(p)}] & \Cdots & C[a_1^{(p)},a_n^{(p)}] \\
4149 \Vdots & \Ddots & \Vdots & \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
4150 C[a_n^{(p)},a_1] & \Cdots & C[a_n^{(p)},a_n] & & C[a_n^{(p)},a_1^{(p)}] & \Cdots & C[a_n^{(p)},a_n^{(p)}]
4151 \end{bNiceMatrix}\]
4152
4153
4154
4155 \subsection{How to generate the dotted leaders transparently}
4156
4157 \index{renew-matrix}
4158 \index{renew-dots}
4159
4160 Imagine you have a document with a great number of mathematical matrices with
4161 ellipsis. You may wish to use the dotted lines of \pkg{nicematrix} without
4162 having to modify the code of each matrix. It's possible with the keys.
4163 |renew-dots| and |renew-matrix|.\footnote{The options |renew-dots|,
4164 |renew-matrix| can be fixed with the command
4165 |\NiceMatrixOptions| like the other options. However, they can also be fixed
4166 as options of the command |\usepackage|.}
4167
4168 \smallskip
4169
4170 \begin{itemize}
4171 \item The option \Definition{renew-dots}
4172
4173 \nobreak
4174 With this option, the commands |\ldots|, |\cdots|, |\vdots|, |\ddots|,
4175 |\iddots|\footnotemark[\thefniddots] and |\hdotsfor| are redefined within the
4176 environments provided by \pkg{nicematrix} and behave like |\Ldots|, |\Cdots|,
4177 |\Vdots|, |\Ddots|, |\Iddots| and |\Hdotsfor|; the command |\dots|
4178 (``automatic dots'' of |amsmath|) is also redefined to behave like |\Ldots|.
4179
4180 \item The option \Definition{renew-matrix}
4181
4182 \nobreak
4183 With this option, the environment |{matrix}| is redefined and behave like
4184 |{NiceMatrix}|, and so on for the five variants with delimiters.
4185 \end{itemize}
4186
4187 \bigskip
4188 Therefore, with the keys |renew-dots| and |renew-matrix|, a classical code
4189 gives directly the output of \pkg{nicematrix}.
4190
4191 \nobreak
4192 \medskip
4193 \begin{scope}
4194 \NiceMatrixOptions{renew-dots,renew-matrix}
4195 \begin{Code}[width=10cm]
4196 \emph{\NiceMatrixOptions{renew-dots,renew-matrix}}
4197 \begin{pmatrix}
4198 1 & \cdots & \cdots & 1 \\
4199 0 & \ddots & & \vdots \\
4200 \vdots & \ddots & \ddots & \vdots \\
4201 0 & \cdots & 0 & 1
4202 \end{pmatrix}
4203 \end{Code}
4204 $\begin{pmatrix}
4205 1 & \cdots & \cdots & 1 \\
4206 0 & \ddots & & \vdots \\
4207 \vdots & \ddots & \ddots & \vdots \\
4208 0 & \cdots & 0 & 1
4209 \end{pmatrix}$
4210 \end{scope}
4211
4212 \bigskip
4213 However, one should note that the environments of \pkg{nicematrix} can't be
4214 nested, and, therefore, it's not possible to use |renew-matrix| if we have, for
4215 example, an environment |{pmatrix}| nested within another environment |{pmatrix}|.
4216
4217
4218 \subsection{The labels of the dotted leaders}
4219
4220
4221
4222 The commands |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots|, |\Hdotsfor| and
4223 |\Vdotsfor| (and the command |\line| in the |\CodeAfter| which is described in
4224 the section~\ref{line-in-code-after}, p.~\pageref{line-in-code-after}) accept
4225 three optional arguments specified by the tokens |_|, |^| and |:| for labels
4226 positioned below, above or on the line. The arguments are composed in math mode
4227 with |\scriptstyle|.
4228
4229 The label specified by ``|:|'' is composed on a white background which is put on
4230 the line previously drawn (cf. example~\ref{ex:colon}, p.~\pageref{ex:colon}).
4231
4232 \bigskip
4233 \begin{Code}[width=10cm]
4234 $\begin{bNiceMatrix}
4235 1 & \hspace*{1cm} & 0 \\[8mm]
4236 & \emph{\Ddots^{n \text{ times}}} & \\
4237 0 & & 1
4238 \end{bNiceMatrix}$
4239 \end{Code}
4240 $\begin{bNiceMatrix}
4241 1 & \hspace*{1cm} & 0 \\[8mm]
4242 & \Ddots^{n \text{ times}} & \\
4243 0 & & 1
4244 \end{bNiceMatrix}$
4245
4246
4247 \bigskip
4248 With the key \Definition{horizontal-label}, the label stays horizontal.
4249
4250 \nobreak
4251 \medskip
4252 \begin{Code}[width=10cm]
4253 $\begin{bNiceMatrix}
4254 1 & \hspace*{1cm} & 0 \\[8mm]
4255 & \emph{\Ddots[horizontal-label]^{n \text{ times}}} & \\
4256 0 & & 1
4257 \end{bNiceMatrix}$
4258 \end{Code}
4259 $\begin{bNiceMatrix}
4260 1 & \hspace*{1cm} & 0 \\[8mm]
4261 & \Ddots[horizontal-label]^{n \text{ times}} & \\
4262 0 & & 1
4263 \end{bNiceMatrix}$
4264
4265
4266
4267 \subsection{Customisation of the dotted leaders}
4268
4269 \label{customisation}
4270 \index{color!key for dotted rules}
4271 \index{radius (key for dotted rules)}
4272 \index{inter (key for dotted rules)}
4273 \index{line-style (key for dotted rules)}
4274 \index{shorten (key for dotted rules)}
4275 \index{shorten-end (key for dotted rules)}
4276 \index{shorten-start (key for dotted rules)}
4277 \index{horizontal-label(s) (key for dotted rules)}
4278 \index{nullify (key for dotted rules)}
4279
4280 The dotted lines drawn by |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots|,
4281 |\Hdotsfor| and |\Vdotsfor| (and by the command |\line| in the |\CodeAfter|
4282 which is described in the section~\ref{line-in-code-after},
4283 p.~\pageref{line-in-code-after}) may be customized by the following options
4284 (specified between square brackets after the command):
4285 \begin{itemize}
4286 \item |nullify|;
4287 \item |horizontal-label(s)|;
4288 \item |color|;
4289 \item |radius|;
4290 \item |shorten-start|$^+$, |shorten-end|$^+$ and |shorten|$^+$;
4291 \item |inter|;
4292 \item |line-style|.
4293 \end{itemize}
4294
4295 \smallskip
4296 For an individual command, it's possible to write |horizontal-label| (in the
4297 singular).
4298
4299 \smallskip
4300 These options may also be fixed with |\NiceMatrixOptions|, as options of
4301 |\CodeAfter| or at the level of a given environment but, in those cases, they
4302 must be prefixed by |xdots| (\textsl{xdots} to remind that it works for
4303 |\Cdots|, |\Ldots|, |\Vdots|, etc.), and, thus have for names:
4304 \begin{itemize}
4305 \item |xdots/nullify|;
4306 \item |xdots/horizontal-labels|;
4307 \item |xdots/color|;
4308 \item |xdots/radius|;
4309 \item |xdots/shorten-start|$^+$, |xdots/shorten-end|$^+$ and |xdots/shorten|$^+$;
4310 \item |xdots/inter|;
4311 \item |xdots/line-style|.
4312 \end{itemize}
4313
4314 For the clarity of the explanations, we will use those names.
4315
4316 \bigskip
4317 The key \Definition{xdots/nullify} has yet been described in the
4318 part~\ref{nullify-dots}, p.~\pageref{nullify-dots}.
4319
4320 \bigskip
4321 With the key \Definition{xdots/horizontal-labels}, the labels (introduced by~|_|,
4322 |^| and~|:|) stay horizontal.
4323
4324 \bigskip
4325 The option \Definition{xdots/color} fixes the color of the dotted line. It's
4326 possible to use a color defined ``on the fly''
4327 (e.g.: |xdots/color = { [RGB]{204,204,255} }|). One should remark that
4328 the dotted lines drawn in the exterior rows and columns have a special
4329 treatment: cf.~\ref{exterior}, p.~\pageref{exterior}.
4330
4331 \bigskip
4332 The option \Definition{xdots/radius} fixes the radius of the dots. The initial value
4333 is 0.53~pt.
4334
4335 \bigskip
4336 The keys \Definition{xdots/shorten-start}$^+$ and \Definition{xdots/shorten-end}$^+$ fix
4337 the margin at the extremities of the line. The key |xdots/shorten|$^+$ fixes both
4338 parameters. The initial value is 0.3~em.\footnote{In fact, when
4339 |xdots/shorten|, |xdots/shorten-start| and |xdots/shorten-end| are used in
4340 |\NiceMatrixOptions| or at the level of an environment (such as
4341 |{pNiceMatrix}|), those keys only apply to the extremeties of dotted lines
4342 corresponding to a non-empty content of a cell. When they are used for a command
4343 such as |\Cdots| (and, in that case, their names are |shorten|,
4344 |shorten-start| and |shorten-end|), they apply to all the extremities.}
4345
4346 \medskip
4347 These keys have a normal syntax but also a ``additive'' syntax. That means that
4348 it's possible to write, for example, |xdots/shorten = 0.6em| but also
4349 |xdots/shorten += 3pt| (ant we remind that the initial value is \emph{not} zero!).
4350
4351 \bigskip
4352 The option \Definition{xdots/inter} fixes the length between the dots. The
4353 initial value is 0.45~em (it is recommended to use a unit of length dependent of
4354 the current font).
4355
4356 \bigskip
4357 \textbf{The option \Definition{xdots/line-style}}
4358
4359 \nobreak
4360 \smallskip
4361 It should be pointed that, by default, the lines drawn by TikZ with the
4362 parameter |dotted| are composed of square dots (and not rounded
4363 ones).\footnote{The first reason of this behaviour is that the \textsc{pdf}
4364 format includes a description for dashed lines. The lines specified with this
4365 descriptor are displayed very efficiently by the \textsc{pdf} readers. It's
4366 easy, starting from these dashed lines,
4367 to create a line composed by square dots whereas a line of rounded dots needs
4368 a specification of each dot in the \textsc{pdf} file. Nevertheless, you can
4369 have a look at the following page to see how to have dotted rules with rounded
4370 dots in TikZ:\newline \small
4371 \url{https://tex.stackexchange.com/questions/52848/tikz-line-with-large-dots}}
4372
4373 \begin{BVerbatim}[baseline=c,boxwidth=9cm]
4374 \tikz \draw [dotted] (0,0) -- (5,0) ;
4375 \end{BVerbatim}
4376 \tikz \draw [dotted] (0,0) -- (5,0) ;
4377
4378 \medskip
4379 In order to provide lines with rounded dots in the style of those provided by
4380 |\ldots| (at least with the \emph{Computer Modern} fonts), the package
4381 \pkg{nicematrix} embeds its own system to draw a dotted line (and this system
4382 uses \textsc{pgf} and not TikZ). This style is called |standard| and that's
4383 the initial value of the parameter |xdots/line-style|.
4384
4385 However (when TikZ is loaded) it's possible to use for |xdots/line-style| any style
4386 provided by TikZ, that is to say any sequence of options provided by TikZ for
4387 the TikZ paths (with the exception of ``|color|'', ``|shorten >|'' and
4388 ``|shorten <|'').
4389
4390 \medskip
4391 Here is for example a tridiagonal matrix with the style |loosely dotted|:
4392
4393 \nobreak
4394 \medskip
4395 \begin{Code}
4396 \[\begin{pNiceMatrix}[xdots={nullify, \emph{shorten += 2pt, line-style = loosely dotted}}]
4397 a & b & 0 & & \Cdots & 0 \\
4398 b & a & b & \Ddots & & \Vdots \\
4399 0 & b & a & \Ddots & & \\
4400 & \Ddots & \Ddots & \Ddots & & 0 \\
4401 \Vdots & & & & & b \\
4402 0 & \Cdots & & 0 & b & a
4403 \end{pNiceMatrix}$
4404 \end{Code}
4405
4406
4407 \[\begin{pNiceMatrix}[xdots={nullify, shorten += 2pt, line-style = loosely dotted}]
4408 a & b & 0 & & \Cdots & 0 \\
4409 b & a & b & \Ddots & & \Vdots \\
4410 0 & b & a & \Ddots & & \\
4411 & \Ddots & \Ddots & \Ddots & & 0 \\
4412 \Vdots & & & & & b \\
4413 0 & \Cdots & & 0 & b & a
4414 \end{pNiceMatrix}\]
4415
4416 \subsection{The dotted leaders and the rules}
4417
4418 \label{dotted-and-rules}
4419
4420 The dotted lines determine virtual blocks which have the same behaviour
4421 regarding the rules (the rules specified by the specifier \verb+|+ in the
4422 preamble, by the command |\Hline|, by the keys |hlines|, |vlines|, |hvlines| and
4423 |hvlines-except-borders| and by the tools created by |custom-line| are not drawn
4424 within the blocks).\footnote{On the other side, the command |\line| in the
4425 |\CodeAfter| (cf.~\ref{line-in-code-after}, p.~\pageref{line-in-code-after})
4426 does \emph{not} create any block.}
4427
4428 \medskip
4429 \begin{Code}[width=10.6cm]
4430 $\begin{bNiceMatrix}[margin,\emph{hvlines}]
4431 \Block{3-3}<\LARGE>{A} & & & 0 \\
4432 & \hspace*{1cm} & & \Vdots \\
4433 & & & 0 \\
4434 0 & \Cdots& 0 & 0
4435 \end{bNiceMatrix}$
4436 \end{Code}
4437 $\begin{bNiceMatrix}[margin,hvlines]
4438 \Block{3-3}<\LARGE>{A} & & & 0 \\
4439 & \hspace*{1cm} & & \Vdots \\
4440 & & & 0 \\
4441 0 & \Cdots& 0 & 0
4442 \end{bNiceMatrix}$
4443
4444
4445
4446 \subsection{The commands \texttt{\textbackslash Hbrace} and \texttt{\textbackslash Vbrace}}
4447
4448
4449 \indexcommand{Hbrace}
4450 \indexcommand{Vbrace}
4451 \index{brace (nicematrix/brace is a TikZ style\newline used by
4452 \texttt{\textbackslash Hbrace} et \texttt{\textbackslash Vbrace})}
4453 \index{tikz-braces (key at load-tome of \texttt{nicematrix)}}
4454 \label{Hbrace}
4455
4456
4457 \smallskip
4458 Since, as said previously, it's possible to use, with the commands |\Cdots|,
4459 |\Ldots|, |\Vdots|, etc. all the styles of lines provided by TikZ, one may wish
4460 to use those commands to draw braces with the decoration |brace| provided by the
4461 library \pkg{decorations.pathreplacing} of TikZ.
4462
4463 \smallskip
4464 In order to facilitate that use, \pkg{nicematrix} provides two commands
4465 \DefinitionCommand{Hbrace} and \DefinitionCommand{Vbrace}. Those commands are
4466 available only if TikZ has been loaded with its library
4467 \pkg{decorations.pathreplacing} (before or after the loading of
4468 \pkg{nicematrix}). Otherwise, a (non-fatal) error will be raised.
4469 \begin{Verbatim}
4470 \usepackage{tikz}
4471 \usetikzlibrary{decorations.pathreplacing}
4472 \end{Verbatim}
4473
4474 \medskip
4475 The commands |\Hbrace| and |\Vbrace| have the same syntax. Both commands take in
4476 three arguments:
4477 \begin{itemize}
4478 \item an optional argument, between square brackets, which contains a list of
4479 \textsl{key=value} pairs: the keys allowed are |color|, |horizontal-labels|,
4480 |shorten|, |shorten-start| and |shorten-end|.
4481
4482 \smallskip
4483 \index{brace-shift (key of \texttt{\textbackslash Hbrace} and \texttt{\textbackslash Vbrace})}
4484
4485 A key \Definition{brace-shift}$^+$ is also provided to shift the brace (and its
4486 label) towards the exterior of the matrix. That key has a normal syntax but also an
4487 ``additive'' syntax, which means that it's possible to write, for example,
4488 |brace-shift = 3pt| but also |brace-shift += 1pt|.
4489
4490 \item a mandatory argument which is the number of columns (for |\Hbrace|) or the
4491 number of rows (for |\Vbrace|) over which the command applies;
4492
4493 \item an mandatory argument which is the label of the curly brace.
4494 \end{itemize}
4495
4496 As regards the ampersands (|&|), |\Hbrace| has the same behavior as the commands
4497 |\multicolumn|, |\hdotsfor|, |\Hdotsfor| (provided by \pkg{nicematrix}), etc.:
4498 only one ampersand must be inserted, even if the brace that will be drawn will
4499 extend on several columns.
4500
4501
4502 \bigskip
4503 \begin{footnotesize}
4504 \begin{Verbatim}
4505 \usepackage{tikz} % in the preamble
4506 \usetikzlibrary{decorations.pathreplacing} % in the preamble
4507 \end{Verbatim}
4508 \end{footnotesize}
4509
4510 \medskip
4511 \begin{Code}[width=11.2cm]
4512 $\begin{NiceArray}{ccccc}%
4513 [ hvlines ,
4514 first-row ,
4515 last-row = 6,
4516 first-col ,
4517 last-col ,
4518 xdots/horizontal-labels ]
4519 & \emph{\Hbrace{3}{p}} & \emph{\Hbrace[brace-shift=1mm]{2}{q}} \\
4520 \emph{\Vbrace{3}{p}} & 1 & 1 & 134 & 1 & 1 & \emph{\Vbrace{3}{p}} \\
4521 & 1 & 1 & 134 & 1 & 1 \\
4522 & 1 & 1 & 13456 & 1 & 1 \\
4523 \emph{\Vbrace{2}{q}} & 1 & 1 & 134 & 1 & 1 & \emph{\Vbrace{2}{q}}\\
4524 & 1 & 1 & 134 & 1 & 1 \\
4525 & \emph{\Hbrace{3}{p}} & \emph{\Hbrace[color=blue]{2}{q}} \\
4526 \end{NiceArray}$
4527 \end{Code}
4528 $\begin{NiceArray}{ccccc}%
4529 [
4530 hvlines ,
4531 first-row ,
4532 last-row = 6,
4533 first-col ,
4534 last-col ,
4535 xdots/horizontal-labels
4536 ]
4537 & \Hbrace{3}{p} & \Hbrace[brace-shift=1mm]{2}{q} \\
4538 \Vbrace{3}{p} & 1 & 1 & 134 & 1 & 1 & \Vbrace{3}{p} \\
4539 & 1 & 1 & 134 & 1 & 1 \\
4540 & 1 & 1 & 13456 & 1 & 1 \\
4541 \Vbrace{2}{q}& 1 & 1 & 134 & 1 & 1 & \Vbrace{2}{q}\\
4542 & 1 & 1 & 134 & 1 & 1 \\
4543 & \Hbrace{3}{p} & \Hbrace[color=blue]{2}{q} \\
4544 \end{NiceArray}$
4545
4546 \medskip
4547 The TikZ style used by \pkg{nicematrix} to draw those braces is called
4548 \Definition{nicematrix/brace}. Here is the initial value of that style:
4549
4550 \begin{Code}[annotation = false]
4551 \emph{decoration = { brace , raise = -0.15 em } , }
4552 \emph{decorate }
4553 \end{Code}
4554
4555 The final user can change that TikZ style as he wishes (respecting the structure
4556 with the keys |decorate| and |decoration|).
4557
4558
4559 \medskip
4560 For another example of use of |\Hbrace| and |\Vbrace|,
4561 see~(\ref{ex:no-longer-dotted-rules} p.~\pageref{ex:no-longer-dotted-rules}).
4562
4563
4564 \medskip
4565 It's also possible to draw braces of the mathematical mode of LaTeX by using the
4566 commands |\OverBrace| and |\UnderBrace| (cf.~\ref{OverBrace},
4567 p.~\pageref{OverBrace}) and the command |\SubMatrix| (cf.~\ref{SubMatrix},
4568 p.~\pageref{sub-matrix}) in the |\CodeAfter|.
4569
4570
4571
4572 \index{dotted@\textbf{Dotted lines}|)}
4573
4574 \section{Delimiters in the preamble of the environment}
4575
4576 \index{blkarray@\pkg{blkarray} (package)}
4577
4578 \index{delimiters@delimiters in the preambles}
4579
4580 \label{delimiters-in-preamble}
4581
4582 In the environments with preamble (|{NiceArray}|, |{pNiceArray}|, etc.), it's
4583 possible to put vertical delimiters directly in the preamble of the
4584 environment.\footnote{This syntax is inspired by the extension \pkg{blkarray}.}
4585
4586 \smallskip
4587 \index{left@\texttt{\textbackslash left} : used by \pkg{nicematrix} for\newline
4588 delimiters in the preambles} \index{right@\texttt{\textbackslash right} : used
4589 by \pkg{nicematrix} for\newline delimiters in the preambles} The opening
4590 delimiters should be prefixed by the keyword \DefinitionCommand{left} and the
4591 closing delimiters by the keyword \DefinitionCommand{right}. It's not mandatory
4592 to use |\left| and |\right| pair-wise.
4593
4594 \smallskip
4595 All the vertical extensible delimiters of LaTeX are allowed.
4596
4597 \medskip
4598 Here is a example which uses the delimiters |\lgroup| and |\rgroup|.
4599
4600 \smallskip
4601 \begin{Code}
4602 $\begin{NiceArray}{\emph{\left\lgroup} ccc\emph{\right\rgroup} l}
4603 1 & 2 & 3 &
4604 4 & 1 & 6 &
4605 7 & 8 & 9 & \scriptstyle L_3 \gets L_3 + L_1 + L_2
4606 \end{NiceArray}$
4607 \end{Code}
4608
4609 \[\begin{NiceArray}{\left\lgroup ccc\right\rgroup l}
4610 1 & 2 & 3 & \\
4611 4 & 1 & 6 & \\
4612 7 & 8 & 9 & \scriptstyle L_3 \gets L_3 + L_1 + L_2
4613 \end{NiceArray}\]
4614
4615 \medskip
4616 For this example, it would also have been possible to use the environment
4617 |{NiceArrayWithDelims}| (cf.~\ref{NiceArrayWithDelims},
4618 p.~\pageref{NiceArrayWithDelims}) and the key |last-col| (cf.~\ref{exterior},
4619 p.~\pageref{exterior}).
4620
4621 \bigskip
4622 There is a particular case: for the delimiters |(|, |[| and |\{|\footnote{For
4623 the braces, the protection by a backslash is mandatory (that's why we have
4624 written |\{|).},
4625 and the corresponding closing delimiters, the prefixes |\left| et |\right| are
4626 optional.\footnote{For the delimiters |[| and |]|, the prefixes remain mandatory
4627 when there is a conflict of notation with the square brackets for the options
4628 of some descriptors of columns.}
4629
4630 \bigskip
4631 Here is an example with a left delimiter |\{| in a |{NiceTabular}| (remark the
4632 compatibility with the key |t|).
4633
4634 \smallskip
4635 \begin{Verbatim}
4636 We define $f$ with\quad
4637 \begin{NiceTabular}[t]{\{ll}
4638 $f(x) = 0$ & if $x$ is non positive \\
4639 $f(x) = 1-e^x$ & if $x$ is positive
4640 \end{Verbatim}
4641
4642 \smallskip
4643 \begin{center}
4644 On définit $f$ par\quad
4645 \begin{NiceTabular}[t]{\{ll}
4646 $f(x) = 0$ & if $x$ is non positive\\
4647 $f(x) = 1-e^x$ & if $x$ is positive
4648 \end{NiceTabular}
4649 \end{center}
4650
4651
4652 \bigskip
4653 When there are two successive delimiters (necessarily a closing one following by
4654 an opening one for another submatrix), a space equal to |\enskip| is
4655 automatically inserted.
4656
4657 \medskip
4658 \begin{Code}
4659 $\begin{pNiceArray}{\emph{(c)(c)(c)}}
4660 a_{11} & a_{12} & a_{13} \\
4661 a_{21} & \displaystyle \int_0^1\dfrac{1}{x^2+1}\,dx & a_{23} \\
4662 a_{31} & a_{32} & a_{33}
4663 \end{pNiceArray}$
4664 \end{Code}
4665
4666 \[\begin{pNiceArray}{(c)(c)(c)}
4667 a_{11} & a_{12} & a_{13} \\
4668 a_{21} & \displaystyle \int_0^1\dfrac{1}{x^2+1}\,dx & a_{23} \\
4669 a_{31} & a_{32} & a_{33}
4670 \end{pNiceArray}\]
4671
4672
4673 \bigskip
4674 For more complex constructions, in particular with delimiters spanning only a
4675 \emph{subset} of the rows of the array, one should consider the command
4676 |\SubMatrix| available in the |\CodeAfter| (and the |\CodeBefore|). See the
4677 section~\ref{sub-matrix}, p.~\pageref{sub-matrix}.
4678
4679
4680
4681 \section{The \textbackslash CodeAfter}
4682
4683 \index{CodeAfter@\texttt{\textbackslash CodeAfter}|(}
4684 \index{code-after}
4685
4686 \label{code-after}
4687 The option \Definition{code-after} may be used to give some code that will be
4688 executed \emph{after} the construction of the matrix.\footnote{There is also a
4689 key |code-before| described in the section~\ref{code-before}, p.~\pageref{code-before}.}
4690
4691 \medskip
4692 \index{sub-matrix (key of \texttt{\textbackslash CodeAfter}, with subkeys)}
4693 For the legibility of the code, an alternative syntax is provided: it's
4694 possible to give the instructions of the |code-after| at the end of the
4695 environment, after the keyword \DefinitionCommand{CodeAfter} (the key
4696 |code-after| is of course mandatory in the |\AutoNiceMatrix| and the
4697 similar commands). Although |\CodeAfter| is a keyword, it takes in an optional
4698 argument (between square brackets).\footnote{Here are the keys accepted in that argument:
4699 |delimiters/color|, |rules| and its sub-keys, |sub-matrix| (linked to the
4700 command |\SubMatrix|) and its sub-keys and |xdots| (for the command |\line|) and
4701 its sub-keys.}
4702
4703
4704 \medskip
4705 The experienced users may, for instance, use the PGF/TikZ nodes created by
4706 \pkg{nicematrix} in the |\CodeAfter|. These nodes are described further
4707 in the section~\ref{PGF-nodes}, p.~\pageref{PGF-nodes}.
4708
4709 \medskip
4710 The |\CodeAfter| provides several special commands: |\line|,
4711 |\SubMatrix|, |\OverBrace|, |\UnderBrace| and |\TikzEveryCell|. We will now
4712 present these commands.
4713
4714 \medskip
4715 One should avoid spurious spaces in that |\CodeAfter|.\footnote{See:
4716 \url{https://tex.stackexchange.com/questions/689336}}
4717
4718
4719 \subsection{The command \texttt{\textbackslash line} in the \texttt{\textbackslash CodeAfter}}
4720
4721 \label{line-in-code-after}
4722 \index{line@\texttt{\textbackslash line} (command of \texttt{\textbackslash CodeAfter})}
4723 The command \DefinitionCommand{line} draws directly dotted lines between cells
4724 or blocks. The mechanism for those dotted lines is the same as the mechanism used
4725 for the dotted leaders created by the commands |\Cdots|, |\Ldots|, etc.
4726 (cf.~\ref{Cdots}, p.~\pageref{Cdots}). The command |\lines| takes in
4727 two arguments for the cells or blocks to link. Both arguments may be:
4728 \begin{itemize}
4729 \item a specification of cell of the form $i$-$j$ where is the
4730 number of the row and $j$ is the number of the column;
4731 \item the name of a block (created by the command |\Block| with the key |name|
4732 of that command).
4733 \end{itemize}
4734 The options available for the customisation of the dotted lines created by
4735 |\Cdots|, |\Vdots|, etc. are also available for this command (cf.~\ref{customisation},
4736 p.~\pageref{customisation}).
4737
4738 \bigskip
4739 This command may be used, for example, to draw a dotted line between two
4740 adjacent cells.
4741
4742 \medskip
4743 \begin{Code}[width=11cm]
4744 \begin{pNiceMatrix}[xdots/shorten += 0.3 em]
4745 I & 0 & \Cdots &0 \\
4746 0 & I & \Ddots &\Vdots\\
4747 \Vdots &\Ddots & I &0 \\
4748 0 &\Cdots & 0 &I
4749 \emph{\CodeAfter \line{2-2}{3-3}}
4750 \end{pNiceMatrix}
4751 \end{Code}
4752 \begin{scope}
4753 $\begin{pNiceMatrix}[xdots/shorten += 0.3 em]
4754 I & 0 & \Cdots &0 \\
4755 0 & I & \Ddots &\Vdots\\
4756 \Vdots &\Ddots & I &0 \\
4757 0 &\Cdots & 0 &I
4758 \CodeAfter \line{2-2}{3-3}
4759 \end{pNiceMatrix}$
4760 \end{scope}
4761
4762 \bigskip
4763 It can also be used to draw a diagonal line not parallel to the other diagonal
4764 lines (by default, the dotted lines drawn by |\Ddots| are ``parallelized'':
4765 cf.~\ref{parallelization}, p.~\pageref{parallelization}).
4766
4767 \medskip
4768 \begin{Code}
4769 \begin{bNiceMatrix}
4770 1 & \Cdots & & 1 & 2 & \Cdots & 2 \\
4771 0 & \Ddots & & \Vdots & \Vdots & \hspace*{2.5cm} & \Vdots \\
4772 \Vdots & \Ddots & & & & & \\
4773 0 & \Cdots & 0 & 1 & 2 & \Cdots & 2
4774 \emph{\CodeAfter \line[shorten=6pt]{1-5}{4-7}}
4775 \end{bNiceMatrix}
4776 \end{Code}
4777 \[\begin{bNiceMatrix}
4778 1 & \Cdots & & 1 & 2 & \Cdots & 2 \\
4779 0 & \Ddots & & \Vdots & \Vdots & \hspace*{2.5cm} & \Vdots \\
4780 \Vdots & \Ddots & & & & & \\
4781 0 & \Cdots & 0 & 1 & 2 & \Cdots & 2
4782 \CodeAfter \line[shorten=6pt]{1-5}{4-7}
4783 \end{bNiceMatrix}\]
4784
4785
4786
4787
4788 \subsection{The command \texttt{\textbackslash SubMatrix}
4789 in the \texttt{\textbackslash CodeAfter} (and the \texttt{\textbackslash CodeBefore})}
4790
4791 \label{SubMatrix}
4792 \label{sub-matrix}
4793 \index{SubMatrix@\texttt{\textbackslash SubMatrix} (command of
4794 \texttt{\textbackslash CodeAfter}\newline and
4795 \texttt{\textbackslash CodeBefore})|textbf}
4796
4797
4798 The command \DefinitionCommand{SubMatrix} provides a way to put delimiters on a portion
4799 of the array considered as a submatrix. The command |\SubMatrix| takes in five
4800 arguments:
4801 \begin{itemize}
4802 \item the first argument is the left delimiter, which may be any extensible delimiter
4803 provided by LaTeX : |(|, |[|, |\{|, |\langle|, |\lgroup|, |\lfloor|, etc. but also
4804 the null delimiter |.|;
4805 \item the second argument is the upper-left corner of the submatrix with the
4806 syntax $i$|-|$j$ where $i$ the number of row and $j$ the number of column (the
4807 special word~|last| is allowed);
4808 \item the third argument is the lower-right corner with the same syntax;
4809 \item the fourth argument is the right delimiter;
4810 \item the last argument, which is optional, is a list of \textsl{key=value}
4811 pairs.\footnote{There is no optional argument between square brackets in first
4812 position because a square bracket just after |\SubMatrix| must be interpreted
4813 as the first (mandatory) argument of the command |\SubMatrix|: that bracket is
4814 the left delimiter of the sub-matrix to construct (eg.:
4815 |\SubMatrix[{2-2}{4-7}]|).}
4816 \end{itemize}
4817
4818 One should remark that the command |\SubMatrix| draws the delimiters \emph{after} the
4819 construction of the array: no space is inserted by the command |\SubMatrix|
4820 itself. That's why, in the following example, we have used the key |margin|
4821 and you have added by hand some space between the third and fourth column with
4822 |@{\hspace{1.5em}}| in the preamble of the array.
4823
4824 \medskip
4825 \begin{Code}[width=15cm]
4826 \[\begin{NiceArray}{ccc\emph{@{\hspace{1.5em}}}c}[cell-space-limits += 2pt,\emph{margin}]
4827 1 & 1 & 1 & x \\
4828 \dfrac{1}{4} & \dfrac{1}{2} & \dfrac{1}{4} & y \\
4829 1 & 2 & 3 & z
4830 \CodeAfter
4831 \emph{\SubMatrix({1-1}{3-3})
4832 \SubMatrix({1-4}{3-4})}
4833 \end{NiceArray}\]
4834 \end{Code}
4835 \hspace{-4cm}
4836 $\begin{NiceArray}{ccc@{\hspace{1.5em}}c}[cell-space-limits += 2pt,margin]
4837 1 & 1 & 1 & x \\
4838 \dfrac{1}{4} & \dfrac{1}{2} & \dfrac{1}{4} & y \\
4839 1 & 2 & 3 & z
4840 \CodeAfter
4841 \SubMatrix({1-1}{3-3})
4842 \SubMatrix({1-4}{3-4})
4843 \end{NiceArray}$
4844
4845 \medskip
4846 Eventually, in this example, it would probably have been easier to put the
4847 delimiters directly in the preamble of |{NiceArray}| (cf.~\ref{delimiters-in-preamble}, p.~\pageref{delimiters-in-preamble})
4848 with the following construction.
4849
4850 \medskip
4851 \begin{scope}
4852 \hfuzz=15cm
4853 \begin{Code}[width=11cm]
4854 $\begin{NiceArray}{\emph{(ccc)(c)}}[cell-space-limits += 2pt]
4855 1 & 1 & 1 & x \\
4856 \dfrac{1}{4} & \dfrac{1}{2} & \dfrac{1}{4} & y \\
4857 1 & 2 & 3 & z
4858 \end{NiceArray}$
4859 \end{Code}
4860 \end{scope}
4861 $\begin{NiceArray}{(ccc)(c)}[cell-space-limits += 2pt]
4862 1 & 1 & 1 & x \\
4863 \dfrac{1}{4} & \dfrac{1}{2} & \dfrac{1}{4} & y \\
4864 1 & 2 & 3 & z
4865 \end{NiceArray}$
4866
4867 \bigskip
4868 In fact, the command |\SubMatrix| also takes in two optional arguments
4869 specified by the traditional symbols |^| and |_| for material in superscript
4870 and subscript (but no space is reserved for that material and that's why, in the
4871 following example, you have used the key |right-margin|).
4872
4873 \medskip
4874 \begin{scope}
4875 \hfuzz=15cm
4876 \begin{Code}[width=11cm]
4877 $\begin{bNiceMatrix}[right-margin=1em]
4878 1 & 1 & 1 \\
4879 1 & a & b \\
4880 1 & c & d
4881 \CodeAfter
4882 \emph{\SubMatrix[{2-2}{3-3}]^{T}}
4883 \end{bNiceMatrix}$
4884 \end{Code}
4885 $\begin{bNiceMatrix}[right-margin=1em]
4886 1 & 1 & 1 \\
4887 1 & a & b \\
4888 1 & c & d
4889 \CodeAfter
4890 \SubMatrix[{2-2}{3-3}]^{T}
4891 \end{bNiceMatrix}$
4892 \end{scope}
4893
4894
4895 \bigskip
4896 The options of the command |\SubMatrix| are as follows:
4897 \begin{itemize}
4898 \item
4899 \index{left-xshift (key of \texttt{\textbackslash SubMatrix})}
4900 \index{right-xshift (key of \texttt{\textbackslash SubMatrix})}
4901 \index{xshift (key of \texttt{\textbackslash SubMatrix})}
4902 \Definition{left-xshift} and \Definition{right-xshift} shift
4903 horizontally the delimiters (there exists also the key \Definition{xshift}
4904 which fixes both parameters);
4905 \item \index{extra-height (key of \texttt{\textbackslash SubMatrix})}
4906 \Definition{extra-height} adds a quantity to the total height of the
4907 delimiters (height |\ht| + depth |\dp|);
4908 \item \index{delimiters!---/color pour \texttt{\textbackslash SubMatrix}}
4909 \Definition{delimiters/color} fixes the color of the delimiters (also
4910 available in |\NiceMatrixOptions|, in the environments with delimiters and as
4911 option of the keyword |\CodeAfter|);
4912 \item \index{slim (key of \texttt{\textbackslash SubMatrix})}
4913 \Definition{slim} is a boolean key: when that key is in force, the horizontal
4914 position of the delimiters is computed by using only the contents of the cells
4915 of the submatrix whereas, in the general case, the position is computed by
4916 taking into account the cells of the whole columns implied in the submatrix
4917 (see example below). ;
4918 \item \index{vlines!key of \texttt{\textbackslash SubMatrix}}
4919 \Definition{vlines} contents a list of numbers of vertical rules that
4920 will be drawn in the sub-matrix (if this key is used without value, all the
4921 vertical rules of the sub-matrix are drawn);
4922 \item \index{hlines!key of \texttt{\textbackslash SubMatrix}}
4923 \Definition{hlines} is similar to |vlines| but for the horizontal rules;
4924 \item \index{hvlines!key of \texttt{\textbackslash SubMatrix}}
4925 \Definition{hvlines}, which must be used without value, draws all the
4926 vertical and horizontal rules;
4927 \item \index{code (key of \texttt{\textbackslash SubMatrix})}
4928 \Definition{code} insert code, especially TikZ code, after the
4929 construction of the submatrix. That key is detailed below.
4930 \end{itemize}
4931 One should remark that the keys add their rules after the construction of
4932 the main matrix: no space is added between the rows and the columns of the
4933 array for these rules.
4934
4935 \bigskip
4936 All these keys are also available in |\NiceMatrixOptions|, at the level of the
4937 environments of \pkg{nicematrix} or as option of the command |\CodeAfter| with
4938 the prefix |sub-matrix| which means that their names are therefore
4939 |sub-matrix/left-xshift|, |sub-matrix/right-xshift|, |sub-matrix/xshift|, etc.
4940
4941 \bigskip
4942
4943 \begin{Code}[width=15cm]
4944 $\begin{NiceArray}{cc@{\hspace{5mm}}l}[cell-space-limits=2pt]
4945 & & \frac{1}{2} \\
4946 & & \frac{1}{4} \\[1mm]
4947 a & b & \frac{1}{2}a+\frac{1}{4}b \\
4948 c & d & \frac{1}{2}c+\frac{1}{4}d \\
4949 \CodeAfter
4950 \SubMatrix({1-3}{2-3})
4951 \SubMatrix({3-1}{4-2})
4952 \SubMatrix({3-3}{4-3})
4953 \end{NiceArray}$
4954 \end{Code}
4955 \hspace{-4cm}
4956 $\begin{NiceArray}{cc@{\hspace{5mm}}l}[cell-space-limits=2pt]
4957 & & \frac12 \\
4958 & & \frac14 \\[1mm]
4959 a & b & \frac12a+\frac14b \\
4960 c & d & \frac12c+\frac14d \\
4961 \CodeAfter
4962 \SubMatrix({1-3}{2-3})
4963 \SubMatrix({3-1}{4-2})
4964 \SubMatrix({3-3}{4-3})
4965 \end{NiceArray}$
4966
4967 \medskip
4968 Here is the same example with the key |slim| used for one of the submatrices.
4969
4970 \medskip
4971 \begin{Code}[width=15cm]
4972 $\begin{NiceArray}{cc@{\hspace{5mm}}l}[cell-space-limits=2pt]
4973 & & \frac12 \\
4974 & & \frac14 \\[1mm]
4975 a & b & \frac12a+\frac14b \\
4976 c & d & \frac12c+\frac14d \\
4977 \CodeAfter
4978 \SubMatrix({1-3}{2-3})[\emph{slim}]
4979 \SubMatrix({3-1}{4-2})
4980 \SubMatrix({3-3}{4-3})
4981 \end{NiceArray}$
4982 \end{Code}
4983 \hspace{-4cm}
4984 $\begin{NiceArray}{cc@{\hspace{5mm}}l}[cell-space-limits=2pt]
4985 & & \frac12 \\
4986 & & \frac14 \\[1mm]
4987 a & b & \frac12a+\frac14b \\
4988 c & d & \frac12c+\frac14d \\
4989 \CodeAfter
4990 \SubMatrix({1-3}{2-3})[slim]
4991 \SubMatrix({3-1}{4-2})
4992 \SubMatrix({3-3}{4-3})
4993 \end{NiceArray}$
4994
4995
4996 \bigskip
4997 There is also a key \Definition{name} which gives a name to the submatrix created by
4998 |\SubMatrix|. That name is used to create PGF/TikZ nodes: cf.~\ref{node-sub-matrix},
4999 p.~\pageref{node-sub-matrix}.
5000
5001
5002 \bigskip
5003 Despite its name, the command |\SubMatrix| may also be used within a
5004 |{NiceTabular}|. Here is an example (which uses |\bottomrule| and
5005 |\toprule| of \pkg{booktabs}).
5006
5007 \medskip
5008 \begin{Code}[width=8.5cm]
5009 \begin{NiceTabular}{@{}ll@{}}
5010 \toprule
5011 Part A & the first part \\
5012 \Block{2-1}{Part B} & a first sub-part \\
5013 & a second sub-part \\
5014 \bottomrule
5015 \CodeAfter
5016 \emph{\SubMatrix{\lbrace}{2-2}{3-2}{.}}
5017 \end{NiceTabular}
5018 \end{Code}
5019 \hspace{15mm}
5020 \begin{NiceTabular}{@{}ll@{}}
5021 \toprule
5022 Part A & the first part \\
5023 \Block{2-1}{Part B} & a first sub-part \\
5024 & a second sub-part \\
5025 \bottomrule
5026 \CodeAfter
5027 \SubMatrix{\lbrace}{2-2}{3-2}{.}
5028 \end{NiceTabular}
5029
5030 \bigskip
5031 The command |\SubMatrix| is, in fact, also available in the |\CodeBefore|. By
5032 using |\SubMatrix| in the |\CodeBefore|, the delimiters drawn by those
5033 commands |\SubMatrix| are taken into account to limit the continuous dotted
5034 lines (drawn by |\Cdots|, |\Vdots|, etc.) which have an open extremity.
5035 For an example, see~\ref{submatrix-in-codebefore},
5036 p.~\pageref{submatrix-in-codebefore}.
5037
5038
5039 \vspace{1cm}
5040 \emph{Caution} : The following functionality is fragile and does not work with
5041 |latex|--|dvips|--|ps2pdf|.
5042
5043 \nobreak
5044 \smallskip
5045 The key \Definition{code} of the command |\SubMatrix| allows the insertion of
5046 code after the construction of the submatrix. It's meant to be used to insert TikZ
5047 instructions because, in the TikZ instructions inserted by that code, the
5048 nodes of the form \texttt{i-j.\textsl{anchor}} or \verb+i-|j+ are interpreted
5049 with |i| and |j| as numbers of row and column \emph{relative to the submatrix}.\footnote{Be
5050 careful: the syntax \verb+j|-i+ is \emph{not} allowed.}
5051
5052 \medskip
5053 \begin{Code}
5054 $\begin{NiceArray}{ccc@{}w{c}{5mm}@{}ccc}
5055 & & && -1 & 1 & 2 \\
5056 & & && 0 & 3 & 4 \\
5057 & & && 0 & 0 & 5 \\
5058 1 & 2 & 3 && -1 & 7 & 25 \\
5059 0 & 4 & 5 && 0 & 12 & 41 \\
5060 0 & 0 & 6 && 0 & 0 & 30
5061 \CodeAfter
5062 \emph{\NewDocumentCommand{\MyDraw}{}{\tikz \draw [blue] (2-|1) -| (3-|2) -| (4-|3) ;}}
5063 \SubMatrix({1-5}{3-7})[\emph{code = \MyDraw} ]
5064 \SubMatrix({4-1}{6-3})[\emph{code = \MyDraw} ]
5065 \SubMatrix({4-5}{6-7})[\emph{code = \MyDraw} ]
5066 \end{NiceArray}$
5067 \end{Code}
5068
5069
5070
5071 \[\begin{NiceArray}{ccc@{}w{c}{5mm}@{}ccc}
5072 & & && -1 & 1 & 2 \\
5073 & & && 0 & 3 & 4 \\
5074 & & && 0 & 0 & 5 \\
5075 1 & 2 & 3 && -1 & 7 & 25 \\
5076 0 & 4 & 5 && 0 & 12 & 41 \\
5077 0 & 0 & 6 && 0 & 0 & 30
5078 \CodeAfter
5079 \NewDocumentCommand{\MyDraw}{}{\tikz \draw [blue] (2-|1) -| (3-|2) -| (4-|3) ;}
5080 \SubMatrix({1-5}{3-7})[code = \MyDraw ]
5081 \SubMatrix({4-1}{6-3})[code = \MyDraw ]
5082 \SubMatrix({4-5}{6-7})[code = \MyDraw ]
5083 \end{NiceArray}\]
5084
5085 \medskip
5086 As we see, the drawing done by our command |\MyDraw| is \emph{relative} to the
5087 submatrix to which it is applied.
5088
5089 \subsection{The commands \texttt{\textbackslash OverBrace} and
5090 \texttt{\textbackslash UnderBrace} in the \texttt{\textbackslash CodeAfter}}
5091
5092
5093 \label{Overbrace}
5094 \label{OverBrace}
5095 \label{UnderBrace}
5096 \index{UncerBrace@\texttt{\textbackslash UnderBrace} (command of
5097 \texttt{\textbackslash CodeAfter}\newline and
5098 \texttt{\textbackslash CodeBefore})}
5099 \index{OverBrace@\texttt{\textbackslash OverBrace} (command of
5100 \texttt{\textbackslash CodeAfter}\newline and
5101 \texttt{\textbackslash CodeBefore})}
5102
5103 The commands \DefinitionCommand{OverBrace} and \DefinitionCommand{UnderBrace}
5104 provide a way to put horizontal braces on a part of the array. These commands
5105 take in three arguments:
5106 \begin{itemize}
5107 \item the first argument is the upper-left corner of the submatrix with the
5108 syntax $i$|-|$j$ where $i$ the number of row and $j$ the number of column;
5109 \item the second argument is the lower-right corner with the same syntax;
5110 \item the third argument is the label of the brace that will be put by
5111 \pkg{nicematrix} (with \textsc{pgf}) above the brace (for the command
5112 |\OverBrace|) or under the brace (for |\UnderBrace|).
5113
5114 It's possible to use the command |\\| in this third argument in order to format
5115 the label on several lines.
5116 \end{itemize}
5117
5118 \bigskip
5119 \begin{Code}[width=9cm]
5120 \begin{pNiceMatrix}
5121 1 & 2 & 3 & 4 & 5 & 6 \\
5122 11 & 12 & 13 & 14 & 15 & 16 \\
5123 \CodeAfter
5124 \emph{\OverBrace{1-1}{2-3}{A}
5125 \OverBrace{1-4}{2-6}{B}}
5126 \end{pNiceMatrix}
5127 \end{Code}
5128 $\begin{pNiceMatrix}
5129 1 & 2 & 3 & 4 & 5 & 6 \\
5130 11 & 12 & 13 & 14 & 15 & 16 \\
5131 \CodeAfter
5132 \OverBrace{1-1}{2-3}{A}
5133 \OverBrace{1-4}{2-6}{B}
5134 \end{pNiceMatrix}$
5135
5136 \bigskip
5137 Caution: There is no vertical space reserved for those braces and their labels.\footnote{See:
5138 \url{https://tex.stackexchange.com/questions/685755}}
5139 \bigskip
5140 \index{color!key of \texttt{\textbackslash OverBrace} and \texttt{\textbackslash
5141 UnderBrace}}
5142 \index{yshift (key of \texttt{\textbackslash OverBrace} and \texttt{\textbackslash
5143 UnderBrace})}
5144 \index{left-shorten (key of \texttt{\textbackslash OverBrace} and\newline \texttt{\textbackslash
5145 UnderBrace})}
5146 \index{right-shorten (key of \texttt{\textbackslash OverBrace} and\newline \texttt{\textbackslash
5147 UnderBrace})}
5148
5149 In fact, the commands |\OverBrace| and |\UnderBrace| take in an optional
5150 argument (in first position and between square brackets) for a list of
5151 \textsl{key=value} pairs. The available keys are:
5152 \begin{itemize}
5153 \item \Definition{left-shorten} and \Definition{right-shorten} which do not take
5154 in value; when the key |left-shorten| is used, the abscissa of the left
5155 extremity of the brace is computed with the contents of the cells of the
5156 involved sub-array, otherwise, the position of the potential vertical rule is
5157 used (idem for |right-shorten|).
5158
5159 \item \Definition{shorten}, which is the conjunction of the keys |left-shorten|
5160 and |right-shorten|;
5161
5162 \item \Definition{yshift}, which shifts vertically the brace (and its label);
5163
5164 \item \Definition{color}, which sets the color of the brace (and its label).
5165 \end{itemize}
5166
5167 \bigskip
5168 \begin{Code}[width=9cm]
5169 \begin{pNiceMatrix}
5170 1 & 2 & 3 & 4 & 5 & 6 \\
5171 11 & 12 & 13 & 14 & 15 & 16 \\
5172 \CodeAfter
5173 \OverBrace[\emph{shorten,yshift=3pt}]{1-1}{2-3}{A}
5174 \OverBrace[\emph{shorten,yshift=3pt}]{1-4}{2-6}{B}
5175 \end{pNiceMatrix}
5176 \end{Code}
5177 $\begin{pNiceMatrix}
5178 1 & 2 & 3 & 4 & 5 & 6 \\
5179 11 & 12 & 13 & 14 & 15 & 16 \\
5180 \CodeAfter
5181 \OverBrace[shorten,yshift=3pt]{1-1}{2-3}{A}
5182 \OverBrace[shorten,yshift=3pt]{1-4}{2-6}{B}
5183 \end{pNiceMatrix}$
5184
5185 \bigskip
5186 $\triangleright$\enskip The commands |\OverBrace| and |\UnderBrace| use the
5187 standard braces of the mathematical mode of LaTeX on which they are based.
5188 However, \pkg{nicematrix} provides also a command |\Hbrace| which should be used
5189 directly in the tabular and which draws braces of TikZ (cf.~\ref{Hbrace},
5190 p.~\pageref{Hbrace}).
5191
5192
5193
5194 \subsection{The command \texttt{\textbackslash TikzEveryCell}}
5195
5196
5197 \index{tikzeverycell@\texttt{\textbackslash TikzEveryCell} (command of
5198 \texttt{\textbackslash CodeAfter}\newline and
5199 \texttt{\textbackslash CodeBefore})|textbf}
5200 \label{TikzEveryCell}
5201 \index{empty (key of \texttt{\textbackslash TikzEveryCell})}
5202 \index{non empty (key of \texttt{\textbackslash TikzEveryCell})}
5203
5204 The command \DefinitionCommand{TikzEveryCell} executes with TikZ the rectangular
5205 path corresponding to each cell of the tabular with parameters of TikZ the
5206 argument of |\TikzEveryCell|. That argument must be a list of \textsl{key=value}
5207 pairs which may be applied to a TikZ path. In fact, the command applies to each cell
5208 of the tabular, except those in the exterior rows and columns
5209 (cf.~\ref{exterior}, p.~\pageref{exterior}) and those in the empty corners (when the key
5210 |corners| is used: cf.~\ref{corners}, p.~\pageref{corners}). It applies in fact to each block
5211 (excepted those with the key |transparent|) and does not apply to the individual
5212 cells located within these blocks.
5213
5214 \medskip
5215 In fact, in the list of keys provided as argument of |\TikzEveryCell|, it's
5216 possible to put a key \Definition{offset}. That key is \emph{not} provided by TikZ but by
5217 \pkg{nicematrix}. It will narrow the rectangular frame corresponding to the
5218 block by a margin (horizontally and vertically) equal to the value (of that key
5219 |offset|). That new frame, a bit narrower, will be executed by TikZ with options
5220 which are the other keys in the argument of |\TikzEveryCell|.
5221
5222 \bigskip
5223 \begingroup
5224 \begin{Code}[width=9cm]
5225 \renewcommand{\arraystretch}{1.3}
5226 \begin{NiceTabular}{ccc}[corners]
5227 & \Block{1-2}{columns} \\
5228 \Block{2-1}{rows}
5229 & cell 1 1 & cell 1 2 \\
5230 & cell 2 1 & cell 2 2
5231 \CodeAfter
5232 \emph{\TikzEveryCell{offset=1pt,draw}}
5233 \end{NiceTabular}
5234 \end{Code}
5235 \renewcommand{\arraystretch}{1.3}
5236 \begin{NiceTabular}{ccc}[corners]
5237 & \Block{1-2}{columns} \\
5238 \Block{2-1}{rows}
5239 & cell 1 1 & cell 1 2 \\
5240 & cell 2 1 & cell 2 2
5241 \CodeAfter
5242 \TikzEveryCell{offset=1pt,draw}
5243 \end{NiceTabular}
5244 \endgroup
5245
5246 \bigskip
5247 The command |\TikzEveryCell| is, in fact, also available in the |\CodeBefore|.
5248
5249 \smallskip
5250 \begingroup
5251 \begin{Code}[width=9cm]
5252 \renewcommand{\arraystretch}{1.3}
5253 \begin{NiceTabular}{ccc}[corners]
5254 \CodeBefore
5255 \emph{\TikzEveryCell
5256 {
5257 offset=1pt,
5258 fill=blue!15,
5259 rounded corners=2pt
5260 }}
5261 \Body
5262 & \Block{1-2}{columns} \\
5263 \Block{2-1}{rows}
5264 & cell 1 1 & cell 1 2 \\
5265 & cell 2 1 & cell 2 2
5266 \end{NiceTabular}
5267 \end{Code}
5268 \renewcommand{\arraystretch}{1.3}
5269 \begin{NiceTabular}{ccc}[corners]
5270 \CodeBefore
5271 \TikzEveryCell{offset=1pt,fill=blue!15,rounded corners=2pt}
5272 \Body
5273 & \Block{1-2}{columns} \\
5274 \Block{2-1}{rows}
5275 & cell 1 1 & cell 1 2 \\
5276 & cell 2 1 & cell 2 2
5277 \end{NiceTabular}
5278 \endgroup
5279
5280
5281 \bigskip
5282 The command |\TikzEveryCell| has two optional keys, available between square brackets.
5283 \begin{itemize}
5284 \item with the key \Definition{empty}, the command only acts on the empty cells
5285 (the exact definition of an ``empty cell'' is given in part~\ref{empty-cells},
5286 p.~\pageref{empty-cells});
5287
5288 \item with the key \Definition{not-empty}, the command only acts on the not-empty cells.
5289 \end{itemize}
5290
5291 \medskip
5292 \begin{Code}[width=9cm]
5293 \renewcommand{\arraystretch}{1.4}
5294 \begin{NiceTabular}{cccccc}[hvlines]
5295 P & O & U & R & V & U \\
5296 O & & & E & I & \\
5297 M & O & R & F & A & L \\
5298 E & T & A & L & & E \\
5299 L & A & S & E & R & S \\
5300 O & & E & X & I & T
5301 \CodeAfter
5302 \emph{\TikzEveryCell[empty]{fill=gray,draw}}
5303 \end{NiceTabular}
5304 \end{Code}
5305 \begin{scope}
5306 \renewcommand{\arraystretch}{1.4}
5307 \begin{NiceTabular}{cccccc}[hvlines]
5308 P & O & U & R & V & U \\
5309 O & & & E & I & \\
5310 M & O & R & F & A & L \\
5311 E & T & A & L & & E \\
5312 L & A & S & E & R & S \\
5313 O & & E & X & I & T
5314 \CodeAfter
5315 \TikzEveryCell[empty]{fill=gray,draw}
5316 \end{NiceTabular}
5317 \end{scope}
5318
5319
5320 \bigskip
5321 \bigskip
5322 \begin{Code}[width=9cm]
5323 \begin{NiceTabular}{cccc}
5324 1 & 2 \\
5325 1 & 2 & 3 \\
5326 1 & 3 \\
5327 1 \\
5328 1 & 2 & 3 & 4 \\
5329 \CodeAfter
5330 \emph{\TikzEveryCell[not-empty]{draw}}
5331 \end{NiceTabular}
5332 \end{Code}
5333 \begin{NiceTabular}{cccc}
5334 1 & 2 \\
5335 1 & 2 & 3 \\
5336 1 & 3 \\
5337 1 \\
5338 1 & 2 & 3 & 4 \\
5339 \CodeAfter
5340 \TikzEveryCell[not-empty]{draw}
5341 \end{NiceTabular}
5342
5343
5344 \index{CodeAfter@\texttt{\textbackslash CodeAfter}|)}
5345
5346 \section{Captions and notes in the tabulars}
5347
5348 \label{s:notes}
5349
5350 \subsection{Caption of a tabular}
5351
5352 \label{s:caption}
5353
5354 \index{caption (key of \texttt{\{NiceTabular\}})}
5355 \index{short-caption}
5356 \index{label (key of \texttt{\{NiceTabular\}})}
5357 \index{caption-above}
5358 \index{caption@\textbf{Captions of the tabulars}}
5359
5360 \smallskip
5361 The environment |{NiceTabular}| provides the keys \Definition{caption},
5362 \Definition{short-caption} and \Definition{label} which may be used when the
5363 tabular is inserted in a floating environment (typically the environment |{table}|).
5364
5365 \smallskip
5366 With the key |caption|, the caption, when it is long, is wrapped at the width of
5367 the tabular (except the potential exterior columns specified by |first-col|
5368 and |last-col|: cf.~\ref{exterior}, p.~\pageref{exterior}), without the use of
5369 the package \pkg{threeparttable} or the package \pkg{floatrow}.
5370
5371 \smallskip
5372 By default, the caption is composed below the tabular. With the key
5373 \Definition{caption-above}, available in |\NiceMatrixOptions|, the caption will
5374 be composed above the tabular (that key is not available for an individual environment).
5375
5376 \smallskip
5377 The key |short-caption| corresponds to the optional argument of the classical
5378 command |\caption| and the key |label| corresponds, of course, to the command
5379 |\label|.
5380
5381 \smallskip
5382 See table \ref{t:tabularnote}, p.~\pageref{t:tabularnote}, for an example of
5383 use the keys |caption| and |label|.
5384
5385 \smallskip
5386 These functionalities are compatible with the extension \pkg{caption}. For example, it's
5387 possible to use the tuning
5388 |\captionsetup{justification=raggedright,singlelinecheck=false}| in order to have
5389 left-align captions, even when the caption is shorter than the tabular.
5390
5391 \subsection{The footnotes}
5392
5393 \index{footnote@\pkg{footnote} (package)}
5394 \index{footnote (key)}
5395 \index{footnotehyper@\pkg{footnotehyper} (package)}
5396 \index{footnotehyper (key)}
5397
5398 \smallskip
5399 The package \pkg{nicematrix} allows, by using \pkg{footnote} or
5400 \pkg{footnotehyper}, the extraction of the notes inserted by |\footnote| in the
5401 environments of \pkg{nicematrix} and their composition in the foot of the page
5402 with the other notes of the document.
5403
5404 \smallskip
5405 If \pkg{nicematrix} is loaded with the option |footnote| (with
5406 |\usepackage[footnote]{nicematrix}| or with |\PassOptionsToPackage|), the
5407 package \pkg{footnote} is loaded (if it is not yet loaded) and it is used to
5408 extract the footnotes.
5409
5410 \smallskip
5411 If \pkg{nicematrix} is loaded with the option |footnotehyper|, the package
5412 \pkg{footnotehyper} is loaded (if it is not yet loaded) ant it is used to
5413 extract footnotes.
5414
5415 \smallskip
5416 Caution: The packages \pkg{footnote} and \pkg{footnotehyper} are incompatible.
5417 The package \pkg{footnotehyper} is the successor of the package \pkg{footnote}
5418 and should be used preferently. The package \pkg{footnote} has some drawbacks,
5419 in particular: it must be loaded after the package \pkg{xcolor} and it is not
5420 perfectly compatible with \pkg{hyperref}.
5421
5422
5423 \subsection{The notes of tabular}
5424
5425 \index{nota@\textbf{Notes in the tabulars}|(}
5426 \index{tabularnote@\texttt{\textbackslash tabularnote}}
5427
5428 The package \pkg{nicematrix} also provides a command
5429 \DefinitionCommand{tabularnote} which gives the ability to specify notes that
5430 will be composed at the end of the array with a width of text equal to the width
5431 of the array (except the potential exterior columns specified by |first-col| and
5432 |last-col|: cf.~\ref{exterior}, p.~\pageref{exterior}). With no surprise, that
5433 command is available only in the environments |{NiceTabular}|, |{NiceTabular*}|
5434 and |{NiceTabularX}|.
5435
5436 In fact, this command is available only if the extension \pkg{enumitem}
5437 \index{enumitem@\pkg{enumitem} (package required to use\newline \texttt{\textbackslash tabularnote})} has
5438 been loaded (before or after \pkg{nicematrix}). Indeed, the notes are composed
5439 at the end of the array with a type of list provided by the package
5440 \pkg{enumitem}. If \pkg{enumitem} has not been loaded, an error will be raised.
5441
5442
5443 \medskip
5444 \begin{Code}
5445 \begin{NiceTabular}{@{}llr@{}}
5446 \toprule \RowStyle{\bfseries}
5447 Last name & First name & Birth day \\
5448 \midrule
5449 Achard\emph{\tabularnote{Achard is an old family of the Poitou.}}
5450 & Jacques & June 5, 2005 \\
5451 Lefebvre\emph{\tabularnote{The name Lefebvre is an alteration of the name Lefebure.}}
5452 & Mathilde & January 23, 1975 \\
5453 Vanesse & Stephany & October 30, 1994 \\
5454 Dupont & Chantal & January 15, 1998 \\
5455 \bottomrule
5456 \end{NiceTabular}
5457 \end{Code}
5458
5459
5460 \begin{center}
5461 \begin{NiceTabular}{@{}llr@{}}[no-cell-nodes]
5462 \toprule \RowStyle{\bfseries}
5463 Last name & First name & Birth day \\
5464 \midrule
5465 Achard\tabularnote{Achard is an old family of the Poitou.}
5466 & Jacques & June 5, 2005 \\
5467 Lefebvre\tabularnote{The name Lefebvre is an alteration of the name Lefebure.}
5468 & Mathilde & January 23, 1975 \\
5469 Vanesse & Stephany & October 30, 1994 \\
5470 Dupont & Chantal & January 15, 1998 \\
5471 \bottomrule
5472 \end{NiceTabular}
5473 \end{center}
5474
5475
5476 \bigskip
5477 \begin{itemize}
5478 \item If you have several successive commands |\tabularnote{...}| \emph{with no
5479 space at all between them}, the labels of the corresponding notes are composed
5480 together, separated by commas (this is similar to the option |multiple| of
5481 \pkg{footmisc} for the footnotes).
5482
5483 \item If a command |\tabularnote{...}| is exactly at the end of a cell (with no
5484 space at all after) and if the alignment mode of the column is |c| or |r|, the
5485 label of the note is composed in an overlapping position (towards the right).
5486 This structure may provide a better alignment of the cells of a given column.
5487
5488 \item If the key \Definition{notes/para} is used, the notes are composed at the
5489 end of the array in a single paragraph (as with the key |para| of
5490 \pkg{threeparttable}).
5491
5492 \item \index{tabularnote (key of \texttt{\{NiceTabular\}})}
5493 There is a key \Definition{tabularnote} which provides a way to insert some text
5494 in the zone of the notes before the numbered tabular notes.
5495
5496 \index{tabularnote@\texttt{\{TabularNote\}}}
5497 An alternative syntax is available with the environment |{TabularNote}|. That
5498 environment should be used at the end of the environment |{NiceTabular}| (but
5499 \emph{before} a potential instruction |\CodeAfter|).
5500
5501 \item If the package \pkg{booktabs} has been loaded (before or after
5502 \pkg{nicematrix}), the key \Definition{notes/bottomrule} draws a |\bottomrule|
5503 of \pkg{booktabs} \emph{after} the notes.
5504
5505 \item The command |\tabularnote| may be used \emph{before}
5506 the environment of \pkg{nicematrix}. Thus, it's possible to use it on the
5507 title inserted by |\caption| in an environment |{table}| of LaTeX (or in a
5508 command |\captionof| of the package \pkg{caption}). It's also possible, as
5509 expected, to use the command |\tabularnote| in the caption provided by the
5510 \emph{key} |caption| of the environment |{NiceTabular}|.
5511
5512 \item If several commands |\tabularnote| are used in a tabular with the same
5513 argument, only one note is inserted at the end of the tabular (but all the
5514 labels are composed, of course). It's possible to control that feature with
5515 the key |notes/detect-duplicates|.\footnote{For technical reasons, the final
5516 user is not allowed to put several commands |\tabularnote| with exactly the
5517 same argument in the caption of the tabular. It's not a real restriction...}
5518
5519 \item It's possible to create a reference to a tabular note created by
5520 |\tabularnote| (with the usual command |\label| used after the |\tabularnote|).
5521
5522 \item The command |\tabularnote| has an optional argument (between square
5523 brackets) to change the symbol of the reference of the note.
5524
5525 \emph{Example}: |\tabularnote[$\star$]{A footnote...}|
5526 \end{itemize}
5527 %
5528 For an illustration of some of those remarks, see table~\ref{t:tabularnote},
5529 p.~\pageref{t:tabularnote}. This table has been composed
5530 with the following code (the package \pkg{caption} has been loaded in this document).
5531
5532 \begin{center}
5533 \small
5534 \begin{Code}
5535 \begin{table}
5536 \centering
5537 \NiceMatrixOptions{caption-above}
5538 \begin{NiceTabular}{@{}llc@{}
5539 [
5540 caption = A tabular whose caption has been specified by the key
5541 \texttt{caption}\emph{\tabularnote[$\star$]{It's possible to put a tabular
5542 note in the caption.}} ,
5543 label = t:tabularnote ,
5544 tabularnote = Some text before the notes. ,
5545 notes/bottomrule
5546 ]
5547 \toprule
5548 Last name & First name & Length of life \\
5549 \midrule
5550 Churchill & Wiston & 91\\
5551 Nightingale\emph{\tabularnote{Considered as the first nurse of history}}%
5552 \emph{\tabularnote{Nicknamed ``the Lady with the Lamp''.}}
5553 & Florence\emph{\tabularnote{This note is shared by two references.}} & 90 \\
5554 Schoelcher & Victor & 89\emph{\tabularnote{The label of the note is overlapping.}}\\
5555 Touchet & Marie\emph{\tabularnote{This note is shared by two references.}} & 89 \\
5556 Wallis & John & 87 \\
5557 \bottomrule
5558 \end{NiceTabular}
5559 \end{table}
5560 \end{Code}
5561 \end{center}
5562
5563
5564 \begin{table}[hbt]
5565 \centering
5566 \NiceMatrixOptions{caption-above}
5567 \begin{NiceTabular}{@{}llc@{}}[
5568 caption = A tabular whose caption has been specified by the key
5569 \texttt{caption}\tabularnote[$\star$]{It's possible to put a tabular
5570 note in the caption} ,
5571 label = t:tabularnote ,
5572 tabularnote = Some text before the notes. ,
5573 notes/bottomrule ,
5574 no-cell-nodes
5575 ]
5576 \toprule
5577 Last name & First name & Length of life \\
5578 \midrule
5579 Churchill & Wiston & 91\\
5580 Nightingale\tabularnote{Considered as the first nurse of
5581 history.}\tabularnote{Nicknamed ``the Lady with the Lamp''.}
5582 & Florence\tabularnote{This note is shared by two references.} & 90 \\
5583 Schoelcher & Victor & 89\tabularnote{The label of the note is overlapping.}\\
5584 Touchet & Marie\tabularnote{This note is shared by two references.} & 89 \\
5585 Wallis & John & 87 \\
5586 \bottomrule
5587 \end{NiceTabular}
5588 \end{table}
5589
5590
5591 \subsection{Customisation of the tabular notes}
5592
5593 \index{para (subkey of ``notes'')}
5594 \index{bottomrule (subkey of ``notes'')}
5595 \index{style (subkey of ``notes'')}
5596 \index{label-in-tabular (subkey of ``notes'')}
5597 \index{label-in-list (subkey of ``notes'')}
5598 \index{enumitem-keys (subkey of ``notes'')}
5599 \index{enumitem-keys-para (subkey of ``notes'')}
5600 \index{code-before!subkey of ``notes''}
5601 \index{detect-duplicates (subkey of ``notes'')}
5602 \index{no-print (subkey of ``notes'')}
5603
5604
5605 The tabular notes can be customized with a set of keys available in
5606 |\NiceMatrixOptions|. The name of these keys is prefixed by |notes|.f
5607 \begin{itemize}[beginpenalty=10000]
5608 \item |notes/para|
5609 \item |notes/bottomrule|
5610 \item |notes/style|
5611 \item |notes/label-in-tabular|
5612 \item |notes/label-in-list|
5613 \item |notes/enumitem-keys|
5614 \item |notes/enumitem-keys-para|
5615 \item |notes/code-before|
5616 \item |notes/no-print|
5617 \end{itemize}
5618 For sake of commodity, it is also possible to set these keys in
5619 |\NiceMatrixOptions| via a key |notes| which takes in as value a list of
5620 pairs \textsl{key=value} where the name of the keys need no longer be
5621 prefixed by |notes|:
5622 \begin{center}
5623 \small
5624 \begin{BVerbatim}
5625 \NiceMatrixOptions
5626 {
5627 notes =
5628 {
5629 bottomrule ,
5630 style = ... ,
5631 label-in-tabular = ... ,
5632 enumitem-keys =
5633 {
5634 labelsep = ... ,
5635 align = ... ,
5636 ...
5637 }
5638 }
5639 }
5640 \end{BVerbatim}
5641 \end{center}
5642
5643
5644 \bigskip
5645 We detail these keys.
5646
5647 \begin{itemize}[itemsep=\medskipamount,beginpenalty=10000]
5648 \item The key \Definition{notes/para} requires the composition of the notes (at
5649 the end of the tabular) in a single paragraph.
5650
5651 Initial value: |false|
5652
5653 That key is also available within a given environment.
5654
5655 \item The key \Definition{notes/bottomrule} adds a |\bottomrule| of \pkg{booktabs}
5656 \emph{after} the notes. Of course, that rule is drawn only if there actually are
5657 notes in the tabular. The package \pkg{booktabs} must have been loaded (before
5658 or after the package \pkg{nicematrix}). If it is not, an error is raised.
5659
5660 Initial value: |false|
5661
5662 That key is also available within a given environment.
5663
5664 \item The key \Definition{notes/style} is a command whose argument is specified
5665 by |#1| and which gives the style of numerotation of the notes. That style will
5666 be used by |\ref| when referencing a tabular note marked with a command |\label|.
5667 The labels formatted by that style are used, separated by commas, when the user
5668 puts several consecutive commands |\tabularnote|. The marker |#1| is meant to
5669 be the name of a LaTeX counter.
5670
5671 Initial value: |\textit{\alph{#1}}|
5672
5673 Another possible value should be a mere |\arabic{#1}|
5674
5675 \item The key \Definition{notes/label-in-tabular} is a command whose argument is
5676 specified by |#1| which is used when formatting the label of a note in the
5677 tabular. Internally, this number of note has already been formatted by
5678 |notes/style| before sent to that command.
5679
5680 Initial value: |\textsuperscript{#1}|
5681
5682 In French, it's a tradition of putting a small space before the label of note.
5683 That tuning could be achieved by the following code:
5684 %
5685 \begin{Verbatim}
5686 \NiceMatrixOptions{notes/label-in-tabular = \,\textsuperscript{~#1}}
5687 \end{Verbatim}
5688
5689
5690 \item The key \Definition{notes/label-in-list} is a command whose argument is
5691 specified by |#1| which is used when formatting the label in the list of notes
5692 at the end of the tabular. Internally, this number of note has already been
5693 formatted by |notes/style| before sent to that command.
5694
5695 Initial value: |\textsuperscript{#1}|
5696
5697 In French, the labels of notes are not composed in upper position when
5698 composing the notes. Such behaviour could be achieved by:
5699 \begin{Verbatim}
5700 \NiceMatrixOptions{notes/label-in-list = ~#1.\nobreak\hspace{0.25em}}
5701 \end{Verbatim}
5702 The command |\nobreak| is for the event that the option |para| is used.
5703
5704
5705 \item The notes are composed at the end of the tabular by using internally a
5706 style of list of \pkg{enumitem}. This style of list is defined as follows (with, of
5707 course, keys of \pkg{enumitem}):
5708
5709 |noitemsep , leftmargin = * , align = left , labelsep = 0pt|
5710
5711 The specification |align = left| in that style requires a
5712 composition of the label leftwards in the box affected to that label.
5713 With that tuning, the notes are composed flush left, which is pleasant when
5714 composing tabulars in the spirit of \pkg{booktabs} (see for example the
5715 table~\ref{t:tabularnote}, p.~\pageref{t:tabularnote}).
5716
5717 \medskip
5718 The key \Definition{notes/enumitem-keys} specifies a list of pairs
5719 \textsl{key=value} (following the specifications of \pkg{enumitem}) to
5720 customize that style of list (it uses internally the command |\setlist*| of
5721 \pkg{enumitem}).
5722
5723
5724 \item The key \Definition{notes/enumitem-keys-para} is similar to the previous
5725 one but corresponds to the type of list used when the option |para| is in force.
5726 Of course, when the option |para| is used, a list of type |inline| (as called by
5727 \pkg{enumitem}) is used and the pairs \textsl{key=value} should correspond to
5728 such a list of type |inline|.
5729
5730 Initially, the style of list is defined by:\quad
5731 |afterlabel = \nobreak, itemjoin = \quad|
5732
5733
5734 \item The key \Definition{notes/code-before}$^+$ is a token list inserted by
5735 \pkg{nicematrix} just before the composition of the notes at the end of the tabular.
5736
5737 Initial value: \textsl{empty}
5738
5739 For example, if one wishes to compose all the notes in gray and |\footnotesize|,
5740 he should use that key:
5741 \begin{Verbatim}
5742 \NiceMatrixOptions{notes/code-before = \footnotesize \color{gray}}
5743 \end{Verbatim}
5744 It's also possible to add |\raggedright| or |\RaggedRight| in that key (|\RaggedRight|
5745 is a command of \pkg{ragged2e}).
5746
5747 The key |nodes/code-before| has a normal syntax, but also an ``additive syntax'',
5748 which means that it's possible to write, for example
5749 |notes/code-before += \footnotesize|. With that syntax, the tokens are appended
5750 on the \emph{right} of the current value of the parameter |notes/code-before|.
5751
5752 \item The key \Definition{notes/detect-duplicates} activates the detection of
5753 the commands |\tabularnotes| with the same argument.
5754
5755 Initial value: |true|
5756
5757 \item \indexcommand{NiceTabularNotes}
5758 When the key \Definition{notes/no-print} is in force, the notes are \emph{not} composed
5759 by \pkg{nicematrix} under the tabular. However, the final user may use the
5760 command \DefinitionCommand{NiceTabularNotes} in order to insert these notes where he wishes
5761 (after the composition of the tabular).
5762
5763 Initial value: |false|
5764 \end{itemize}
5765
5766 \index{nota@\textbf{Notes in the tabulars}|)}
5767
5768 \bigskip
5769 For an example of customisation of the tabular notes,
5770 see~\ref{ex:notes}, p.~\pageref{ex:notes}.
5771
5772
5773 \section{Other features}
5774
5775
5776 \subsection{Trees}
5777
5778 \index{draw-trees-in-col}
5779 \index{trees (plusieurs sous-clés)}
5780
5781
5782 \colorbox{yellow!50}{\textbf{New 7.8}}
5783
5784 \nobreak
5785 \smallskip
5786
5787 The key \Definition{draw-trees-in-col} takes in as argument a list of
5788 numbers of columns and, in each of those columns, will draw a tree
5789 in the style the trees drawn by the packages \pkg{dirtree} and \pkg{dirtreex}.
5790
5791 \medskip
5792 \begin{Verbatim}[formatcom=\footnotesize \color{gray}]
5793 \usepackage{booktabs} % in the preamble
5794 \end{Verbatim}
5795
5796 \begin{Code}
5797 \renewcommand{\arraystretch}{1.3}
5798 \begin{NiceTabular}{w{l}{2.5mm}w{l}{2.5mm}lr}[\emph{draw-trees-in-col=1-2}]
5799 \toprule
5800 Category &&& \% \\
5801 \midrule
5802 Animal &&& 100 \\
5803 & Human && 50 \\
5804 && Man & 20 \\
5805 && Woman & 30 \\
5806 & Fox && 30 \\
5807 && Vixen & 16 \\
5808 && Dog & 14 \\
5809 & Chicken && 20 \\
5810 && Cock & 8 \\
5811 && Hen & 12 \\
5812 \bottomrule
5813 \end{NiceTabular}
5814 \end{Code}
5815
5816 \begin{center}
5817 \renewcommand{\arraystretch}{1.3}
5818 \begin{NiceTabular}{w{l}{2.5mm}w{l}{2.5mm}lr}[draw-trees-in-col=1-2]
5819 \toprule
5820 Category &&& \% \\
5821 \midrule
5822 Animal &&& 100 \\
5823 & Human && 50 \\
5824 && Man & 20 \\
5825 && Woman & 30 \\
5826 & Fox && 30 \\
5827 && Vixen & 16 \\
5828 && Dog & 14 \\
5829 & Chicken && 20 \\
5830 && Cock & 8 \\
5831 && Hen & 12 \\
5832 \bottomrule
5833 \end{NiceTabular}
5834 \end{center}
5835
5836
5837 \bigskip
5838 Three keys \Definition{trees/line-width}, \Definition{trees/color} and
5839 \Definition{trees/rounded-corners} are provided for the customization of those rules
5840 (the prefix |trees| may be factorized).
5841
5842 \medskip
5843 \begin{Code}
5844 \renewcommand{\arraystretch}{1.3}
5845 \NiceMatrixOptions{\emph{trees= {line-width = 0.4pt, color = red , rounded-corners}}}
5846 \begin{NiceTabular}{w{l}{2.5mm}w{l}{2.5mm}lr}[\emph{draw-trees-in-col=1-2}]
5847 \toprule
5848 Category &&& \% \\
5849 \midrule
5850 Animal &&& 100 \\
5851 & Human && 50 \\
5852 && Man & 20 \\
5853 && Woman & 30 \\
5854 & Fox && 30 \\
5855 && Vixen & 16 \\
5856 && Dog & 14 \\
5857 & Chicken && 20 \\
5858 && Cock & 8 \\
5859 && Hen & 12 \\
5860 \bottomrule
5861 \end{NiceTabular}
5862 \end{Code}
5863
5864 \begin{center}
5865 \renewcommand{\arraystretch}{1.3}
5866 \NiceMatrixOptions{trees= {line-width = 0.4pt, color = red , rounded-corners}}
5867 \begin{NiceTabular}{w{l}{2.5mm}w{l}{2.5mm}lr}[draw-trees-in-col=1-2]
5868 \toprule
5869 \RowStyle{\bfseries}
5870 Category &&& \% \\
5871 \midrule
5872 Animal &&& 100 \\
5873 & Human && 50 \\
5874 && Man & 20 \\
5875 && Woman & 30 \\
5876 & Fox && 30 \\
5877 && Vixen & 16 \\
5878 && Dog & 14 \\
5879 & Chicken && 20 \\
5880 && Cock & 8 \\
5881 && Hen & 12 \\
5882 \bottomrule
5883 \end{NiceTabular}
5884 \end{center}
5885
5886
5887 \subsection{The key rounded-corners of the environments}
5888
5889 \label{tabular-rounded-corners}
5890 \index{rounded-corners!key of \texttt{\{NiceTabular\}}}
5891 \index{Corners (rounded ---)!for a tabular}
5892
5893 The key |rounded-corners| that we will describe now has no direct link with
5894 the key |corners| (which is used to specify ``empty corners'') described in
5895 the part~\ref{corners}, p.~\pageref{corners}. On the other side, it is similar with the
5896 key |rounded-corners| of the command |\Block|
5897 (cf.~\ref{block-rounded-corners},~\pageref{block-rounded-corners}).
5898
5899 \smallskip
5900 The key \Definition{rounded-corners} specifies that the tabular should have
5901 rounded corners with a radius equal to the value of that key (the default value is
5902 4~pt\footnote{This value is the initial value of the \emph{rounded corners} of
5903 TikZ.}). More precisely, that key has two effects that we describe now.
5904 \begin{itemize}
5905 \item All the commands for coloring the cells, columns and rows (in the
5906 |\CodeBefore| but also directly in the array) will respect those rounded corners.
5907
5908 \item When the key |hvlines| is used, the exterior rules will be drawn with
5909 rounded corners.\footnote{Of course, when used in an environment with delimiters
5910 (|{pNiceMatrix}|, |{bNiceArray}|, etc.), the key |hvlines| does not draw the
5911 exterior rules.}
5912 \end{itemize}
5913
5914
5915 That key is available in all the environments and commands (e.g.
5916 |\pAutoNiceMatrix|) of \pkg{nicematrix} and also in the command
5917 |\NiceMatrixOptions|.
5918
5919 \bigskip
5920 \begin{Code}[width=9cm]
5921 \begin{NiceTabular}
5922 [hvlines,\emph{rounded-corners}]
5923 {ccc}
5924 \CodeBefore
5925 \rowcolor{red!15}{1}
5926 \Body
5927 Last name & First name & Profession \\
5928 Arvy & Jacques & Physicist \\
5929 Jalon & Amandine & Physicist
5930 \end{NiceTabular}
5931 \end{Code}
5932 \begin{NiceTabular}{ccc}[hvlines,rounded-corners,no-cell-nodes]
5933 \CodeBefore
5934 \rowcolor{red!15}{1}
5935 \Body
5936 Last name & First name & Profession \\
5937 Arvy & Jacques & Physicist \\
5938 Jalon & Amandine & Physicist
5939 \end{NiceTabular}
5940
5941
5942 \subsection{The command \texttt{\textbackslash ShowCellNames}}
5943
5944 \index{ShowCellNames@\texttt{\textbackslash ShowCellNames} (command of
5945 \texttt{\textbackslash CodeAfter}\newline and
5946 \texttt{\textbackslash CodeBefore})}
5947
5948
5949 The command \DefinitionCommand{ShowCellNames}, which may be used in the
5950 |\CodeBefore| and in the |\CodeAfter| displays the name (with the form $i$-$j$)
5951 of each cell. It is provided as a tool which may be helpul during the conception of
5952 a table.
5953
5954 \medskip
5955 When it is used in the |\CodeBefore|, the names are drawn after the colored backgrounds
5956 (but before the contents of the cells).
5957
5958 \medskip
5959 \begin{Code}[width=10.6cm]
5960 \begin{NiceTabular}{ccc}[hvlines,cell-space-limits=3pt]
5961 \CodeBefore
5962 \emph{\ShowCellNames}
5963 \rowcolor{gray!15}{3}
5964 \Body
5965 \Block{2-2}{} & & test \\
5966 & & blah blah \\
5967 & some text & nothing
5968 \end{NiceTabular}
5969 \end{Code}
5970 \begin{NiceTabular}{ccc}[hvlines,cell-space-limits=3pt,no-cell-nodes]
5971 \CodeBefore
5972 \ShowCellNames
5973 \rowcolor{gray!15}{3}
5974 \Body
5975 \Block{2-2}{} & & test \\
5976 & & blah blah \\
5977 & some text & nothing
5978 \end{NiceTabular}
5979
5980 \bigskip
5981 When used in the |\CodeAfter|, that command applies a semi-transparent white
5982 rectangle to fade the array (caution: some \textsc{pdf} readers don't support
5983 transparency) and, then, the names of the cells are drawn above.
5984
5985 \medskip
5986 \begin{Code}[width=10.6cm]
5987 \begin{NiceTabular}{ccc}[hvlines,cell-space-limits=3pt]
5988 \CodeBefore
5989 \rowcolor{gray!15}{3}
5990 \Body
5991 \Block{2-2}{} & & test \\
5992 & & blah blah \\
5993 & some text & nothing
5994 \CodeAfter \emph{\ShowCellNames}
5995 \end{NiceTabular}
5996 \end{Code}
5997 \begin{NiceTabular}{ccc}[hvlines,cell-space-limits=3pt,no-cell-nodes]
5998 \CodeBefore
5999 \rowcolor{gray!15}{3}
6000 \Body
6001 \Block{2-2}{} & & test \\
6002 & & blah blah \\
6003 & some text & nothing
6004 \CodeAfter \ShowCellNames
6005 \end{NiceTabular}
6006
6007
6008
6009
6010 \subsection{Use of the column type S of \texorpdfstring{\pkg{siunitx}}{siunitx}}
6011
6012 \index{S (the columns S of \pkg{siunitx})}
6013 \index{siunitx@\pkg{siunitx} (package)}
6014
6015 If the package \pkg{siunitx} is loaded (before or after \pkg{nicematrix}),
6016 it's possible to use the |S| column type of \pkg{siunitx} in the environments
6017 of \pkg{nicematrix}.
6018
6019
6020
6021 \medskip
6022 \begin{Code}[width = 11cm]
6023 $\begin{pNiceArray}{\emph{S}cW{c}{1cm}c}[xdots/nullify,first-row]
6024 {C_1} & \Cdots & & C_n \\
6025 2.3 & 0 & \Cdots & 0 \\
6026 12.4 & \Vdots & & \Vdots \\
6027 1.45 \\
6028 7.2 & 0 & \Cdots & 0
6029 \end{pNiceArray}$
6030 \end{Code}
6031 $\begin{pNiceArray}{ScW{c}{1cm}c}[xdots/nullify,first-row]
6032 {C_1} & \Cdots & & C_n \\
6033 2.3 & 0 & \Cdots & 0 \\
6034 12.4 & \Vdots & & \Vdots \\
6035 1.45 \\
6036 7.2 & 0 & \Cdots & 0
6037 \end{pNiceArray}$
6038
6039 \medskip
6040 On the other hand, the |d| columns of the package \pkg{dcolumn} are not
6041 supported by \pkg{nicematrix}.
6042
6043
6044 \subsection{Default column type in \texttt{\{NiceMatrix\}}}
6045
6046 \label{columns-width}
6047 \index{columns-type (key of \texttt{\{NiceMatrix\}}, etc.)}
6048
6049 The environments without preamble (|{NiceMatrix}|, |{pNiceMatrix}|,
6050 |{bNiceMatrix}|, etc.) and the commande |\pAutoNiceMatrix| (and its variants)
6051 provide an option \Definition{columns-type} to specify the type of column which
6052 will be used (the initial value is, of course, |c|).
6053
6054 The keys \Definition{l} and \Definition{r} are shortcuts for |columns-type=l|
6055 and |columns-type=r|.
6056
6057
6058 \medskip
6059 \begin{Code}[width=10cm]
6060 $\begin{bNiceMatrix}\emph{[r]}
6061 \cos x & - \sin x \\
6062 \sin x & \cos x
6063 \end{bNiceMatrix}$
6064 \end{Code}
6065 $\begin{bNiceMatrix}[r,no-cell-nodes]
6066 \cos x & - \sin x \\
6067 \sin x & \cos x
6068 \end{bNiceMatrix}$
6069
6070 \medskip
6071 The key |columns-type| is available in |\NiceMatrixOptions| but with the
6072 prefix |matrix|, which means that its name is, within |\NiceMatrixOptions| :
6073 |matrix/columns-type|.
6074
6075 \subsection{The command \texttt{\textbackslash rotate}}
6076
6077 \label{rotate}
6078 \index{rotate@\texttt{\textbackslash rotate}}
6079
6080 The package \pkg{nicematrix} provides a command \DefinitionCommand{rotate}. When
6081 used in the beginning of a cell, this command composes the contents of the cell
6082 after a rotation of 90° in the direct sens.
6083
6084 In the following command, we use that command in the
6085 |code-for-first-row|.\footnote{It can also be used in |\RowStyle|
6086 (cf.~\ref{RowStyle}, p.~\pageref{RowStyle}).}
6087
6088 \bigskip
6089
6090 \begin{Code}[width=12cm]
6091 \NiceMatrixOptions
6092 {
6093 code-for-first-row = \scriptstyle \emph{\rotate} \text{image of },
6094 code-for-last-col = \scriptstyle
6095 }
6096 $A = \begin{pNiceMatrix}[first-row,last-col=4]
6097 e_1 & e_2 & e_3 \\
6098 1 & 2 & 3 & e_1 \\
6099 4 & 5 & 6 & e_2 \\
6100 7 & 8 & 9 & e_3
6101 \end{pNiceMatrix}$
6102 \end{Code}
6103 \begin{varwidth}{10cm}
6104 \NiceMatrixOptions
6105 {
6106 code-for-first-row = \scriptstyle\rotate \text{image of },
6107 code-for-last-col = \scriptstyle
6108 }
6109 $ A = \begin{pNiceMatrix}[first-row,last-col=4,no-cell-nodes]
6110 e_1 & e_2 & e_3 \\
6111 1 & 2 & 3 & e_1 \\
6112 4 & 5 & 6 & e_2 \\
6113 7 & 8 & 9 & e_3
6114 \end{pNiceMatrix}$
6115 \end{varwidth}
6116
6117 \bigskip
6118 If the command |\rotate| is used in the ``last row'' (exterior to the matrix),
6119 the corresponding elements are aligned upwards as shown below.
6120
6121 \bigskip
6122 \index{first-row|textit}
6123 \index{last-row|textit}
6124 \index{code-for-first-row|textit}
6125 \index{code-for-last-row|textit}
6126 \index{last-col|textit}
6127 \index{code-for-last-col|textit}
6128
6129 \begin{Code}[width=12cm]
6130 \NiceMatrixOptions
6131 {
6132 code-for-last-row = \scriptstyle \emph{\rotate} ,
6133 code-for-last-col = \scriptstyle
6134 }
6135 $A = \begin{pNiceMatrix}[last-row=4,last-col=4]
6136 1 & 2 & 3 & e_1 \\
6137 4 & 5 & 6 & e_2 \\
6138 7 & 8 & 9 & e_3 \\
6139 \text{image of } e_1 & e_2 & e_3
6140 \end{pNiceMatrix}$
6141 \end{Code}
6142 \begin{varwidth}{10cm}
6143 \NiceMatrixOptions
6144 {
6145 code-for-last-row = \scriptstyle\rotate ,
6146 code-for-last-col = \scriptstyle
6147 }
6148 $A = \begin{pNiceMatrix}[last-row=4,last-col=4,no-cell-nodes]
6149 1 & 2 & 3 & e_1 \\
6150 4 & 5 & 6 & e_2 \\
6151 7 & 8 & 9 & e_3 \\
6152 \text{image of } e_1 & e_2 & e_3
6153 \end{pNiceMatrix}$
6154 \end{varwidth}
6155
6156 \bigskip
6157 The command |\rotate| has a key |c|: |\rotate[c]| (spaces are deleted after
6158 |\rotate[c]|). When that key is used, the content is composed in a |\vcenter|
6159 and, therefore, in most cases, we will have a vertical alignment.
6160
6161 \medskip
6162 The command |\rotate| also supports a key called \Definition{-90}. With that key,
6163 the content is rotated by an angle of $-90$° and not $90$°.
6164
6165 \bigskip
6166 \emph{Caution: } the command |\rotate| is designed to be used in a |\Block| or in
6167 columns of type |l|, |r|, |c|, |w| or |W|; if it is used in other column types
6168 (such as |p{...}|), the result will maybe differ from what is expected. In that case,
6169 it will be valuable to consider the command |\rotatebox| of the package \pkg{graphicx}
6170 (that package is loaded by \pkg{nicematrix}).
6171
6172 \subsection{The key small}
6173
6174 \label{small}
6175 \index{small (key for an environment)}
6176 \index{smallmatrix@\texttt{\{smallmatrix\}} (environment of \pkg{amsmath})}
6177
6178
6179 With the option \Definition{small}, the environments of the package
6180 \pkg{nicematrix} are composed in a way similar to the environment
6181 |{smallmatrix}| of the package \pkg{amsmath} (and the environments
6182 |{psmallmatrix}|, |{bsmallmatrix}|, etc. of the package \pkg{mathtools}).
6183
6184 \bigskip
6185 \begin{Code}
6186 $\begin{bNiceArray}{cccc|c}[\emph{small},
6187 last-col ,
6188 code-for-last-col = \scriptscriptstyle,
6189 columns-width = 3mm ]
6190 1 & -2 & 3 & 4 & 5 \\
6191 0 & 3 & 2 & 1 & 2 & L_2 \gets 2 L_1 - L_2 \\
6192 0 & 1 & 1 & 2 & 3 & L_3 \gets L_1 + L_3
6193 \end{bNiceArray}$
6194 \end{Code}
6195 %
6196 \[\begin{bNiceArray}{cccc|c}%
6197 [
6198 small,
6199 last-col ,
6200 code-for-last-col = \scriptscriptstyle,
6201 columns-width=3mm,
6202 no-cell-nodes
6203 ]
6204 1 & -2 & 3 & 4 & 5 \\
6205 0 & 3 & 2 & 1 & 2 & L_2 \gets 2 L_1 - L_2 \\
6206 0 & 1 & 1 & 2 & 3 & L_3 \gets L_1 + L_3
6207 \end{bNiceArray}\]
6208
6209
6210 \bigskip
6211 One should note that the environment |{NiceMatrix}| with the option |small| is
6212 not composed \emph{exactly} as the environment |{smallmatrix}|. Indeed, all
6213 the environments of \pkg{nicematrix} are constructed upon |{array}| (of the
6214 package \pkg{array}) whereas the environment |{smallmatrix}| is constructed
6215 directly with an |\halign| of TeX.
6216
6217 \medskip
6218 In fact, the option |small| corresponds to the following tuning:
6219 \begin{itemize}
6220 \item the cells of the array are composed with |\scriptstyle|;
6221 \item |\arraystretch| is set to $0.47$;
6222 \item |\arraycolsep| is set to $1.45$~pt;
6223 \item the characteristics of the dotted lines are also modified.
6224 \end{itemize}
6225
6226 \medskip
6227 When the key |small| is in force, some functionalities of \pkg{nicematrix} are
6228 no longer available: for example, it's no longer possible to put vertical
6229 delimiters directly in the preamble of an environment with preamble
6230 (cf.~\ref{delimiters-in-preamble}, p.~\pageref{delimiters-in-preamble}).
6231
6232
6233 \subsection{\texttt{\textbackslash AutoNiceMatrix} and the counters iRow and jCol}
6234
6235 \label{iRow}
6236 \index{iRow (LaTeX counter)}
6237 \index{jCol (LaTeX counter)}
6238
6239 In the cells of the array, it's possible to use the LaTeX counters \Definition{iRow} and
6240 \Definition{jCol}\footnote{These counters are actual LaTeX counters: the underlying TeX
6241 counters are |\c@iRow| and |\c@jCol|} which represent the number of the
6242 current row and the number of the current column. We recall that the exterior
6243 ``first row'' (if it exists) has the number~$0$ and that the exterior ``first
6244 column'' (if it exists) has also the number~$0$. Of course, the user must not
6245 change the value of these counters |iRow| and |jCol| which are used internally
6246 by \pkg{nicematrix}.
6247
6248 In the |\CodeBefore| (cf.~\ref{code-before}, p.~\pageref{code-before}) and in the |\CodeAfter|
6249 (cf.~\ref{code-after}, p.~\pageref{code-after}), |iRow| represents the total number of
6250 rows (except the potential exterior rows: cf.~\ref{exterior}, p.~\pageref{exterior})
6251 and |jCol| represents the total number of columns (except the potential exterior columns).
6252
6253 \medskip
6254 \begin{Code}[width=10.6cm]
6255 $\begin{pNiceMatrix}% don’t forget the %
6256 [first-row,
6257 first-col,
6258 code-for-first-row = \mathbf{\emph{\alph{jCol}}} ,
6259 code-for-first-col = \mathbf{\emph{\arabic{iRow}}} ]
6260 & & & & \\
6261 & 1 & 2 & 3 & 4 \\
6262 & 5 & 6 & 7 & 8 \\
6263 & 9 & 10 & 11 & 12
6264 \end{pNiceMatrix}$
6265 \end{Code}
6266 $\begin{pNiceMatrix}[first-row,
6267 first-col,
6268 code-for-first-row = \mathbf{\alph{jCol}} ,
6269 code-for-first-col = \mathbf{\arabic{iRow}} ,
6270 no-cell-nodes]
6271 & & & & \\
6272 & 1 & 2 & 3 & 4 \\
6273 & 5 & 6 & 7 & 8 \\
6274 & 9 & 10 & 11 & 12
6275 \end{pNiceMatrix}$
6276
6277 \medskip
6278 If LaTeX counters called |iRow| and |jCol| are defined in the document by
6279 packages other than \pkg{nicematrix} (or by the final user), they are shadowed
6280 in the environments of \pkg{nicematrix}.
6281
6282 \bigskip
6283 \indexcommand{AutoNiceMatrix}
6284 \indexcommand{pAutoNiceMatrix}
6285 \indexcommand{bAutoNiceMatrix}
6286 \indexcommand{vAutoNiceMatrix}
6287 \indexcommand{VAutoNiceMatrix}
6288 \indexcommand{BAutoNiceMatrix}
6289 The package \pkg{nicematrix} also provides commands in order to compose
6290 automatically matrices from a general pattern. These commands are
6291 \DefinitionCommand{AutoNiceMatrix}, \DefinitionCommand{pAutoNiceMatrix},
6292 \DefinitionCommand{bAutoNiceMatrix}, \DefinitionCommand{vAutoNiceMatrix},
6293 \DefinitionCommand{VAutoNiceMatrix} et \DefinitionCommand{BAutoNiceMatrix}.
6294
6295 These commands take in two mandatory arguments. The first is the format of the
6296 matrix, with the syntax $n$-$p$ where $n$ is the number of rows and $p$ the
6297 number of columns. The second argument is the pattern (it's a list of tokens
6298 which are inserted in each cell of the constructed matrix).
6299
6300 \medskip
6301 \begin{Code}
6302 $C = \emph{\pAutoNiceMatrix}{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$
6303 \end{Code}
6304
6305
6306 \[C = \pAutoNiceMatrix{3-3}{C_{\arabic{iRow},\arabic{jCol}}}\]
6307
6308 There exists also \DefinitionCommand{AutoNiceArrayWithDelims} similar to
6309 |{NiceArrayWithDelims}|.
6310
6311
6312 \subsection{The key light-syntax}
6313
6314 \label{light-syntax}
6315 \index{light-syntax}
6316
6317 The option \Definition{light-syntax} (inpired by the package \pkg{spalign})
6318 allows the user to compose the arrays with a lighter syntax, which gives a
6319 better legibility of the TeX source.
6320
6321 When this option is used, one should use the semicolon for the end of a row
6322 and spaces or tabulations to separate the columns. However, as usual in the
6323 TeX world, the spaces after a control sequence are discarded and the elements
6324 between curly braces are considered as a whole.
6325
6326
6327 \medskip
6328 \begin{Code}[width=10cm]
6329 $\begin{bNiceMatrix}[\emph{light-syntax},first-row,first-col]
6330 {} a b ;
6331 a 2\cos a {\cos a + \cos b} ;
6332 b \cos a+\cos b { 2 \cos b }
6333 \end{bNiceMatrix}$
6334 \end{Code}
6335 $\begin{bNiceMatrix}[light-syntax,first-row,first-col,no-cell-nodes]
6336 {} a b ;
6337 a 2\cos a {\cos a + \cos b} ;
6338 b \cos a+\cos b { 2 \cos b }
6339 \end{bNiceMatrix}$
6340
6341 \medskip
6342 \index{end-of-row (to be used with light-syntax)}
6343 It's possible to change the character used to mark the end of rows with the
6344 option \Definition{end-of-row}. As said before, the initial value is a semicolon.
6345
6346 \medskip
6347 When the option |light-syntax| is used, it is not possible to put verbatim
6348 material (for example with the command \texttt{\textbackslash verb}) in the cells of the
6349 array.\footnote{The reason is that, when the option |light-syntax| is used,
6350 the whole content of the environment is loaded as a TeX argument to be
6351 analyzed. The environment doesn't behave in that case as a standard
6352 environment of LaTeX which only put TeX commands before and after the content.}
6353
6354 \medskip
6355 \index{light-syntax-expanded}
6356
6357 The key \Definition{light-syntax-expanded} has the same behaviour as the key
6358 |light-syntax| but the body of the environment is expanded (in the TeX
6359 sense\footnote{More precisely, it's an expansion of type |e| of L3.}) before being
6360 split in rows (but after the extraction of a potential |\CodeAfter|).
6361
6362
6363 \subsection{Color of the delimiters}
6364
6365 \index{delimiters!---/color for an environment}
6366 \index{color!for the delimiters of the matrices}
6367 \index{Colour!of the delimiters of the matrices}
6368
6369
6370 For the environments with delimiters (|{pNiceArray}|, |{pNiceMatrix}|, etc.),
6371 it's possible to change the color of the delimiters with the key
6372 \Definition{delimiters/color}.
6373
6374 \medskip
6375 \begin{Code}[width=12cm]
6376 $\begin{bNiceMatrix}[delimiters/color=red]
6377 1 & 2 \\
6378 3 & 4
6379 \end{bNiceMatrix}$
6380 \end{Code}
6381 $\begin{bNiceMatrix}[delimiters/color=red]
6382 1 & 2 \\
6383 3 & 4
6384 \end{bNiceMatrix}$
6385
6386 \medskip
6387 This color also applies to the delimiters drawn by the command |\SubMatrix|
6388 (cf.~\ref{sub-matrix}, p.~\pageref{sub-matrix}) and for the delimiters directly specified in the
6389 preamble of the environments with preamble (cf.~\ref{delimiters-in-preamble},
6390 p.~\pageref{delimiters-in-preamble}).
6391
6392 \subsection{The environment \texttt{\{NiceArrayWithDelims\}}}
6393
6394 \label{NiceArrayWithDelims}
6395 \index{NiceArrayWithDelims@\texttt{\{NiceArrayWithDelims\}}}
6396
6397 In fact, the environment |{pNiceArray}| and its variants are based upon a
6398 more general environment, called \Definition{\{NiceArrayWithDelims\}}. The first
6399 two mandatory arguments of this environment are the left and right delimiters
6400 used in the construction of the matrix.
6401
6402 It's possible to use |{NiceArrayWithDelims}| if we want to use atypical or
6403 asymmetrical delimiters.
6404
6405 \medskip
6406 \begin{Code}[width=11cm]
6407 $\begin{\emph{NiceArrayWithDelims}}
6408 {\downarrow}{\uparrow}{ccc}[margin]
6409 1 & 2 & 3 \\
6410 4 & 5 & 6 \\
6411 7 & 8 & 9
6412 \end{\emph{NiceArrayWithDelims}}$
6413 \end{Code}
6414 $\begin{NiceArrayWithDelims}
6415 {\downarrow}{\uparrow}{ccc}[margin,no-cell-nodes]
6416 1 & 2 & 3 \\
6417 4 & 5 & 6 \\
6418 7 & 8 & 9
6419 \end{NiceArrayWithDelims}$
6420
6421 \subsection{The command \texttt{\textbackslash OnlyMainNiceMatrix}}
6422
6423 \indexcommand{OnlyMainNiceMatrix}
6424
6425 The command \DefinitionCommand{OnlyMainNiceMatrix} executes its argument only
6426 when it is in the main part of the array, that is to say when it is not in one
6427 of the exterior rows or one of the exterior columns. If it is used outside an
6428 environment of \pkg{nicematrix}, that command is no-op.
6429
6430 For an example of use, see \url{tex.stackexchange.com/questions/488566}
6431
6432 \section{Use of TikZ with nicematrix}
6433
6434 \label{name}
6435 \label{PGF-nodes}
6436 \index{tikza@TikZ (use with \pkg{nicematrix})}
6437 \index{node@\textbf{Nodes of PGF/TikZ}|(}
6438
6439 \subsection{The nodes corresponding to the contents of the cells}
6440
6441 \index{no-cell-nodes}
6442 \label{no-cell-nodes}
6443
6444 The package \pkg{nicematrix} creates a PGF/TikZ node\footnote{We recall that TikZ
6445 is a layer over PGF. The extension \pkg{nicematrix} loads PGF but does not
6446 load TikZ. We speak of PGF/TikZ nodes to emphase the fact that the PGF nodes
6447 created by \pkg{nicematrix} may be used with PGF but also with TikZ. The final
6448 user will probably prefer to use TikZ rather than PGF.} for the \textbf{content} of each (non-empty) cell of the array. These nodes are
6449 used to draw the dotted lines between the cells of the matrix (inter alia).
6450
6451 \smallskip
6452 By default, those nodes are not available in the |\CodeBefore| (in order to speed up
6453 compilations). In order to be able to use those nodes in the |\CodeBefore|, one must
6454 use the key |create-cell-nodes| of the keyword |\CodeBefore|.
6455
6456
6457 \smallskip
6458 \textbf{Caution} : By default, no node is created in an empty cell.
6459
6460 \smallskip
6461 However, it's possible to impose the creation of a node with the command
6462 |\NotEmpty|. \footnote{One should note that, with that command, the cell is
6463 considered as non-empty, which has consequencies for the continuous dotted
6464 lines (cf.~\ref{Cdots}, p.~\pageref{Cdots}) and the computation of the ``corners''
6465 (cf.~\ref{corners}, p.~\pageref{corners}).}
6466
6467 \medskip
6468 The creation of those nodes needs time and memory. It's possible to desactive
6469 ponctually the creation of those nodes with the key \Definition{no-cell-nodes}
6470 in order to speed up the compilations. But be careful: those nodes are used
6471 internally but \pkg{nicematrix} for several features. One should use the key
6472 |no-cell-nodes| only when those feateures are not used. Among these are the key
6473 |corners| and the commands for the continuous dotted lines (|\Cdots|, etc.).
6474
6475 \medskip
6476 The nodes of a document must have distinct names. That's why the names of the
6477 nodes created by \pkg{nicematrix} contains the number of the current
6478 environment. Indeed, the environments of \pkg{nicematrix} are numbered by a
6479 internal global counter.
6480
6481 \smallskip
6482 In the environment with the number $n$, the node of the row $i$ and
6483 column~$j$ has for name |nm-|$n$|-|$i$|-|$j$.
6484
6485 \smallskip
6486 The command \DefinitionCommand{NiceMatrixLastEnv} provides the number of the
6487 last environment of \pkg{nicematrix} (for LaTeX, it's a ``fully expandable''
6488 command and not a counter).
6489
6490 \smallskip
6491 \index{name!key for an environment}
6492 However, it's advisable to use instead the key \Definition{name}\footnote{The value of the
6493 key |name| is \emph{expanded} (in the TeX sens).}. This key
6494 gives a name to the current environment. When the environment has a name, the
6495 nodes are accessible with the name ``\textsl{name}-$i$-$j$'' where \textsl{name}
6496 is the name given to the array and $i$ and $j$ the numbers of row and column.
6497 It's possible to use these nodes with \textsc{pgf} but the final user will
6498 probably prefer to use TikZ (which is a convenient layer upon \textsc{pgf}).
6499 However, one should remind that \pkg{nicematrix} doesn't load TikZ by default.
6500 In the following examples, we assume that TikZ has been loaded.
6501
6502 \bigskip
6503 \begin{Code}[width=11cm]
6504 $\begin{pNiceMatrix}[name=\emph{mymatrix}]
6505 1 & 2 & 3 \\
6506 4 & 5 & 6 \\
6507 7 & 8 & 9
6508 \end{pNiceMatrix}$
6509 \tikz[remember picture,overlay]
6510 \draw \emph{(mymatrix-2-2)} circle (2mm) ;
6511 \end{Code}
6512 $\begin{pNiceMatrix}[name=mymatrix]
6513 1 & 2 & 3 \\
6514 4 & 5 & 6 \\
6515 7 & 8 & 9
6516 \end{pNiceMatrix}$
6517 \tikz[remember picture,overlay]
6518 \draw (mymatrix-2-2) circle (2mm) ;
6519
6520 \medskip
6521 Don't forget the options |remember picture| and |overlay|.
6522
6523 \bigskip
6524 In the |\CodeAfter|, the things are easier : one must refer to the nodes with
6525 the form $i$-$j$ (we don't have to indicate the environment which is of
6526 course the current environment).
6527
6528
6529 \medskip
6530 \begin{Code}[width=11cm]
6531 $\begin{pNiceMatrix}
6532 1 & 2 & 3 \\
6533 4 & 5 & 6 \\
6534 7 & 8 & 9
6535 \CodeAfter
6536 \tikz \draw \emph{(2-2)} circle (2mm) ;
6537 \end{pNiceMatrix}$
6538 \end{Code}
6539 $\begin{pNiceMatrix}
6540 1 & 2 & 3 \\
6541 4 & 5 & 6 \\
6542 7 & 8 & 9
6543 \CodeAfter
6544 \tikz \draw (2-2) circle (2mm) ;
6545 \end{pNiceMatrix}$
6546
6547 \medskip
6548 The nodes of the last column (except the potential ``last column'' specified
6549 by |last-col|\footnote{For the exterior columns, cf.~\ref{exterior}, p.~\pageref{exterior}.})
6550 may also be indicated by $i$-|last|. Similarly, the nodes of the last row
6551 may be indicated by |last|-$j$.
6552
6553 \bigskip
6554 In the following example, we have stroken all the nodes of the matrix.
6555
6556 \[
6557 \NiceMatrixOptions
6558 {
6559 pgf-node-code =
6560 {
6561 \pgfsetstrokecolor{red}%
6562 \pgfusepathqstroke
6563 }
6564 }
6565 \begin{pNiceMatrix}
6566 a & a + b & a + b + c \\
6567 a & a & a + b \\
6568 a & a & a
6569 \end{pNiceMatrix}\]
6570
6571
6572 \bigskip
6573 Since those nodes are PGF nodes, one won't be surprised to learn that they are
6574 drawn by using a specific PGF style. That style is called |nicematrix/cell-node|
6575 and its definition in the source file |nicematrix.sty| is as follows:
6576
6577 \begin{Code}[annotation = false]
6578 \pgfset
6579 {
6580 \emph{nicematrix / cell-node} /.style =
6581 {
6582 inner sep = 0 pt ,
6583 minimum width = 0 pt
6584 }
6585 }
6586 \end{Code}
6587
6588 The final user may modify that style by changing the values of the keys |text/rotate|,
6589 |inner xsep|, |inner ysep|, |inner sep|, |outer xsep|, |outer ysep|, |outer sep|,
6590 |minimum width|, |minimum height| and |minimum size|.
6591
6592 \medskip
6593 For an example of use, see part~\ref{triangular}, p.~\pageref{triangular}.
6594
6595
6596 \subsubsection{The key pgf-node-code}
6597
6598 \index{pgf-node-code}
6599
6600 \textbf{For the experienced users}, \pkg{nicematrix} provides the key
6601 \Definition{pgf-node-code} which corresponds to some PGF node that will be
6602 executed at the creation, by PGF, of the nodes corresponding to the cells of the
6603 array. More pricisely, the value given to the key |pgf-node-code| will be passed
6604 in the fifth argument of the command |\pgfnode|. That value should contain at
6605 least an instruction such as |\pgfusepath|, |\pgfusepathqstroke|, |\pgfusepathqfill|,
6606 etc.
6607
6608 \subsubsection{The columns V of varwidth}
6609
6610 \label{node-V}
6611 \index{V (the columns V of \pkg{varwidth})}
6612 \index{varwidth@\pkg{varwidth} (package)}
6613
6614 When the extension \pkg{varwidth} is loaded, the columns of the type |V|
6615 defined by \pkg{varwidth} are supported by \pkg{nicematrix}. It may be
6616 interessant to notice that, for a cell of a column of type |V|, the PGF/TikZ
6617 node created by \pkg{nicematrix} for the content of that cell has a width
6618 adjusted to the content of the cell. This is in contrast to the case of the
6619 columns of type |p|, |m| or |b| for which the nodes have always a width equal
6620 to the width of the column. In the following example, the command |\lipsum| is
6621 provided by the eponymous package.
6622
6623 \begin{Verbatim}
6624 \begin{NiceTabular}{V{10cm}}
6625 \bfseries \large
6626 Titre \\
6627 \lipsum[1][1-4]
6628 \CodeAfter
6629 \tikz \draw [rounded corners] (1-1) -| (last-|2) -- (last-|1) |- (1-1) ;
6630 \end{NiceTabular}
6631 \end{Verbatim}
6632
6633
6634 \begin{center}
6635 \begin{NiceTabular}{V{10cm}}
6636 \bfseries \large
6637 Titre \\
6638 \lipsum[1][1-4]
6639 \CodeAfter
6640 \tikz \draw [rounded corners] (1-1) -| (last-|2) -- (last-|1) |- (1-1) ;
6641 \end{NiceTabular}
6642 \end{center}
6643
6644 We have used the nodes corresponding to the position of the potential rules,
6645 which are described below (cf.~\ref{nodes-i}, p.~\pageref{nodes-i}).
6646
6647 Of course, there are dedicated packages to such constructions (for example \pkg{tcolorbox}).
6648
6649
6650 \subsection[The medium nodes and the large nodes]{The ``medium nodes'' and the ``large nodes''}
6651
6652 \index{create-medium-nodes}
6653 \index{create-large-nodes}
6654 \index{create-extra-nodes}
6655
6656 In fact, the package \pkg{nicematrix} can create ``extra nodes'': the ``medium
6657 nodes'' and the ``large nodes''. The first ones
6658 are created with the option \Definition{create-medium-nodes} and the second ones with the
6659 option \Definition{create-large-nodes}.\footnote{There is also an option
6660 |create-extra-nodes| which is an alias for the conjunction of
6661 |create-medium-nodes| and |create-large-nodes|.}
6662
6663 \medskip
6664 These nodes are not used by \pkg{nicematrix} by default, and that's why they
6665 are not created by default.
6666
6667 \medskip
6668 The names of the ``medium nodes'' are constructed by adding the suffix
6669 ``|-medium|'' to the names of the ``normal nodes''. In the following example,
6670 we have underlined the ``medium nodes''. We consider that this example is
6671 self-explanatory.
6672 \[\begin{pNiceMatrix}[create-medium-nodes]
6673 \CodeBefore [create-cell-nodes]
6674 \begin{tikzpicture}
6675 [every node/.style = {fill = red!15, inner sep = 0 pt},
6676 name suffix = -medium]
6677 \node [fit = (1-1)] {} ;
6678 \node [fit = (1-2)] {} ;
6679 \node [fit = (1-3)] {} ;
6680 \node [fit = (2-1)] {} ;
6681 \node [fit = (2-2)] {} ;
6682 \node [fit = (2-3)] {} ;
6683 \node [fit = (3-1)] {} ;
6684 \node [fit = (3-2)] {} ;
6685 \node [fit = (3-3)] {} ;
6686 \end{tikzpicture}
6687 \Body
6688 a & a + b & a + b + c \\
6689 a & a & a + b \\
6690 a & a & a
6691 \end{pNiceMatrix}\]
6692
6693
6694 \medskip
6695 \index{left-margin}
6696 \index{right-margin}
6697 The names of the ``large nodes'' are constructed by adding the suffix
6698 ``|-large|'' to the names of the ``normal nodes''. In the following example,
6699 we have underlined the ``large nodes''. We consider that this example is
6700 self-explanatory.\footnote{There is no ``large nodes'' created in the exterior
6701 rows and columns (for these rows and columns, cf.~\ref{exterior}, p.~\pageref{exterior}).}
6702 \[\begin{pNiceMatrix}[create-large-nodes]
6703 \CodeBefore [create-cell-nodes]
6704 \begin{tikzpicture}
6705 [every node/.style = { inner sep = 0 pt} ,
6706 name suffix = -large]
6707 \node [fit = (1-1),fill = red!15] {} ;
6708 \node [fit = (1-3),fill = red!15] {} ;
6709 \node [fit = (2-2),fill = red!15] {} ;
6710 \node [fit = (3-1),fill = red!15] {} ;
6711 \node [fit = (3-3),fill = red!15] {} ;
6712 \node [fit = (1-2),fill = blue!15] {} ;
6713 \node [fit = (2-1),fill = blue!15] {} ;
6714 \node [fit = (2-3),fill = blue!15] {} ;
6715 \node [fit = (3-2),fill = blue!15] {} ;
6716 \end{tikzpicture}
6717 \Body
6718 a & a + b & a + b + c \\
6719 a & a & a + b \\
6720 a & a & a
6721 \end{pNiceMatrix}\]
6722
6723
6724
6725 \medskip
6726 \index{extra-left-margin}
6727 \index{extra-right-margin}
6728 The ``large nodes'' of the first column and last column may appear too small
6729 for some usage. That's why it's possible to use the options \Definition{left-margin} and
6730 \Definition{right-margin} to add space on both sides of the array and also space in the
6731 ``large nodes'' of the first column and last column. In the following example,
6732 we have used the options |left-margin| and |right-margin|.\footnote{The
6733 options |left-margin| and |right-margin| take dimensions as values but, if no
6734 value is given, the default value is used, which is |\arraycolsep| (by
6735 default: 5~pt). There is also an option \Definition{margin} to fix both |left-margin| and
6736 |right-margin| to the same value.}
6737 \[\begin{pNiceMatrix}[create-large-nodes,left-margin,right-margin]
6738 \CodeBefore [create-cell-nodes]
6739 \begin{tikzpicture}
6740 [every node/.style = {inner sep = 0 pt},
6741 name suffix = -large]
6742 \node [fit = (1-1),fill = red!15] {} ;
6743 \node [fit = (1-3),fill = red!15] {} ;
6744 \node [fit = (2-2),fill = red!15] {} ;
6745 \node [fit = (3-1),fill = red!15] {} ;
6746 \node [fit = (3-3),fill = red!15] {} ;
6747 \node [fit = (1-2),fill = blue!15] {} ;
6748 \node [fit = (2-1),fill = blue!15] {} ;
6749 \node [fit = (2-3),fill = blue!15] {} ;
6750 \node [fit = (3-2),fill = blue!15] {} ;
6751 \end{tikzpicture}
6752 \Body
6753 a & a + b & a + b + c \\
6754 a & a & a + b \\
6755 a & a & a
6756 \end{pNiceMatrix}\]
6757
6758
6759 \medskip
6760 It's also possible to add more space on both side of the array with the
6761 options \Definition{extra-left-margin} and \Definition{extra-right-margin}.
6762 These margins are not incorporated in the ``large nodes''. It's possible to fix
6763 both values with the option \Definition{extra-margin} and, in the following
6764 example, we use |extra-margin| with the value $3$~pt.
6765 \[\begin{pNiceMatrix}[create-large-nodes,left-margin,right-margin,extra-right-margin=3pt,extra-left-margin=3pt]
6766 \CodeBefore [create-cell-nodes]
6767 \begin{tikzpicture}
6768 [every node/.style = {inner sep = 0 pt},
6769 name suffix = -large]
6770 \node [fit = (1-1),fill = red!15] {} ;
6771 \node [fit = (1-3),fill = red!15] {} ;
6772 \node [fit = (2-2),fill = red!15] {} ;
6773 \node [fit = (3-1),fill = red!15] {} ;
6774 \node [fit = (3-3),fill = red!15] {} ;
6775 \node [fit = (1-2),fill = blue!15] {} ;
6776 \node [fit = (2-1),fill = blue!15] {} ;
6777 \node [fit = (2-3),fill = blue!15] {} ;
6778 \node [fit = (3-2),fill = blue!15] {} ;
6779 \end{tikzpicture}
6780 \Body
6781 a & a + b & a + b + c \\
6782 a & a & a + b \\
6783 a & a & a
6784 \end{pNiceMatrix}\]
6785
6786
6787
6788 \bigskip
6789 \textbf{Be careful} : These nodes are reconstructed from the contents of the
6790 contents cells of the array. Usually, they do not correspond to the cells
6791 delimited by the rules (if we consider that these rules are drawn).
6792
6793 \bigskip
6794 \begin{minipage}[c]{7.6cm}
6795 Here is an array composed with the following code:
6796
6797 \medskip
6798 \begin{BVerbatim}
6799 \large
6800 \begin{NiceTabular}{wl{2cm}ll}[hvlines]
6801 fraise & amande & abricot \\
6802 prune & pêche & poire \\[1ex]
6803 noix & noisette & brugnon
6804 \end{NiceTabular}
6805 \end{BVerbatim}
6806 \end{minipage}
6807 \hspace{0.9cm}
6808 \begin{scope}
6809 \large
6810 \begin{NiceTabular}[c]{wl{2cm}ll}[hvlines]
6811 fraise & amande & abricot \\
6812 prune & pêche & poire \\[1ex]
6813 noix & noisette & brugnon
6814 \end{NiceTabular}
6815 \end{scope}
6816
6817 \vspace{1cm}
6818 \begin{minipage}[c]{7cm}
6819 Here, we have colored all the cells of the array with |\chessboardcolors|.
6820 \end{minipage}
6821 \hspace{1.5cm}
6822 \begin{scope}
6823 \large
6824 \begin{NiceTabular}[c]{wl{2cm}ll}[hvlines,code-before = \chessboardcolors{red!15}{blue!15}]
6825 fraise & amande & abricot \\
6826 prune & pêche & poire \\[1ex]
6827 noix & noisette & brugnon
6828 \end{NiceTabular}
6829 \end{scope}
6830
6831
6832 \vspace{1cm}
6833 \begin{minipage}[c]{7cm}
6834 Here are the ``large nodes'' of this array (without use of |margin|
6835 nor |extra-margin|).
6836 \end{minipage}
6837 \hspace{1.5cm}
6838 \begin{scope}
6839 \large
6840 \begin{NiceTabular}[c]{w{l}{2cm}ll}[hvlines,create-large-nodes]
6841 \CodeBefore [create-cell-nodes]
6842 \begin{tikzpicture}
6843 [every node/.style = {inner sep = 0 pt},
6844 name suffix = -large]
6845 \node [fit = (1-1),fill = red!15] {} ;
6846 \node [fit = (1-3),fill = red!15] {} ;
6847 \node [fit = (2-2),fill = red!15] {} ;
6848 \node [fit = (3-1),fill = red!15] {} ;
6849 \node [fit = (3-3),fill = red!15] {} ;
6850 \node [fit = (1-2),fill = blue!15] {} ;
6851 \node [fit = (2-1),fill = blue!15] {} ;
6852 \node [fit = (2-3),fill = blue!15] {} ;
6853 \node [fit = (3-2),fill = blue!15] {} ;
6854 \end{tikzpicture}
6855 \Body
6856 fraise & amande & abricot \\
6857 prune & pêche & poire \\[1ex]
6858 noix & noisette & brugnon
6859 \end{NiceTabular}
6860 \end{scope}
6861
6862
6863 \vspace{1cm}
6864 The nodes we have described are not available by default in the |\CodeBefore|
6865 (cf.~\ref{code-before}, p.~\pageref{code-before}).
6866
6867 \nobreak
6868 \index{create-cell-nodes (key of \texttt{\textbackslash CodeBefore})}
6869 It's possible to have these nodes available in the |\CodeBefore| by using the
6870 key \Definition{create-cell-nodes} of the keyword |\CodeBefore| (in that case,
6871 the nodes are created first before the construction of the array by using
6872 information written on the |aux| file and created a second time during the
6873 construction of the array itself; this mechanism is not activated by default for
6874 efficiency reasons).
6875
6876 \bigskip
6877 Here is an example which uses these nodes in the |\CodeAfter|.
6878
6879 \begin{center}
6880 \begin{Code}
6881 \begin{NiceArray}{c@{\;}c@{\;}c@{\;}c@{\;}c}[create-medium-nodes]
6882 u_1 &-& u_0 &=& r \\
6883 u_2 &-& u_1 &=& r \\
6884 u_3 &-& u_2 &=& r \\
6885 u_4 &-& u_3 &=& r \\
6886 \phantom{u_5} & & \phantom{u_4} &\smash{\vdots} & \\
6887 u_n &-& u_{n-1} &=& r \\[3pt]
6888 \hline
6889 u_n &-& u_0 &=& nr \\
6890 \CodeAfter
6891 \tikz[very thick, red, opacity=0.4, name suffix = -medium]
6892 \draw (1-1.north west) -- (2-3.south east)
6893 (2-1.north west) -- (3-3.south east)
6894 (3-1.north west) -- (4-3.south east)
6895 (4-1.north west) -- (5-3.south east)
6896 (5-1.north west) -- (6-3.south east) ;
6897 \end{NiceArray}
6898 \end{Code}
6899 \end{center}
6900
6901 \[\begin{NiceArray}{c@{\;}c@{\;}c@{\;}c@{\;}c}[create-medium-nodes]
6902 u_1 &-& u_0 &=& r \\
6903 u_2 &-& u_1 &=& r \\
6904 u_3 &-& u_2 &=& r \\
6905 u_4 &-& u_3 &=& r \\
6906 \phantom{u_5} & & \phantom{u_4} &\smash{\vdots} & \\
6907 u_n &-& u_{n-1} &=& r \\[3pt]
6908 \hline
6909 u_n &-& u_0 &=& nr \\
6910 \CodeAfter
6911 \tikz[very thick, red, opacity=0.4, name suffix = -medium]
6912 \draw (1-1.north west) -- (2-3.south east)
6913 (2-1.north west) --(3-3.south east)
6914 (3-1.north west) -- (4-3.south east)
6915 (4-1.north west) -- (5-3.south east)
6916 (5-1.north west) -- (6-3.south east) ;
6917 \end{NiceArray}\]
6918
6919
6920
6921 \subsection{The nodes which indicate the position of the rules}
6922
6923 \label{nodes-i}
6924 The package \pkg{nicematrix} creates a PGF/TikZ node merely called $i$ (with
6925 the classical prefix) at the intersection of the horizontal rule of number~$i$
6926 and the vertical rule of number~$i$ (more specifically the potential position
6927 of those rules because maybe there are not actually drawn). The last node has
6928 also an alias called |last|.
6929
6930 \smallskip
6931 There are also nodes called $i$|.1|, $i$|.2|, $i$|.25|, $i$|.3|, $i$|.4|,
6932 $i$|.5|, $i$|.6|, $i$|.7|, $i$|.75|, $i$|.8| and $i$|.9| between the node~$i$
6933 and the node~$i+1$.
6934
6935 \smallskip
6936 These nodes are available in the |\CodeBefore| and the |\CodeAfter|.
6937
6938 \begin{center}
6939 \begin{NiceTabular}{ccc}[hvlines,rules/width=1pt,rules/color=gray]
6940 & tulipe & lys \\
6941 arum & & violette mauve \\
6942 muguet & dahlia
6943 \CodeAfter
6944 \tiny
6945 \begin{tikzpicture}
6946 \foreach \i in {1,1.5,2,2.5,3,3.5,4}
6947 {
6948 \fill [red] (\i) circle (0.5mm) ;
6949 \node [red,above right] at (\i) {\i} ;
6950 }
6951 \end{tikzpicture}
6952 \end{NiceTabular}
6953 \end{center}
6954
6955 \bigskip
6956 If we use TikZ (we remind that \pkg{nicematrix} does not load TikZ by default,
6957 by only \textsc{pgf}, which is a sub-layer of TikZ), we can access, in the
6958 |\CodeAfter| but also in the |\CodeBefore|, to the intersection of the
6959 (potential) horizontal rule~$i$ and the (potential) vertical rule~$j$ with the
6960 syntax |(|$i$\verb+-|+$j$|)|.
6961
6962 \medskip
6963 \begin{Code}
6964 \begin{NiceMatrix}
6965 \CodeBefore
6966 \emph{\tikz \draw [fill=red!15] (7-|4) |- (8-|5) |- (9-|6) |- cycle ;}
6967 \Body
6968 1 \\
6969 1 & 1 \\
6970 1 & 2 & 1 \\
6971 1 & 3 & 3 & 1 \\
6972 1 & 4 & 6 & 4 & 1 \\
6973 1 & 5 & 10 & 10 & 5 & 1 \\
6974 1 & 6 & 15 & 20 & 15 & 6 & 1 \\
6975 1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 \\
6976 1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1
6977 \end{NiceMatrix}
6978 \end{Code}
6979 %
6980 \[\begin{NiceMatrix}
6981 \CodeBefore
6982 \tikz \draw [fill=red!15] (7-|4) |- (8-|5) |- (9-|6) |- cycle ;
6983 \Body
6984 1 \\
6985 1 & 1 \\
6986 1 & 2 & 1 \\
6987 1 & 3 & 3 & 1 \\
6988 1 & 4 & 6 & 4 & 1 \\
6989 1 & 5 & 10 & 10 & 5 & 1 \\
6990 1 & 6 & 15 & 20 & 15 & 6 & 1 \\
6991 1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 \\
6992 1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1
6993 \end{NiceMatrix}\]
6994
6995
6996 \bigskip
6997 The ``decimal'' nodes (like $i$|.4|) may be used, for example to cross a row of
6998 a matrix (if TikZ is loaded).
6999
7000 \smallskip
7001 \begin{Code}[width=11cm]
7002 $\begin{pNiceArray}{ccc|c}
7003 2 & 1 & 3 & 0 \\
7004 3 & 3 & 1 & 0 \\
7005 3 & 3 & 1 & 0
7006 \CodeAfter
7007 \tikz \draw [red] (\emph{3.4}-|1) -- (\emph{3.4}-|last) ;
7008 \end{pNiceArray}$
7009 \end{Code}
7010 $\begin{pNiceArray}{ccc|c}
7011 2 & 1 & 3 & 0 \\
7012 3 & 3 & 1 & 0 \\
7013 3 & 3 & 1 & 0
7014 \CodeAfter
7015 \tikz \draw [red] (3.4-|1) -- (3.4-|last) ;
7016 \end{pNiceArray}$
7017
7018 \subsection{The nodes corresponding to the command \texttt{\textbackslash SubMatrix}}
7019
7020 \label{node-sub-matrix}
7021 \index{SubMatrix@\texttt{\textbackslash SubMatrix} (command of
7022 \texttt{\textbackslash CodeAfter}\newline and
7023 \texttt{\textbackslash CodeBefore})}
7024 \index{name!key of \texttt{\textbackslash SubMatrix}}
7025
7026
7027 The command |\SubMatrix| available in the |\CodeAfter| has been described
7028 in the section~\ref{sub-matrix}, p.~\pageref{sub-matrix}.
7029
7030 \smallskip
7031 If a command |\SubMatrix| has been used with the key |name| with an expression
7032 such as |name=|\textsl{\ttfamily MyName} three PGF/TikZ nodes are created
7033 with the names \textsl{\ttfamily MyName}|-left|, \textsl{\ttfamily MyName} and
7034 \textsl{\ttfamily MyName}|-right|.
7035
7036 \smallskip
7037 The nodes \textsl{\ttfamily MyName}|-left| and \textsl{\ttfamily
7038 MyName}|-right| correspond to the delimiters left and right and the node
7039 \textsl{\ttfamily MyName} correspond to the submatrix itself.
7040
7041 \medskip
7042 In the following example, we have highlighted these nodes (the submatrix itself has
7043 been created with |\SubMatrix\{{2-2}{3-3}\}|).
7044
7045 \[\begin{pNiceMatrix}
7046 121 & 23 & 345 & 345\\
7047 45 & 346 & 863 & 444\\
7048 3462 & 38458 & 34 & 294 \\
7049 34 & 7 & 78 & 309 \\
7050 \CodeAfter
7051 \SubMatrix\{{2-2}{3-3}\}[name=A]
7052 \begin{tikzpicture}
7053 [every node/.style = {blend mode = multiply,
7054 inner sep = 0 pt}]
7055 \node [fit = (A),fill = red!15] {} ;
7056 \node [fit = (A-left),fill = blue!15] {} ;
7057 \node [fit = (A-right),fill = blue!15] {} ;
7058 \end{tikzpicture}
7059 \end{pNiceMatrix}\]
7060
7061 \index{node@\textbf{Nodes of PGF/TikZ}|)}
7062
7063 \section{API for the developers}
7064
7065
7066 \subsection{Public sets of keys}
7067
7068 The extension \pkg{nicematrix} provides several public sets of keys:
7069 \begin{itemize}
7070 \item \Definition{nicematrix/environments} which applies to all the
7071 environments of \pkg{nicematrix};
7072 \item \Definition{nicematrix/NiceMatrix} which applies specifically to the
7073 environment |{NiceMatrix}| and its variants with delimiters (|{pNiceMatrix}|,
7074 etc.);
7075 \item \Definition{nicematrix/NiceTabular} which applies specifically to the
7076 environements |{NiceTabular}|, |{NiceTabularX}| and |{NiceTabular*}|.
7077 \end{itemize}
7078
7079 \bigskip
7080 For example, if you wish to be able to fix the parameter |\arraystretch| with
7081 a key |arraystretch|, you only have to add the following instructions in the preamble
7082 of the LaTeX document.
7083
7084 \bigskip
7085 \begin{Code}
7086 \DeclareKeys[\emph{nicematrix/environments}]{arraystretch.store=\arraystretch}
7087 \end{Code}
7088
7089 \bigskip
7090 Then, it's possible to write, for example:
7091
7092 \medskip
7093 \begin{Code}[width=11cm]
7094 \begin{NiceTabular}{cc}[hvlines,\emph{arraystretch=2}]
7095 a & b \\
7096 c & d
7097 \end{NiceTabular}
7098 \end{Code}
7099 \begin{scope}
7100 \renewcommand{\arraystretch}{2}
7101 \begin{NiceTabular}{cc}[hvlines]
7102 a & b \\
7103 c & d
7104 \end{NiceTabular}
7105 \end{scope}
7106
7107
7108 \subsection{\texttt{\textbackslash CodeBefore} and \texttt{\textbackslash CodeAfter}}
7109
7110 The package \pkg{nicematrix} provides two variables which are internal but
7111 public\footnote{According to the LaTeX3 conventions,
7112 each variable with name beginning with |\g_nicematrix| ou |\l_nicematrix| is
7113 public and each variable with name beginning with |\g__nicematrix| or
7114 |\l__nicematrix| is private.}:
7115 \begin{itemize}
7116 \item |\g_nicematrix_code_before_tl| ;
7117 \item |\g_nicematrix_code_after_tl|.
7118 \end{itemize}
7119
7120
7121 \medskip
7122 These variables contain the code of what we have called the ``|code-before|''
7123 (usually specified at the beginning of the environment with the syntax using
7124 the keywords |\CodeBefore| and |\Body|) and the ``|code-after|'' (usually
7125 specified at the end of the environment after the keyword |\CodeAfter|). The
7126 developer can use them to add code from a cell of the array (the affectation
7127 must be global, allowing to exit the cell, which is a TeX group).
7128
7129 \medskip
7130 One should remark that the use of |\g_nicematrix_code_before_tl| needs one
7131 compilation more (because the instructions are written on the |aux| file to be
7132 used during the next run).
7133
7134 \bigskip
7135 \emph{Example} : We want to write a command |\crossbox| to draw a cross in the
7136 current cell. This command will take in an optional argument between square
7137 brackets for a list of pairs \textsl{key}-\textsl{value} which will be given to
7138 TikZ before the drawing.
7139 It's possible to program such command |\crossbox| as follows, explicitly
7140 using the public variable |\g_nicematrix_code_before_tl|.
7141
7142 We use |\g_nicematrix_code_before_tl| instead of |\g_nicematrix_code_after_tl| because
7143 we want to draw the cross before the horizontal aud vertical rules (in order to have
7144 a perfect output).
7145
7146 \index{crossbox@\texttt{\textbackslash crossbox} (defined in an example)|textit}
7147
7148 \medskip
7149 \begin{Code}
7150 \ExplSyntaxOn
7151 \cs_new_protected:Nn \__pantigny_crossbox:nnn
7152 {
7153 \tikz \draw [ #3 ]
7154 ( #1 -| \inteval { #2 + 1 } ) -- ( \inteval { #1 + 1 } -| #2 )
7155 ( #1 -| #2 ) -- ( \inteval { #1 + 1 } -| \inteval { #2 + 1 } ) ;
7156 }
7157
7158 \NewDocumentCommand \crossbox { ! O { } }
7159 {
7160 \tl_gput_right:Ne \emph{\g_nicematrix_code_before_tl}
7161 {
7162 \__pantigny_crossbox:nnn
7163 { \int_use:c { c@iRow } }
7164 { \int_use:c { c@jCol } }
7165 { \exp_not:n { #1 } }
7166 }
7167 \ignorespaces
7168 }
7169 \ExplSyntaxOff
7170 \end{Code}
7171
7172
7173
7174 \ExplSyntaxOn
7175 \cs_new_protected:Nn \__pantigny_crossbox:nnn
7176 {
7177 \tikz \draw [ #3 ]
7178 ( #1 -| \inteval { #2 + 1 } ) -- ( \inteval { #1 + 1 } -| #2 )
7179 ( #1 -| #2 ) -- ( \inteval { #1 + 1 } -| \inteval { #2 + 1 } ) ;
7180 }
7181
7182
7183 \NewDocumentCommand \crossbox { ! O { } }
7184 {
7185 \tl_gput_right:Ne \g_nicematrix_code_before_tl
7186 {
7187 \__pantigny_crossbox:nnn
7188 { \int_use:c { c@iRow } }
7189 { \int_use:c { c@jCol } }
7190 { \exp_not:n { #1 } }
7191 }
7192 \ignorespaces
7193 }
7194 \ExplSyntaxOff
7195
7196 \medskip
7197 We have used the LaTeX |counters iRow| and |jCol| provided by \pkg{nicematrix}
7198 (cf.~\ref{iRow}, p.~\pageref{iRow}).
7199
7200 \bigskip
7201 Here is an example of use:
7202
7203 \medskip
7204 \begin{Code}[width=9cm]
7205 \begin{NiceTabular}{ccc}[hvlines]
7206 \CodeBefore
7207 \arraycolor{gray!10}
7208 \Body
7209 merlan & requin & cabillaud \\
7210 baleine & \emph{\crossbox[red]} & morue \\
7211 mante & raie & poule
7212 \end{NiceTabular}
7213 \end{Code}
7214 \begin{NiceTabular}{ccc}[hvlines]
7215 \CodeBefore
7216 \arraycolor{gray!10}
7217 \Body
7218 merlan & requin & cabillaud \\
7219 baleine & \crossbox[red] & morue \\
7220 mante & raie & poule
7221 \end{NiceTabular}
7222
7223
7224
7225 \section{Technical remarks}
7226
7227 First remark: the package \pkg{underscore} must be loaded before
7228 \pkg{nicematrix}. If it is loaded after, an error will be raised.
7229
7230 \subsection{Diagonal lines}
7231
7232 \label{parallelization}
7233 \index{parallelize-diags}
7234 \index{Ddots@\texttt{\textbackslash Ddots}}
7235 \index{Iddots@\texttt{\textbackslash Iddots}}
7236
7237 By default, all the diagonal lines\footnote{We speak of the lines created by
7238 |\Ddots| and not the lines created by a command |\line| in the |\CodeAfter|.} of a
7239 same array are ``parallelized''. That means that the first diagonal line is
7240 drawn and, then, the other lines are drawn parallel to the first one (by
7241 rotation around the left-most extremity of the line). That's why the position
7242 of the instructions |\Ddots| in the array can have a marked effect on the
7243 final result.
7244
7245 \medskip
7246 In the following examples, the first |\Ddots| instruction is written in color.
7247
7248 \begin{scope}
7249 \begin{minipage}{9.5cm}
7250 Example with parallelization (default):
7251 \begin{Code}
7252 $A = \begin{pNiceMatrix}
7253 1 & \Cdots & & 1 \\
7254 a+b & \emph{\Ddots} & & \Vdots \\
7255 \Vdots & \Ddots & & \\
7256 a+b & \Cdots & a+b & 1
7257 \end{pNiceMatrix}$
7258 \end{Code}
7259 \end{minipage}
7260 $A = \begin{pNiceMatrix}
7261 1 & \Cdots & & 1 \\
7262 a+b & \Ddots & & \Vdots \\
7263 \Vdots & \Ddots & & \\
7264 a+b & \Cdots & a+b & 1
7265 \end{pNiceMatrix}$
7266
7267 \bigskip
7268 \NiceMatrixOptions{parallelize-diags=true}%
7269 \begin{minipage}{9.5cm}
7270 \begin{Code}
7271 $A = \begin{pNiceMatrix}
7272 1 & \Cdots & & 1 \\
7273 a+b & & & \Vdots \\
7274 \Vdots & \emph{\Ddots} & \Ddots & \\
7275 a+b & \Cdots & a+b & 1
7276 \end{pNiceMatrix}$
7277 \end{Code}
7278 \end{minipage}
7279 $A = \begin{pNiceMatrix}
7280 1 & \Cdots & & 1 \\
7281 a+b & & & \Vdots \\
7282 \Vdots & \Ddots & \Ddots & \\
7283 a+b & \Cdots & a+b & 1
7284 \end{pNiceMatrix}$
7285
7286 \bigskip
7287 It's possible to turn off the parallelization with the option
7288 \Definition{parallelize-diags} set to |false|: \par\nobreak
7289
7290 \medskip
7291 \NiceMatrixOptions{parallelize-diags=false}%
7292 \begin{minipage}{9.5cm}
7293 The same example without parallelization:
7294 \end{minipage}
7295 $A = \begin{pNiceMatrix}
7296 1 & \Cdots & & 1 \\
7297 a+b & \Ddots & & \Vdots \\
7298 \Vdots & \Ddots & & \\
7299 a+b & \Cdots & a+b & 1
7300 \end{pNiceMatrix}$
7301 \end{scope}
7302
7303 \medskip
7304 It's possible to specify the instruction |\Ddots| which will be drawn first
7305 (and which will be used to draw the other diagonal dotted lines when the
7306 parallelization is in force) with the key \Definition{draw-first}:
7307 |\Ddots[draw-first]|.
7308
7309 \subsection[The empty cells]{The ``empty'' cells}
7310
7311 \label{empty-cells}
7312 The package \pkg{nicematrix} uses, in several circunstancies, the concept of
7313 ``empty cell''. For example, an instruction like |\Ldots|, |\Cdots|,
7314 etc. (cf.~\ref{Cdots}, p.~\pageref{Cdots}) tries to determine the first non-empty
7315 cell on both sides. In the same way, when the key |corners| is used
7316 (cf.~\ref{corners}, p.~\pageref{corners}), \pkg{nicematrix} computes corners
7317 consisting of empty cells.
7318
7319 However, an ``empty cell'' is not necessarily a cell with no TeX
7320 content (that is to say a cell with no token between the two ampersands~|&|).
7321 The precise rules are as follow.
7322
7323 \begin{itemize}
7324 \item An implicit cell is empty. For example, in the following matrix:
7325
7326 \begin{Verbatim}
7327 \begin{pmatrix}
7328 a & b \\
7329 c \\
7330 \end{pmatrix}
7331 \end{Verbatim}
7332
7333 the last cell (second row and second column) is empty.
7334
7335 \medskip
7336 \item For the columns of type |p|, |m|, |b|, |V|\footnote{The columns of type
7337 |V| are provided by \pkg{varwidth}, which must be loaded:
7338 cf.~\ref{varwidth}, p.~\pageref{varwidth}.} and
7339 |X|\footnote{See~\ref{X-columns}, p.~\pageref{X-columns}}, the
7340 cell is empty if (and only if) its content in the TeX code is empty (there is
7341 only spaces between the ampersands |&|).
7342
7343 \medskip
7344 \item For the columns of type |c|, |l|, |r| and |w{...}{...}|, the cell is
7345 empty if (and only if) its TeX output has a width equal to zero.
7346
7347 \medskip
7348 \item \indexcommand{NotEmpty}
7349 A cell containing the command |\NotEmpty| is not empty (and a
7350 PGF/TikZ node is created in that cell).
7351
7352 \medskip
7353 \item A cell with only a command |\Hspace| (or |\Hspace*|) is empty. This
7354 command |\Hspace| is a command defined by the package \pkg{nicematrix} with
7355 the same meaning as |\hspace| except that the cell where it is used is
7356 considered as empty. This command can be used to fix the width of some columns
7357 of the matrix without interfering with \pkg{nicematrix}.
7358 \end{itemize}
7359
7360
7361 \subsection{The option exterior-arraycolsep}
7362
7363 \index{exterior-arraycolsep}
7364
7365 The environment |{array}| inserts an horizontal space equal to |\arraycolsep|
7366 before and after each column. In particular, there is a space equal to
7367 |\arraycolsep| before and after the array. This feature of the environment
7368 |{array}| was probably not a good idea\footnote{In the documentation of
7369 \pkg{amsmath}, we can read: {\itshape The extra space of |\arraycolsep| that
7370 \pkg{array} adds on each side is a waste so we remove it [in |{matrix}|]
7371 (perhaps we should instead remove it from array in general, but that's a
7372 harder task).}}. The environment |{matrix}| of
7373 \pkg{amsmath} and its variants (|{pmatrix}|, |{vmatrix}|, etc.) of
7374 \pkg{amsmath} prefer to delete these spaces with explicit instructions
7375 |\hskip -\arraycolsep|\footnote{And not by inserting |@{}| on both sides of the
7376 preamble of the array. As a consequence, the length of the |\hline| is not
7377 modified and may appear too long, in particular when using square brackets.}.
7378 The package \pkg{nicematrix} does the same in all its environments,
7379 |{NiceArray}| included. However, if the user wants the environment
7380 |{NiceArray}| behaving by default like the environment |{array}| of
7381 \pkg{array} (for example, when adapting an existing document) it's possible to
7382 control this behaviour with the option \Definition{exterior-arraycolsep}, set by
7383 the command |\NiceMatrixOptions|. With this option, exterior spaces of length
7384 |\arraycolsep| will be inserted in the environments |{NiceArray}| (the other
7385 environments of \pkg{nicematrix} are not affected).
7386
7387
7388
7389
7390 \subsection{Incompatibilities}
7391
7392 \index{Incompatibilities}
7393
7394 \textbf{The package \pkg{nicematrix} can't be used in the class \cls{revtex4-2}
7395 because this class is not compatible with the recent versions of LaTeX.}
7396 Indeed, \cls{revtex4-2} modifies serval interal commands of \pkg{array} and
7397 those modifications have not been updated to take into acount the recent changes in
7398 \pkg{array} in relation with the Tagging Project.
7399
7400 \bigskip
7401
7402 There might be incompatibilities between \pkg{nicematrix} and \pkg{babel} with
7403 the language which activate (in the TeX sens) some characters, in particular
7404 the character |<|.
7405
7406 Par exemple, for Spanish, it's recommended to deactivate the abreviations at
7407 load-time with the instruction:
7408
7409 \begin{Code}
7410 \usepackage[spanish,es-noshorthands]{babel}
7411 \end{Code}
7412
7413 \medskip
7414 The extension \pkg{nicematrix} is usually not compatible with the classes and
7415 packages that redefine the environments |{tabular}| and |{array}|. In
7416 particular, it's the case of the class |socg-lipics-v2021|. However, in that
7417 case, it's possible to load the class with the key |notab| which requires that
7418 the environment |{tabular}| is not redefined.
7419
7420 \medskip
7421
7422 The package \pkg{nicematrix} is not compatible with the class \cls{ieeeaccess}
7423 because that class is not compatible with PGF/TikZ. However, there is a simple
7424 workaround by writing:\footnote{See
7425 \url{https://tex.stackexchange.com/questions/528975}}
7426
7427 \nobreak
7428 \begin{Code}
7429 \let\TeXyear\year
7430 \documentclass{IEEEaccess}
7431 \let\year\TeXyear
7432 \end{Code}
7433
7434
7435
7436 \medskip
7437 % the following requirement is still in force on April 23, 2024
7438 In order to use \pkg{nicematrix} with the class \cls{aastex631}
7439 (of the \emph{American Astronomical Society}), you have to
7440 add the following instructions in the preamble of your document :
7441
7442 % With the following construction, we avoid problem of fontification with Emacs
7443 \begin{scope}\ttfamily \color{gray}
7444 \textbackslash BeforeBegin\{NiceTabular\}\{\textbackslash
7445 let\textbackslash begin\textbackslash BeginEnvironment\textbackslash
7446 let\textbackslash end\textbackslash EndEnvironment\}
7447
7448 \textbackslash BeforeBegin\{NiceArray\}\{\textbackslash
7449 let\textbackslash begin\textbackslash BeginEnvironment\}
7450
7451 \textbackslash BeforeBegin\{NiceMatrix\}\{\textbackslash
7452 let\textbackslash begin\textbackslash BeginEnvironment\}
7453 \end{scope}
7454
7455
7456 \medskip
7457 The package \pkg{nicematrix} is not fully compatible with the packages and classes
7458 of LuaTeX-ja: the detection of the empty corners (cf.~\ref{corners}, p.~\pageref{corners})
7459 may be wrong in some circonstances.
7460
7461 \medskip
7462 The package \pkg{nicematrix} is not fully compatible with the package
7463 \pkg{arydshln} (because this package redefines many internals of \pkg{array})
7464 and does not support the columns~|V| of \pkg{boldline} (because the letter |V| is
7465 reserved for the columns~|V| of \pkg{varwidth}). By any means, \pkg{nicematrix}
7466 provides, with the key |custom-line| (cf.~\ref{custom-line},
7467 p.~\pageref{custom-line}), tools to draw dashed rules and rules of different
7468 widths.
7469
7470 \bigskip
7471 The columns |d| of \pkg{dcolumn} are not supported (but it's possible to use
7472 the columns |S| of \pkg{siunitx}).
7473
7474
7475 \subsection{Compatibility with the Tagging Project of LaTeX}
7476
7477 \index{Tagging Project}
7478 \label{Tagging Project}
7479
7480 Since the version 7.0, the extension \pkg{nicematrix} is compatible with the
7481 \emph{Tagging Project} of LaTeX (whose aim is to create tagged PDF). At this time, only
7482 simple standard tabulars are correctly tagged.
7483
7484 Here is a example of code which will generate a tagged PDF.
7485
7486 \bigskip
7487 \begin{center}
7488 \small
7489 \begin{Code}
7490 \emph{\DocumentMetadata{tagging = on}}
7491 \documentclass{article}
7492 \usepackage{lmodern}
7493 \usepackage{nicematrix}
7494
7495 \begin{document}
7496
7497 \begin{center}
7498 \emph{\tagpdfsetup{table/header-rows=1}}
7499 \begin{NiceTabular}{ccc}[hvlines]
7500 First name & Last name & Age \\
7501 Paul & Imbert & $66$ \\
7502 John & Sarrus & $23$ \\
7503 Liz & Taylor & $100$ \\
7504 George & Adams & $34$
7505 \end{NiceTabular}
7506 \end{center}
7507
7508 \end{document}
7509 \end{Code}
7510 \end{center}
7511
7512
7513
7514 \section{Examples}
7515
7516
7517
7518 \subsection{Notes in the tabulars}
7519
7520 \index{nota@\textbf{Notes in the tabulars}|textit}
7521 \index{tabularnote@\texttt{\textbackslash tabularnote}|textit}
7522 \index{notes (key to customize the notes of a\newline tabular)|textit}
7523 \index{style (subkey of ``notes'')|textit}
7524 \index{enumitem-keys (subkey of ``notes'')|textit}
7525 \index{enumitem@\pkg{enumitem} (package required to use\newline \texttt{\textbackslash tabularnote})|textit}
7526
7527
7528 \label{ex:notes}
7529
7530 The tools provided by \pkg{nicematrix} for the composition of the tabular
7531 notes have been presented in the section~\ref{s:notes}, p.~\pageref{s:notes}.
7532
7533 \medskip
7534 Let's consider that we wish to number the notes of a tabular with
7535 stars.\footnote{Of course, it's realistic only when there is very few notes in
7536 the tabular.}
7537
7538 \medskip
7539 First, we write a command |\stars| similar to the well-known commands
7540 |\arabic|, |\alph|, |\Alph|, etc. which produces a number of stars equal to
7541 its argument\footnote{In fact: the value of its argument.}.
7542 \begin{Code}
7543 \ExplSyntaxOn
7544 \NewDocumentCommand { \emph{\stars} } { m }
7545 { \prg_replicate:nn { \value { #1 } } { \( \star \) } }
7546 \ExplSyntaxOff
7547 \end{Code}
7548 %
7549 Of course, we change the style of the labels with the key |notes/style|.
7550 However, it would be interesting to change also some parameters in the type of
7551 list used to compose the notes at the end of the tabular.
7552 First, we required a composition flush right for the labels with the setting
7553 |align=right|.
7554 Moreover, we want the labels to be composed on a width equal to the width of
7555 the widest label. The widest label is, of course, the label with the greatest
7556 number of stars. We know that number: it is equal to |\value{tabularnote}|
7557 (because |tabularnote| is the LaTeX counter used by |\tabularnote| and,
7558 therefore, at the end of the tabular, its value is equal to the total number
7559 of tabular notes). We use the key |widest*| of \pkg{enumitem} in order to
7560 require a width equal to that value: |widest*=\value{tabularnote}|.
7561
7562 \begin{Code}
7563 \NiceMatrixOptions
7564 {
7565 notes =
7566 {
7567 \emph{style = \stars{#1} ,
7568 enumitem-keys =
7569 {
7570 widest* = \value{tabularnote} ,
7571 align = right
7572 } }
7573 }
7574 }
7575 \end{Code}
7576
7577
7578
7579 \begin{scope}
7580 \ExplSyntaxOn
7581 \NewDocumentCommand \stars { m }
7582 { \prg_replicate:nn { \value { #1 } } { \( \star \) } }
7583 \NiceMatrixOptions
7584 {
7585 notes =
7586 {
7587 style = \stars{#1} ,
7588 enumitem-keys =
7589 {
7590 widest* = \value{tabularnote} ,
7591 align = right
7592 }
7593 }
7594 }
7595 \ExplSyntaxOff
7596 \begin{Code}
7597 \begin{NiceTabular}{@{}llr@{}}
7598 \toprule \RowStyle{\bfseries}
7599 Last name & First name & Birth day \\
7600 \midrule
7601 Achard\tabularnote{\emph{Achard is an old family of the Poitou.}}
7602 & Jacques & 5 juin 1962 \\
7603 Lefebvre\tabularnote{\emph{The name Lefebvre is an alteration of the name Lefebure.}}
7604 & Mathilde & 23 mai 1988 \\
7605 Vanesse & Stephany & 30 octobre 1994 \\
7606 Dupont & Chantal & 15 janvier 1998 \\
7607 \bottomrule
7608 \end{NiceTabular}
7609 \end{Code}
7610
7611 \begin{center}
7612 \begin{NiceTabular}{@{}llr@{}}[no-cell-nodes]
7613 \toprule \RowStyle{\bfseries}
7614 Last name & First name & Birth day \\
7615 \midrule
7616 Achard\tabularnote{Achard is an old family of the Poitou.}
7617 & Jacques & June 5, 2005 \\
7618 Lefebvre\tabularnote{The name Lefebvre is an alteration of the name Lefebure.}
7619 & Mathilde & January 23, 1975 \\
7620 Vanesse & Stephany & October 30, 1994 \\
7621 Dupont & Chantal & January 15, 1998 \\
7622 \bottomrule
7623 \end{NiceTabular}
7624 \end{center}
7625 \end{scope}
7626
7627
7628 \subsection[{Use of the key 'tikz' of the command \textbackslash
7629 Block}]{Use of the key ``tikz'' of the command \texttt{\textbackslash Block}}
7630 \label{tikz-key-examples}
7631
7632 \index{tikzz@tikz!key of \texttt{\textbackslash Block}|textit}
7633
7634 The key |tikz| of the command |\Block| is available only when TikZ is
7635 loaded.\footnote{By default, \pkg{nicematrix} only loads \textsc{pgf}, which is
7636 a sub-layer of TikZ.}
7637
7638 For the following example, we also need the TikZ library |patterns|.
7639
7640 \begin{Verbatim}[formatcom = \footnotesize\color{gray}]
7641 \usepackage{tikz} % in the preamble
7642 \usetikzlibrary{patterns} % in the preamble
7643 \end{Verbatim}
7644
7645
7646 \begin{Code}
7647 \ttfamily \small
7648 \begin{NiceTabular}{X[m]X[m]X[m]}[hvlines,cell-space-limits=3pt,rounded-corners]
7649 \Block[\emph{tikz={pattern=grid,pattern color=lightgray}}]{}
7650 {pattern = grid,\\ pattern color = lightgray}
7651 & \Block[\emph{tikz={pattern = north west lines,pattern color=blue}}]{}
7652 {pattern = north west lines,\\ pattern color = blue}
7653 & \Block[\emph{tikz={outer color = red!50, inner color=white }}]{2-1}
7654 {outer color = red!50,\\ inner color = white} \\
7655 \Block[\emph{tikz={pattern = sixpointed stars, pattern color = blue!15}}]{}
7656 {pattern = sixpointed stars,\\ pattern color = blue!15}
7657 & \Block[\emph{tikz={left color = blue!50}}]{}
7658 {left color = blue!50} \\
7659 \end{NiceTabular}
7660 \end{Code}
7661
7662 \begin{center}
7663 \ttfamily \small
7664 \begin{NiceTabular}{X[m]X[m]X[m]}[hvlines,cell-space-limits=3pt,rounded-corners,no-cell-nodes]
7665 \Block[tikz={pattern=grid,pattern color=lightgray}]{}
7666 {pattern = grid,\\ pattern color = lightgray}
7667 & \Block[tikz={pattern = north west lines,pattern color=blue}]{}
7668 {pattern = north west lines,\\ pattern color = blue}
7669 & \Block[tikz={outer color = red!50, inner color=white }]{2-1}
7670 {outer color = red!50,\\ inner color = white} \\
7671 \Block[tikz={pattern = sixpointed stars, pattern color = blue!15}]{}
7672 {pattern = sixpointed stars,\\ pattern color = blue!15}
7673 & \Block[tikz={left color = blue!50}]{}
7674 {left color = blue!50} \\
7675 \end{NiceTabular}
7676 \end{center}
7677
7678 \bigskip
7679 In the following example, we use the key |tikz| to hatch a row of the tabular.
7680 Remark that you use the key |transparent| of the command |\Block| in order to
7681 have the rules drawn in the block.\footnote{By default, the rules are not
7682 drawn in the blocks created by the command |\Block| (cf.~\ref{rules},
7683 p.~\pageref{rules}): with the key |transparent|, they are drawn (the block
7684 becomes \emph{transparent} to the exterior rules).}
7685
7686 \index{transparent (key of \texttt{\textbackslash Block})|textit}
7687 \index{columncolor@\texttt{\textbackslash columncolor}!command of
7688 \texttt{\textbackslash CodeBefore}|textit}
7689
7690 \medskip
7691
7692 \begin{Code}
7693 \begin{NiceTabular}{ccc}[hvlines]
7694 \CodeBefore
7695 \columncolor[RGB]{169,208,142}{2}
7696 \Body
7697 one & two & three \\
7698 \Block[\emph{transparent,tikz={pattern = north west lines, pattern color = red}}]{1-*}{}
7699 four & five & six \\
7700 seven & eight & nine
7701 \end{NiceTabular}
7702 \end{Code}
7703
7704 \begin{center}
7705 \begin{NiceTabular}{ccc}[hvlines]
7706 \CodeBefore
7707 \columncolor[RGB]{169,208,142}{2}
7708 \Body
7709 one & two & three \\
7710 \Block[transparent,tikz={pattern = north west lines, pattern color = red}]{1-*}{}
7711 four & five & six \\
7712 seven & eight & nine
7713 \end{NiceTabular}
7714 \end{center}
7715
7716 \subsection{Use with \texorpdfstring{\pkg{tcolorbox}}{tcolorbox}}
7717
7718 \label{tcolorbox}
7719 \index{tcolorbox@\pkg{tcolorbox} (package)|textit}
7720
7721 Here is an example of use of |{NiceTabular}| within a command |\tcbox| of
7722 \pkg{tcolorbox}. We have used the key |hvlines-except-borders| in order to draw all
7723 the rules, except on the borders (which are, of course, added by \pkg{tcolorbox}).
7724
7725 \medskip
7726 \begin{Code}
7727 \tcbset
7728 {
7729 colframe = blue!50!black ,
7730 colback = white ,
7731 fonttitle = \bfseries ,
7732 nobeforeafter ,
7733 center title
7734 }
7735
7736 \tcbox
7737 [
7738 left = 0mm ,
7739 right = 0mm ,
7740 top = 0mm ,
7741 bottom = 0mm ,
7742 boxsep = 0mm ,
7743 toptitle = 0.5mm ,
7744 bottomtitle = 0.5mm ,
7745 title = My table
7746 ]
7747 {
7748 \renewcommand{\arraystretch}{1.2}% <-- the % is mandatory here
7749 \begin{NiceTabular}{rcl}[\emph{hvlines-except-borders},rules/color=blue!50!black]
7750 \CodeBefore
7751 \rowcolor{red!15}{1}
7752 \Body
7753 One & Two & Three \\
7754 Men & Mice & Lions \\
7755 Upper & Middle & Lower
7756 \end{NiceTabular}
7757 }
7758 \end{Code}
7759
7760
7761 \index{hvlines-except-borders|textit}
7762 \index{rules (key for an environment)|textit}
7763 \index{rowcolor@\texttt{\textbackslash rowcolor}!command of \texttt{\textbackslash CodeBefore}|textit}
7764
7765 \medskip
7766 \begin{center}
7767 \tcbset
7768 {
7769 colframe = blue!50!black ,
7770 colback = white ,
7771 fonttitle = \bfseries ,
7772 nobeforeafter ,
7773 center title
7774 }
7775
7776 \tcbox
7777 [
7778 left = 0mm ,
7779 right = 0mm ,
7780 top = 0mm ,
7781 bottom = 0mm ,
7782 boxsep = 0mm ,
7783 toptitle = 0.5mm ,
7784 bottomtitle = 0.5mm ,
7785 title = My table
7786 ]
7787 {
7788 \renewcommand{\arraystretch}{1.2}\begin{NiceTabular}{rcl}[hvlines-except-borders,rules/color=blue!50!black]
7789 \CodeBefore
7790 \rowcolor{red!15}{1}
7791 \Body
7792 One & Two & Three \\
7793 Men & Mice & Lions \\
7794 Upper & Middle & Lower
7795 \end{NiceTabular}
7796 }
7797 \end{center}
7798
7799
7800 \subsection{A sign chart}
7801
7802
7803 \begin{Code}
7804 \[\begin{NiceMatrix}[columns-width=1cm,hvlines]
7805 f(x) & \Block[C]{1-5}{+} \\
7806 f'(x) & \Block[C]{1-2}{+} && \Block[C]{1-2}{+} && + \\
7807 f''(x) & - & \Block[C]{1-2}{-} && \Block[C]{1-2}{+} \\
7808 \end{NiceMatrix}\]
7809 \end{Code}
7810
7811 \bigskip
7812 With the key |C| of the command |\Block|, the content of the block is centered according
7813 to the absolute limits of the columns (whereas, with the key |c|, the content is centered
7814 according to the \emph{contents} of the cells of the corresponding columns --- and, here,
7815 there are many columns without content).
7816
7817 \bigskip
7818
7819 \[\begin{NiceMatrix}[columns-width=1cm,hvlines]
7820 f(x) & \Block[C]{1-5}{+} \\
7821 f'(x) & \Block[C]{1-2}{+} && \Block[C]{1-2}{+} && + \\
7822 f''(x) & - & \Block[C]{1-2}{-} && \Block[C]{1-2}{+} \\
7823 \end{NiceMatrix}\]
7824
7825
7826
7827 \subsection{A variation table}
7828
7829
7830 In the following variation table, you draw the arrows (and some additional rules)
7831 with TikZ by using the PGF/TikZ nodes created by \pkg{nicematrix}
7832 (cf.~\ref{PGF-nodes}, p.~\pageref{PGF-nodes}).
7833
7834 \medskip
7835 \begin{Code}
7836 \begin{NiceArray}{r|cw{c}{1cm}cw{c}{1cm}c}[cell-space-limits=2pt]
7837 x & 0 & - & \frac{1}{e} & + & +\infty \\
7838 \Hline
7839 f'(x) & & - & 0 & + & \\
7840 \Hline
7841 & 1 & & & & +\infty \\
7842 f & & & & & \\
7843 & & & (1/e)^{1/e} \\
7844 \CodeAfter
7845 \begin{tikzpicture}
7846 \draw (3-|4.5) -- (5-|4.5) ;
7847 \draw ([xshift=3pt]2-|2) -- ([xshift=3pt]3-|2) ;
7848 \draw [->,red,shorten < = 3pt] (3-2) -- (5-4) ;
7849 \draw [->,red,shorten < = 3pt] (5-4) -- (3-6) ;
7850 \end{tikzpicture}
7851 \end{NiceArray}
7852 \end{Code}
7853
7854
7855 \[
7856 \begin{NiceArray}{r|cw{c}{1cm}cw{c}{1cm}c}[cell-space-limits=2pt]
7857 x & 0 & - & \frac{1}{e} & + & +\infty \\
7858 \Hline
7859 f'(x) & & - & 0 & + & \\
7860 \Hline
7861 & 1 & & & & +\infty \\
7862 f & & & & & \\
7863 & & & (1/e)^{1/e} \\
7864 \CodeAfter
7865 \begin{tikzpicture}
7866 \draw (3-|4.5) -- (5-|4.5) ;
7867 \draw ([xshift=3pt]2-|2) -- ([xshift=3pt]3-|2) ;
7868 \draw [->,red,shorten < = 3pt] (3-2) -- (5-4) ;
7869 \draw [->,red,shorten < = 3pt] (5-4) -- (3-6) ;
7870 \end{tikzpicture}
7871 \end{NiceArray}
7872 \]
7873
7874
7875
7876 \subsection{Use of the key borders of the command \texttt{\textbackslash Block}}
7877 \label{ex:borders}
7878 \index{tikzz@tikz!key of ``borders'' de \texttt{\textbackslash Block}|textit}
7879
7880 In the following example, we use the command |\Block| to draw rules.
7881
7882 \medskip
7883 \begin{Verbatim}[formatcom = \footnotesize \color{gray}]
7884 \usepackage{tikz} % in the preamble
7885 \end{Verbatim}
7886
7887 \smallskip
7888
7889 \begin{Code}
7890 \begin{pNiceMatrix}
7891 \emph{\Block[borders={bottom,right,tikz=dotted}]{2-2}{}}
7892 1 & 2 & 0 & 0 & 0 & 0 \\
7893 4 & 5 & 0 & 0 & 0 & 0 \\
7894 0 & 0 & \emph{\Block[borders={all,tikz=dotted}]{2-2}{}}
7895 7 & 1 & 0 & 0 \\
7896 0 & 0 & -1 & 2 & 0 & 0 \\
7897 0 & 0 & 0 & 0 & \emph{\Block[borders={left,top,tikz=dotted}]{2-2}{}}
7898 3 & 4 \\
7899 0 & 0 & 0 & 0 & 1 & 4
7900 \end{pNiceMatrix}
7901 \end{Code}
7902
7903
7904 \[\begin{pNiceMatrix}
7905 \Block[borders={bottom,right,tikz=dotted}]{2-2}{}
7906 1 & 2 & 0 & 0 & 0 & 0 \\
7907 4 & 5 & 0 & 0 & 0 & 0 \\
7908 0 & 0 & \Block[borders={all,tikz=dotted}]{2-2}{}
7909 7 & 1 & 0 & 0 \\
7910 0 & 0 & -1 & 2 & 0 & 0 \\
7911 0 & 0 & 0 & 0 & \Block[borders={left,top,tikz=dotted}]{2-2}{}
7912 3 & 4 \\
7913 0 & 0 & 0 & 0 & 1 & 4
7914 \end{pNiceMatrix}\]
7915
7916
7917 \subsection{Dotted leaders in the matrices}
7918
7919 \index{dotted@\textbf{Dotted leaders}|textit}
7920
7921 An example with the resultant of two polynoms (this example requires TikZ
7922 for the dashed rule specified by the letter ``|;|'' in the preamble of the array).
7923
7924
7925 \nobreak
7926 \bigskip
7927 \begin{Verbatim}[formatcom=\footnotesize \color{gray}]
7928 \usepackage{tikz} % in the preamble
7929 \end{Verbatim}
7930
7931 \nobreak
7932 \medskip
7933 \begin{Code}
7934 \setlength{\extrarowheight}{1mm}
7935 \[\begin{vNiceArray}{cccc;ccc}[columns-width=6mm, xdots/shorten += 3pt]
7936 a_0 & && &b_0 & & \\
7937 a_1 &\Ddots&& &b_1 &\Ddots& \\
7938 \Vdots&\Ddots&& &\Vdots &\Ddots&b_0 \\
7939 a_p & &&a_0 & & &b_1 \\
7940 &\Ddots&&a_1 &b_q & &\Vdots\\
7941 & &&\Vdots & &\Ddots& \\
7942 & &&a_p & & &b_q
7943 \end{vNiceArray}\]
7944 \end{Code}
7945
7946 \bigskip
7947 \index{Ddots@\texttt{\textbackslash Ddots}|textit}
7948
7949 \begin{scope}
7950 \setlength{\extrarowheight}{1mm}
7951 \[\begin{vNiceArray}{cccc;ccc}[columns-width=6mm, xdots/shorten += 3pt]
7952 a_0 & && &b_0 & & \\
7953 a_1 &\Ddots&& &b_1 &\Ddots& \\
7954 \Vdots&\Ddots&& &\Vdots &\Ddots&b_0 \\
7955 a_p & &&a_0 & & &b_1 \\
7956 &\Ddots&&a_1 &b_q & &\Vdots\\
7957 & &&\Vdots & &\Ddots& \\
7958 & &&a_p & & &b_q
7959 \end{vNiceArray}\]
7960 \end{scope}
7961
7962 \vspace{2cm}
7963 An example for a linear system. We recall that the key |xdots/nullify| nullifies the
7964 horizontal and vertical spaces created by the commands |\Cdots|, |\Vdots|, etc.
7965 in the tabular (but the dotted lines are actually drawn, despite the name |nullify|!).
7966
7967 \index{last-col|textit}
7968 \index{code-for-last-col|textit}
7969
7970 \medskip
7971 \begin{Code}
7972 \NiceMatrixOptions{code-for-last-col=\scriptstyle}
7973 $\begin{pNiceMatrix}[vlines=-1,xdots/nullify,last-col]
7974 1 & 1 & 1 &\Cdots & & 1 & 0 & \\
7975 0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\
7976 0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\
7977 & & &\Ddots & & & \Vdots & \Vdots \\
7978 \Vdots & & &\Ddots & & 0 & \\
7979 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1
7980 \end{pNiceMatrix}$
7981 \end{Code}
7982
7983
7984 \[\begin{pNiceMatrix}[vlines=-1,xdots/nullify,last-col,code-for-last-col=\scriptstyle]
7985 1 & 1 & 1 &\Cdots & & 1 & 0 & \\
7986 0 & 1 & 0 &\Cdots & & 0 & & L_2 \gets L_2-L_1 \\
7987 0 & 0 & 1 &\Ddots & & \Vdots & & L_3 \gets L_3-L_1 \\
7988 & & &\Ddots & & & \Vdots & \Vdots \\
7989 \Vdots & & &\Ddots & & 0 & \\
7990 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1
7991 \end{pNiceMatrix}\]
7992
7993
7994
7995 \subsection{Dotted leaders which are no longer dotted}
7996
7997 \label{ex:no-longer-dotted-rules}
7998
7999 The option |line-style| controls the style of the leaders drawn by |\Ldots|,
8000 |\Cdots|, etc. Thus, it's possible with these commands to draw lines which are
8001 not longer dotted.
8002
8003 \index{line-style (key for the dotted rules)|textit}
8004
8005 \medskip
8006 \begin{Verbatim}[formatcom=\footnotesize \color{gray}]
8007 \usepackage{tikz} % in the preamble
8008 \usetikzlibrary{decorations} % in the preamble
8009 \end{Verbatim}
8010
8011 \medskip
8012 \begin{small}
8013 \begin{Code}
8014 \setcounter{MaxMatrixCols}{12}
8015 \newcommand{\blue}{\color{blue}}
8016 \[\begin{pNiceMatrix}%
8017 [last-row,last-col,xdots={nullify,line-style={dashed,dash expand off,blue}}]
8018 1& & & \Vdots & & & & \Vdots \\
8019 & \Ddots[line-style=standard] \\
8020 & & 1 \\
8021 \Cdots & & & \blue 0 & \Cdots & & & \blue 1 & & & \Cdots & \blue \leftarrow i \\
8022 & & & & 1 \\
8023 & & &\Vdots & & \Ddots[line-style=standard] & & \Vdots \\
8024 & & & & & & 1 \\
8025 \Cdots & & & \blue 1 & \Cdots & & \Cdots & \blue 0 & & & \Cdots & \blue \leftarrow j \\
8026 & & & & & & & & 1 \\
8027 & & & & & & & & & \Ddots[line-style=standard] \\
8028 & & & \Vdots & & & & \Vdots & & & 1 \\
8029 & & & \blue \overset{\uparrow}{i} & & & & \blue \overset{\uparrow}{j} \\
8030 \end{pNiceMatrix}\]
8031 \end{Code}
8032 \end{small}
8033
8034 \index{code-for-first-row|textit}
8035 \index{code-for-last-col|textit}
8036
8037
8038 \begin{scope}
8039 \setcounter{MaxMatrixCols}{12}
8040 \newcommand{\blue}{\color{blue}}
8041 \[\begin{pNiceMatrix}%
8042 [last-row,last-col,xdots={nullify,line-style={dashed,dash expand off,blue}}]
8043 1& & & \Vdots & & & & \Vdots \\
8044 & \Ddots[line-style=standard] \\
8045 & & 1 \\
8046 \Cdots & & & \blue 0 & \Cdots & & & \blue 1 & & & \Cdots & \blue \leftarrow i \\
8047 & & & & 1 \\
8048 & & &\Vdots & & \Ddots[line-style=standard] & & \Vdots \\
8049 & & & & & & 1 \\
8050 \Cdots & & & \blue 1 & \Cdots & & \Cdots & \blue 0 & & & \Cdots & \blue \leftarrow j \\
8051 & & & & & & & & 1 \\
8052 & & & & & & & & & \Ddots[line-style=standard] \\
8053 & & & \Vdots & & & & \Vdots & & & 1 \\
8054 & & & \blue \overset{\uparrow}{i} & & & & \blue \overset{\uparrow}{j} \\
8055 \end{pNiceMatrix}\]
8056 \end{scope}
8057
8058 \subsection{How the illustrate the numbers of rows and columns in a matrix}
8059
8060
8061 In this document, the TikZ library \pkg{arrows.meta}
8062 has been loaded, which impacts the shape of the arrow tips.
8063
8064 \bigskip
8065 \begin{Code}
8066 \NiceMatrixOptions{xdots={horizontal-labels,line-style = <->}}
8067 \end{Code}
8068 \begin{Code}[width=11cm]
8069 $\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
8070 \emph{\Hdotsfor{3}^{3}} & \emph{\Hdotsfor{2}^{2}} \\
8071 2 & 1 & 1 & 1 & 1 & \emph{\Vdotsfor{3}^{3}}\\
8072 1 & 1 & 1 & 1 & 1 \\
8073 1 & 1 & 1 & 1 & 1 \\
8074 \Hline
8075 1 & 1 & 1 & 1 & 1 & \emph{\Vdotsfor{2}^{2}} \\
8076 1 & 1 & 1 & 1 & 1 \\
8077 \end{pNiceArray}$
8078 \end{Code}
8079 {\NiceMatrixOptions{xdots={horizontal-labels,line-style = <->}}
8080 $\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
8081 \Hdotsfor{3}^{3} & \Hdotsfor{2}^{2} \\
8082 2 & 1 & 1 & 1 & 1 & \Vdotsfor{3}^{3}\\
8083 1 & 1 & 1 & 1 & 1 \\
8084 1 & 1 & 1 & 1 & 1 \\
8085 \Hline
8086 1 & 1 & 1 & 1 & 1 & \Vdotsfor{2}^{2}\\
8087 1 & 1 & 1 & 1 & 1 \\
8088 \end{pNiceArray}$}
8089
8090
8091 \interitem
8092 \label{ex:colon}
8093 If you want the label \emph{on the line}, you should use the special
8094 token~``|:|'' instead of~``|^|'':
8095
8096 \medskip
8097 \begin{Code}
8098 \NiceMatrixOptions{xdots={horizontal-labels,line-style = <->}}
8099 \end{Code}
8100
8101 \medskip
8102 \begin{Code}[width=11cm]
8103 $\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
8104 \emph{\Hdotsfor{3}:{3}} & \emph{\Hdotsfor{2}:{2}} \\
8105 2 & 1 & 1 & 1 & 1 & \emph{\Vdotsfor{3}:{3}} \\
8106 1 & 1 & 1 & 1 & 1 \\
8107 1 & 1 & 1 & 1 & 1 \\
8108 \Hline
8109 1 & 1 & 1 & 1 & 1 &
8110 \emph{\Vdotsfor{2}:{2 \rlap{ \smash{rows}}}} \\
8111 1 & 1 & 1 & 1 & 1 \\
8112 \end{pNiceArray}$
8113 \end{Code}
8114 {\NiceMatrixOptions{xdots={horizontal-labels,line-style = <->}}
8115 $\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
8116 \Hdotsfor{3}:{3} & \Hdotsfor{2}:{2} \\
8117 2 & 1 & 1 & 1 & 1 & \Vdotsfor{3}:{3}\\
8118 1 & 1 & 1 & 1 & 1 \\
8119 1 & 1 & 1 & 1 & 1 \\
8120 \Hline
8121 1 & 1 & 1 & 1 & 1 & \Vdotsfor{2}:{2 \rlap{ \smash{rows}}}\\
8122 1 & 1 & 1 & 1 & 1 \\
8123 \end{pNiceArray}$}
8124
8125
8126 \bigskip
8127
8128 If one prefers the braces of the library \pkg{decorations.pathreplacing} of TikZ, the
8129 best way is to use the commands |\Hbrace| and |\Vbrace| provided by
8130 \pkg{nicematrix} (cf.~\ref{Hbrace}, p.~\pageref{Hbrace}).
8131
8132 \smallskip
8133 \begin{Verbatim}[formatcom=\footnotesize \color{gray}]
8134 \usepackage{tikz} % in the preamble
8135 \usetikzlibrary{decorations.pathreplacing} % in the preamble
8136 \end{Verbatim}
8137
8138
8139 \medskip
8140 \begin{Code}[width=11cm]
8141 \NiceMatrixOptions{xdots/horizontal-labels}
8142 $\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
8143 \emph{\Hbrace{3}{3}} & \emph{\Hbrace{2}{2}} \\
8144 2 & 1 & 1 & 1 & 1 & \emph{\Vbrace{3}{3}} \\
8145 1 & 1 & 1 & 1 & 1 \\
8146 1 & 1 & 1 & 1 & 1 \\
8147 \Hline
8148 1 & 1 & 1 & 1 & 1 & \emph{\Vbrace{2}{2}} \\
8149 1 & 1 & 1 & 1 & 1 \\
8150 \end{pNiceArray}$
8151 \end{Code}
8152 {\NiceMatrixOptions{xdots/horizontal-labels}
8153 $\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
8154 \Hbrace{3}{3} & \Hbrace{2}{2} \\
8155 2 & 1 & 1 & 1 & 1 & \Vbrace{3}{3}\\
8156 1 & 1 & 1 & 1 & 1 \\
8157 1 & 1 & 1 & 1 & 1 \\
8158 \Hline
8159 1 & 1 & 1 & 1 & 1 & \Vbrace{2}{2}\\
8160 1 & 1 & 1 & 1 & 1 \\
8161 \end{pNiceArray}$}
8162
8163
8164 \bigskip
8165 It's possible to change the TikZ style of those braces by changing the TikZ
8166 style |nicematrix/brace|. In the following example, we use
8167 ``calligraphic'' braces (the TikZ library \pkg{calligraphy} must be loaded \emph{after}
8168 \pkg{decorations.pathreplacing}).
8169
8170 \smallskip
8171 \begin{Verbatim}[formatcom=\footnotesize \color{gray}]
8172 \usepackage{tikz} % in the preamble
8173 \usetikzlibrary{decorations.pathreplacing,calligraphy} % in the preamble
8174 \end{Verbatim}
8175
8176 \medskip
8177 \begin{Code}
8178 \NiceMatrixOptions{xdots/horizontal-labels}
8179 \tikzset
8180 {
8181 nicematrix/brace/.style =
8182 {
8183 decoration =
8184 {
8185 \emph{calligraphic brace} ,
8186 amplitude = 0.4 em ,
8187 raise = -0.25 em
8188 } ,
8189 line width = 0.1 em ,
8190 decorate
8191 }
8192 }
8193 \end{Code}
8194 \begin{Code}[width=11cm]
8195 $\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
8196 \emph{\Hbrace{3}{3}} & \emph{\Hbrace{2}{2}} \\
8197 2 & 1 & 1 & 1 & 1 & \emph{\Vbrace{3}{3}} \\
8198 1 & 1 & 1 & 1 & 1 \\
8199 1 & 1 & 1 & 1 & 1 \\
8200 \Hline
8201 1 & 1 & 1 & 1 & 1 & \emph{\Vbrace{2}{2}} \\
8202 1 & 1 & 1 & 1 & 1 \\
8203 \end{pNiceArray}$
8204 \end{Code}
8205 {\NiceMatrixOptions{xdots/horizontal-labels}
8206 \tikzset
8207 {
8208 nicematrix/brace/.style =
8209 {
8210 decoration =
8211 {
8212 calligraphic brace ,
8213 amplitude = 0.4 em ,
8214 raise = -0.25 em
8215 } ,
8216 line width = 0.1 em ,
8217 decorate
8218 }
8219 }
8220 $\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
8221 \Hbrace{3}{3} & \Hbrace{2}{2} \\
8222 2 & 1 & 1 & 1 & 1 & \Vbrace{3}{3}\\
8223 1 & 1 & 1 & 1 & 1 \\
8224 1 & 1 & 1 & 1 & 1 \\
8225 \Hline
8226 1 & 1 & 1 & 1 & 1 & \Vbrace{2}{2}\\
8227 1 & 1 & 1 & 1 & 1 \\
8228 \end{pNiceArray}$}
8229
8230
8231
8232 \bigskip
8233 If one prefers the curly braces of the current mathematical font of LaTeX, one
8234 should use the commands |\SubMatrix|, |\OverBrace| and |\UnderBrace| in the
8235 |\CodeAfter|.
8236
8237 \medskip
8238 \begin{Code}[width=11cm]
8239 $\begin{pNiceArray}{ccc|cc}[margin,last-col]
8240 2 & 1 & 1 & 1 & 1 & \Block{3-1}{\quad 3} \\
8241 1 & 1 & 1 & 1 & 1 \\
8242 1 & 1 & 1 & 1 & 1 \\
8243 \Hline
8244 1 & 1 & 1 & 1 & 1 & \Block{2-1}{\quad 2} \\
8245 1 & 1 & 1 & 1 & 1 \\
8246 \CodeAfter
8247 \emph{\OverBrace[shorten,yshift=1.5mm]{1-1}{1-3}{3}}
8248 \emph{\OverBrace[shorten,yshift=1.5mm]{1-4}{1-5}{2}}
8249 \emph{\SubMatrix{.}{1-1}{3-5}{\rbrace}[xshift=3.5mm]}
8250 \emph{\SubMatrix{.}{4-1}{5-5}{\rbrace}[xshift=3.5mm]}
8251 \end{pNiceArray}$
8252 \end{Code}
8253 {$\begin{pNiceArray}{ccc|cc}[margin,last-col]
8254 2 & 1 & 1 & 1 & 1 & \Block{3-1}{\quad 3} \\
8255 1 & 1 & 1 & 1 & 1 \\
8256 1 & 1 & 1 & 1 & 1 \\
8257 \Hline
8258 1 & 1 & 1 & 1 & 1 & \Block{2-1}{\quad 2} \\
8259 1 & 1 & 1 & 1 & 1 \\
8260 \CodeAfter
8261 \OverBrace[shorten,yshift=1.5mm]{1-1}{1-3}{3}
8262 \OverBrace[shorten,yshift=1.5mm]{1-4}{1-5}{2}
8263 \SubMatrix{.}{1-1}{3-5}{\rbrace}[xshift=3.5mm]
8264 \SubMatrix{.}{4-1}{5-5}{\rbrace}[xshift=3.5mm]
8265 \end{pNiceArray}$}
8266
8267 \medskip
8268 Or course, the output may seem disappointing. That's why, for this type of use,
8269 we recommend the use of the commands |\Hbrace| and |\Vbrace| (provided by
8270 \pkg{nicematrix}), as shown in the previous examples.
8271
8272
8273
8274 \subsection{Stacks of matrices}
8275
8276 \index{NiceMatrixBlock@\texttt{\{NiceMatrixBlock\}}|textit}
8277
8278 We often need to compose mathematical matrices on top on each other (for
8279 example for the resolution of linear systems).
8280
8281 \medskip
8282 In order to have the columns aligned one above the other, it's possible to
8283 fix a width for all the columns. That's what is done in the following example
8284 with the environment |{NiceMatrixBlock}| and its option |auto-columns-width|.
8285
8286 \medskip
8287 \begin{small}
8288 \begin{Code}
8289 \emph{\begin{NiceMatrixBlock}[auto-columns-width]}
8290 \NiceMatrixOptions
8291 {
8292 light-syntax,
8293 last-col, code-for-last-col = \color{blue}\scriptstyle,
8294 vlines = 5 ,
8295 matrix/columns-type = r ,
8296 no-cell-nodes % only for speedup
8297 }
8298 \setlength{\extrarowheight}{1mm}
8299
8300 \quad $\begin{pNiceMatrix}
8301 12 -8 7 5 3 {} ;
8302 3 -18 12 1 4 ;
8303 -3 -46 29 -2 -15 ;
8304 9 10 -5 4 7
8305 \end{pNiceMatrix}$
8306
8307 \smallskip
8308 \quad $\begin{pNiceMatrix}
8309 12 -8 7 5 3 ;
8310 0 64 -41 1 19 { L_2 \gets L_1-4L_2 } ;
8311 0 -192 123 -3 -57 { L_3 \gets L_1+4L_3 } ;
8312 0 -64 41 -1 -19 { L_4 \gets 3L_1-4L_4 } ;
8313 \end{pNiceMatrix}$
8314
8315 \smallskip
8316 \quad $\begin{pNiceMatrix}
8317 12 -8 7 5 3 ;
8318 0 64 -41 1 19 ;
8319 0 0 0 0 0 { L_3 \gets 3 L_2 + L_3 }
8320 \end{pNiceMatrix}$
8321
8322 \smallskip
8323 \quad $\begin{pNiceMatrix}
8324 12 -8 7 5 3 {} ;
8325 0 64 -41 1 19 ;
8326 \end{pNiceMatrix}$
8327 \emph{\end{NiceMatrixBlock}}
8328 \end{Code}
8329 \end{small}
8330
8331 \medskip
8332 \index{auto-columns-width!(clé de \texttt{\{NiceMatrixBlock\}})|textit}
8333 \begin{NiceMatrixBlock}[auto-columns-width]
8334 \NiceMatrixOptions
8335 {
8336 light-syntax,
8337 last-col, code-for-last-col = \color{blue}\scriptstyle,
8338 vlines = 5 ,
8339 matrix/columns-type = r ,
8340 no-cell-nodes
8341 }
8342 \setlength{\extrarowheight}{1mm}
8343
8344 \quad $\begin{pNiceMatrix}
8345 12 -8 7 5 3 {} ;
8346 3 -18 12 1 4 ;
8347 -3 -46 29 -2 -15 ;
8348 9 10 -5 4 7
8349 \end{pNiceMatrix}$
8350
8351 \smallskip
8352 \quad $\begin{pNiceMatrix}
8353 12 -8 7 5 3 ;
8354 0 64 -41 1 19 { L_2 \gets L_1-4L_2 } ;
8355 0 -192 123 -3 -57 { L_3 \gets L_1+4L_3 } ;
8356 0 -64 41 -1 -19 { L_4 \gets 3L_1-4L_4 } ;
8357 \end{pNiceMatrix}$
8358
8359 \smallskip
8360 \quad $\begin{pNiceMatrix}
8361 12 -8 7 5 3 ;
8362 0 64 -41 1 19 ;
8363 0 0 0 0 0 { L_3 \gets 3 L_2 + L_3 }
8364 \end{pNiceMatrix}$
8365
8366 \smallskip
8367 \quad $\begin{pNiceMatrix}
8368 12 -8 7 5 3 {} ;
8369 0 64 -41 1 19 ;
8370 \end{pNiceMatrix}$
8371 \end{NiceMatrixBlock}
8372
8373 \bigskip
8374 However, one can see that the last matrix is not perfectly aligned with
8375 others. That's because, in LaTeX, the parenthesis have not exactly the same width
8376 (smaller parenthesis are a bit slimer).
8377
8378 \medskip
8379 \index{max-width (subkey of ``delimiters'')}
8380 \index{delimiters!---/max-width}
8381 In order the solve that problem, it's possible to require the delimiters to be
8382 composed with the maximal width, thanks to the boolean key
8383 \Definition{delimiters/max-width}.
8384
8385 \medskip
8386 \begin{small}
8387 \begin{Code}
8388 \emph{\begin{NiceMatrixBlock}[auto-columns-width]}
8389 \NiceMatrixOptions
8390 {
8391 \emph{delimiters/max-width},
8392 light-syntax,
8393 last-col, code-for-last-col = \color{blue}\scriptstyle,
8394 vlines = 5 ,
8395 matrix/columns-type = r ,
8396 no-cell-nodes % only for speedup
8397 }
8398 \setlength{\extrarowheight}{1mm}
8399
8400 \quad $\begin{pNiceMatrix}
8401 12 -8 7 5 3 {} ;
8402 3 -18 12 1 4 ;
8403 -3 -46 29 -2 -15 ;
8404 9 10 -5 4 7
8405 \end{pNiceMatrix}$
8406 ...
8407 \emph{\end{NiceMatrixBlock}}
8408 \end{Code}
8409 \end{small}
8410
8411 \medskip
8412 \begin{NiceMatrixBlock}[auto-columns-width]
8413 \NiceMatrixOptions
8414 {
8415 delimiters/max-width,
8416 light-syntax,
8417 last-col, code-for-last-col = \color{blue}\scriptstyle,
8418 vlines = 5 ,
8419 matrix/columns-type = r ,
8420 no-cell-nodes
8421 }
8422 \setlength{\extrarowheight}{1mm}
8423
8424 \quad $\begin{pNiceMatrix}
8425 12 -8 7 5 3 {} ;
8426 3 -18 12 1 4 ;
8427 -3 -46 29 -2 -15 ;
8428 9 10 -5 4 7
8429 \end{pNiceMatrix}$
8430
8431 \smallskip
8432 \quad $\begin{pNiceMatrix}
8433 12 -8 7 5 3 ;
8434 0 64 -41 1 19 { L_2 \gets L_1-4L_2 } ;
8435 0 -192 123 -3 -57 { L_3 \gets L_1+4L_3 } ;
8436 0 -64 41 -1 -19 { L_4 \gets 3L_1-4L_4 } ;
8437 \end{pNiceMatrix}$
8438
8439 \smallskip
8440 \quad $\begin{pNiceMatrix}
8441 12 -8 7 5 3 ;
8442 0 64 -41 1 19 ;
8443 0 0 0 0 0 { L_3 \gets 3 L_2 + L_3 }
8444 \end{pNiceMatrix}$
8445
8446 \smallskip
8447 \quad $\begin{pNiceMatrix}
8448 12 -8 7 5 3 {} ;
8449 0 64 -41 1 19 ;
8450 \end{pNiceMatrix}$
8451 \end{NiceMatrixBlock}
8452
8453
8454 \interitem
8455 If you wish an alignment of the different matrices without the same width
8456 for all the columns, you can construct a unique array and place the
8457 parenthesis with commands |\SubMatrix| in the |\CodeAfter|. Of course, that
8458 array can't be broken by a page break.
8459
8460 \medskip
8461 \index{SubMatrix@\texttt{\textbackslash SubMatrix} (command of
8462 \texttt{\textbackslash CodeAfter}\newline and
8463 \texttt{\textbackslash CodeBefore})|textit}
8464
8465 \begin{Code}
8466 \setlength{\extrarowheight}{1mm}
8467 \[\begin{NiceMatrix}[r, last-col=6, code-for-last-col = \scriptstyle \color{blue}]
8468 12 & -8 & 7 & 5 & 3 \\
8469 3 & -18 & 12 & 1 & 4 \\
8470 -3 & -46 & 29 &-2 &-15 \\
8471 9 & 10 &-5 &4 & 7 \\[1mm]
8472 12 & -8 & 7 &5 & 3 \\
8473 0 & 64 &-41 & 1 & 19 & L_2 \gets L_1-4L_2 \\
8474 0 & -192 &123 &-3 &-57 & L_3 \gets L_1+4L_3 \\
8475 0 & -64 & 41 &-1 &-19 & L_4 \gets 3L_1-4L_4 \\[1mm]
8476 12 & -8 &7 &5 & 3 \\
8477 0 & 64 &-41 &1 &19 \\
8478 0 & 0 &0 &0 & 0 & L_3 \gets 3L_2+L_3 \\[1mm]
8479 12 & -8 &7 &5 & 3 \\
8480 0 & 64 &-41 & 1 & 19 \\
8481 \emph{\CodeAfter [sub-matrix/vlines=4]
8482 \SubMatrix({1-1}{4-5})
8483 \SubMatrix({5-1}{8-5})
8484 \SubMatrix({9-1}{11-5})
8485 \SubMatrix({12-1}{13-5})}
8486 \end{NiceMatrix}\]
8487 \end{Code}
8488
8489 \medskip
8490 \begin{scope}
8491 \setlength{\extrarowheight}{1mm}
8492 \[\begin{NiceMatrix}[ r, last-col=6, code-for-last-col = \scriptstyle \color{blue} ]
8493 12 & -8 & 7 & 5 & 3 \\
8494 3 & -18 & 12 & 1 & 4 \\
8495 -3 & -46 & 29 &-2 &-15 \\
8496 9 & 10 &-5 &4 & 7 \\[1mm]
8497 12 & -8 & 7 &5 & 3 \\
8498 0 & 64 &-41 & 1 & 19 & L_2 \gets L_1-4L_2 \\
8499 0 & -192 &123 &-3 &-57 & L_3 \gets L_1+4L_3 \\
8500 0 & -64 & 41 &-1 &-19 & L_4 \gets 3L_1-4L_4 \\[1mm]
8501 12 & -8 &7 &5 & 3 \\
8502 0 & 64 &-41 &1 &19 \\
8503 0 & 0 &0 &0 & 0 & L_3 \gets 3L_2+L_3 \\[1mm]
8504 12 & -8 &7 &5 & 3 \\
8505 0 & 64 &-41 & 1 & 19 \\
8506 \CodeAfter [sub-matrix/vlines=4]
8507 \SubMatrix({1-1}{4-5})
8508 \SubMatrix({5-1}{8-5})
8509 \SubMatrix({9-1}{11-5})
8510 \SubMatrix({12-1}{13-5})
8511 \end{NiceMatrix}\]
8512 \end{scope}
8513
8514 \bigskip
8515 In this tabular, the instructions |\SubMatrix| are executed after the
8516 composition of the tabular and, thus, the vertical rules are drawn without
8517 adding space between the columns.
8518
8519
8520 \bigskip
8521 In fact, it's possible, with the key \Definition{vlines-in-sub-matrix}, to
8522 choice a letter in the preamble of the array to specify vertical rules which
8523 will be drawn in the |\SubMatrix| only (and it will add space between the columns
8524 for that rule).
8525
8526 \index{vlines-in-sub-matrix}
8527 \medskip
8528 \begin{Code}
8529 \setlength{\extrarowheight}{1mm}
8530 \[\begin{NiceArray}
8531 [
8532 \emph{vlines-in-sub-matrix = I},
8533 last-col,
8534 code-for-last-col = \scriptstyle \color{blue}
8535 ]
8536 {rrrrIr}
8537 12 & -8 & 7 & 5 & 3 \\
8538 3 & -18 & 12 & 1 & 4 \\
8539 -3 & -46 & 29 &-2 &-15 \\
8540 9 & 10 &-5 &4 & 7 \\[1mm]
8541 12 & -8 & 7 &5 & 3 \\
8542 0 & 64 &-41 & 1 & 19 & L_2 \gets L_1-4L_2 \\
8543 0 & -192 &123 &-3 &-57 & L_3 \gets L_1+4L_3 \\
8544 0 & -64 & 41 &-1 &-19 & L_4 \gets 3L_1-4L_4 \\[1mm]
8545 12 & -8 &7 &5 & 3 \\
8546 0 & 64 &-41 &1 &19 \\
8547 0 & 0 &0 &0 & 0 & L_3 \gets 3L_2+L_3 \\[1mm]
8548 12 & -8 &7 &5 & 3 \\
8549 0 & 64 &-41 & 1 & 19 \\
8550 \CodeAfter
8551 \SubMatrix({1-1}{4-5})
8552 \SubMatrix({5-1}{8-5})
8553 \SubMatrix({9-1}{11-5})
8554 \SubMatrix({12-1}{13-5})
8555 \end{NiceArray}\]
8556 \end{Code}
8557
8558
8559 \medskip
8560 \begin{scope}
8561 \setlength{\extrarowheight}{1mm}
8562 \[\begin{NiceArray}
8563 [
8564 vlines-in-sub-matrix=I,
8565 last-col,
8566 code-for-last-col = \scriptstyle \color{blue}
8567 ]
8568 {rrrrIr}
8569 12 & -8 & 7 & 5 & 3 \\
8570 3 & -18 & 12 & 1 & 4 \\
8571 -3 & -46 & 29 &-2 &-15 \\
8572 9 & 10 &-5 &4 & 7 \\[1mm]
8573 12 & -8 & 7 &5 & 3 \\
8574 0 & 64 &-41 & 1 & 19 & L_2 \gets L_1-4L_2 \\
8575 0 & -192 &123 &-3 &-57 & L_3 \gets L_1+4L_3 \\
8576 0 & -64 & 41 &-1 &-19 & L_4 \gets 3L_1-4L_4 \\[1mm]
8577 12 & -8 &7 &5 & 3 \\
8578 0 & 64 &-41 &1 &19 \\
8579 0 & 0 &0 &0 & 0 & L_3 \gets 3L_2+L_3 \\[1mm]
8580 12 & -8 &7 &5 & 3 \\
8581 0 & 64 &-41 & 1 & 19 \\
8582 \CodeAfter
8583 \SubMatrix({1-1}{4-5})
8584 \SubMatrix({5-1}{8-5})
8585 \SubMatrix({9-1}{11-5})
8586 \SubMatrix({12-1}{13-5})
8587 \end{NiceArray}\]
8588 \end{scope}
8589
8590
8591
8592
8593
8594 \subsection{How to highlight cells of a matrix}
8595
8596
8597 \label{highlight}
8598 \index{draw (key of \texttt{\textbackslash Block})|textit}
8599
8600 \medskip
8601 In order to highlight a cell of a matrix, it's possible to ``draw'' that cell
8602 with the key |draw| of the command |\Block| (this is one of the uses of a
8603 mono-cell block\footnote{We recall that, if the first mandatory argument of
8604 the command |\Block| is left empty, that means that the block is a mono-cell block.}).
8605
8606 \label{example-CodeAfter}
8607
8608 \medskip
8609 \begin{Code}
8610 $\begin{pNiceArray}{>{\strut}cccc}[margin,rules/color=blue,no-cell-nodes]
8611 \emph{\Block[draw]{}{a_{11}}} & a_{12} & a_{13} & a_{14} \\
8612 a_{21} & \emph{\Block[draw]{}{a_{22}}} & a_{23} & a_{24} \\
8613 a_{31} & a_{32} & \emph{\Block[draw]{}{a_{33}}} & a_{34} \\
8614 a_{41} & a_{42} & a_{43} & \emph{\Block[draw]{}{a_{44}}} \\
8615 \end{pNiceArray}$
8616 \end{Code}
8617 \[\begin{pNiceArray}{>{\strut}cccc}[margin,rules/color=blue,no-cell-nodes]
8618 \Block[draw]{}{a_{11}} & a_{12} & a_{13} & a_{14} \\
8619 a_{21} & \Block[draw]{}{a_{22}} & a_{23} & a_{24} \\
8620 a_{31} & a_{32} & \Block[draw]{}{a_{33}} & a_{34} \\
8621 a_{41} & a_{42} & a_{43} & \Block[draw]{}{a_{44}} \\
8622 \end{pNiceArray}\]
8623
8624 We should remark that the rules we have drawn are drawn \emph{after} the
8625 construction of the array and thus, they don't spread the cells of the array.
8626 We recall that, on the other side, the commands |\hline| and |\Hline|, the
8627 specifier ``\verb+|+'' and the options |hlines|, |vlines|, |hvlines|,
8628 |hvlines-except-borders| and |hlines-except-borders| spread the
8629 cells.\footnote{For the command |\cline|, see the remark in the
8630 section~\ref{remark-cline}, p.~\pageref{remark-cline}.}
8631
8632
8633 \vspace{1cm}
8634 It's possible to color a row with |\rowcolor| in the |\CodeBefore|, or with
8635 |\rowcolor| in the first cell of the row (if used in another cell of the row
8636 |\rowcolor| will color till the end of the row).
8637
8638 \index{rowcolor@\texttt{\textbackslash rowcolor}!command in tabular|textit}
8639
8640
8641 \medskip
8642 \begin{Code}
8643 \begin{pNiceArray}{>{\strut}cccc}% <-- % mandatory
8644 [margin, extra-margin=2pt,no-cell-nodes]
8645 \emph{\rowcolor{red!15}}A_{11} & A_{12} & A_{13} & A_{14} \\
8646 A_{21} & \emph{\rowcolor{red!15}}A_{22} & A_{23} & A_{24} \\
8647 A_{31} & A_{32} & \emph{\rowcolor{red!15}}A_{33} & A_{34} \\
8648 A_{41} & A_{42} & A_{43} & \emph{\rowcolor{red!15}}A_{44}
8649 \end{pNiceArray}
8650 \end{Code}
8651
8652 \[\begin{pNiceArray}{>{\strut}cccc}[margin, extra-margin=2pt,no-cell-nodes]
8653 \rowcolor{red!15}A_{11} & A_{12} & A_{13} & A_{14} \\
8654 A_{21} & \rowcolor{red!15}A_{22} & A_{23} & A_{24} \\
8655 A_{31} & A_{32} & \rowcolor{red!15}A_{33} & A_{34} \\
8656 A_{41} & A_{42} & A_{43} & \rowcolor{red!15}A_{44}
8657 \end{pNiceArray}\]
8658
8659 \bigskip
8660 However, it's not possible to do a fine tuning. That's why we describe now a
8661 method to highlight a row of the matrix.
8662
8663 \medskip
8664 That example and the following ones require TikZ (by default, \pkg{nicematrix}
8665 only loads \textsc{pgf}, which is a sub-layer of TikZ) and the TikZ library
8666 |fit|.
8667
8668 \smallskip
8669 \begin{Verbatim}[formatcom=\footnotesize \color{gray}]
8670 \usepackage{tikz} % in the preamble
8671 \usetikzlibrary{fit}
8672 \end{Verbatim}
8673
8674 \medskip
8675 We create a rectangular TikZ node which encompasses the nodes of the second
8676 row by using the tools of the TikZ library \pkg{fit}. Those nodes are not
8677 available by default in the |\CodeBefore| (for efficiency). We have to require
8678 their creation with the key |create-cell-nodes| of the keyword |\CodeBefore|.
8679
8680 \tikzset{highlight/.style={rectangle,
8681 fill=red!15,
8682 rounded corners = 0.5 mm,
8683 inner sep=1pt,
8684 fit = #1}}
8685
8686 \medskip
8687 \index{highlight (TikZ style defined in\newline an example)|textit}
8688 \begin{Code}
8689 \tikzset{highlight/.style={rectangle,
8690 fill=red!15,
8691 rounded corners = 0.5 mm,
8692 inner sep=1pt,
8693 fit=#1}}
8694
8695 $\begin{bNiceMatrix}
8696 \emph{\CodeBefore [create-cell-nodes]
8697 \tikz \node [highlight = (2-1) (2-last)] {} ;
8698 \Body}
8699 0 & \Cdots & 0 \\
8700 1 & \Cdots & 1 \\
8701 0 & \Cdots & 0 \\
8702 \end{bNiceMatrix}$
8703 \end{Code}
8704 \index{create-cell-nodes (key of \texttt{\textbackslash CodeBefore})|textit}
8705 \index{CodeBefore@\texttt{\textbackslash CodeBefore}...\texttt{\textbackslash Body}|textit}
8706
8707 \[\begin{bNiceMatrix}
8708 \CodeBefore [create-cell-nodes]
8709 \tikz \node [highlight = (2-1) (2-last)] {} ;
8710 \Body
8711 0 & \Cdots & 0 \\
8712 1 & \Cdots & 1 \\
8713 0 & \Cdots & 0 \\
8714 \end{bNiceMatrix}\]
8715
8716
8717 \vspace{1cm}
8718 We consider now the following matrix. If we want to highlight each row of
8719 this matrix, we can use the previous technique three times.
8720
8721 \medskip
8722 \begin{Code}
8723 \begin{pNiceArray}{ccc}[last-col, margin = 2pt]
8724 \CodeBefore [create-cell-nodes]
8725 \begin{tikzpicture}
8726 \emph{\node [highlight = (1-1) (1-last)] {} ;
8727 \node [highlight = (2-1) (2-last)] {} ;
8728 \node [highlight = (3-1) (3-last)] {} ;}
8729 \end{tikzpicture}
8730 \Body
8731 a & a + b & a + b + c & L_1 \\
8732 a & a & a + b & L_2 \\
8733 a & a & a & L_3
8734 \end{pNiceArray}
8735 \end{Code}
8736
8737
8738 \[\begin{pNiceArray}{ccc}[last-col, margin = 2pt]
8739 \CodeBefore [create-cell-nodes]
8740 \begin{tikzpicture}
8741 \node [highlight = (1-1) (1-last)] {} ;
8742 \node [highlight = (2-1) (2-last)] {} ;
8743 \node [highlight = (3-1) (3-last)] {} ;
8744 \end{tikzpicture}
8745 \Body
8746 a & a + b & a + b + c & L_1 \\
8747 a & a & a + b & L_2 \\
8748 a & a & a & L_3
8749 \end{pNiceArray}\]
8750
8751 \medskip
8752 The result may seem disappointing. We can improve it by using the ``medium
8753 nodes'' instead of the ``normal nodes''.
8754
8755 \index{create-medium-nodes|textit}
8756 \index{create-cell-nodes (key of \texttt{\textbackslash CodeBefore})|textit}
8757
8758
8759 \begin{Code}
8760 \[\begin{pNiceArray}{ccc}[last-col, margin = 2pt, create-medium-nodes]
8761 \CodeBefore [create-cell-nodes]
8762 \begin{tikzpicture} \emph{[name suffix = -medium]}
8763 \node [highlight = (1-1) (1-last)] {} ;
8764 \node [highlight = (2-1) (2-last)] {} ;
8765 \node [highlight = (3-1) (3-last)] {} ;
8766 \end{tikzpicture}
8767 \Body
8768 a & a + b & a + b + c & L_1 \\
8769 a & a & a + b & L_2 \\
8770 a & a & a & L_3
8771 \end{pNiceArray}\]
8772 \end{Code}
8773
8774
8775 \[\begin{pNiceArray}{ccc}[last-col, margin = 2pt, create-medium-nodes]
8776 \CodeBefore [create-cell-nodes]
8777 \begin{tikzpicture} [name suffix = -medium]
8778 \node [highlight = (1-1) (1-last)] {} ;
8779 \node [highlight = (2-1) (2-last)] {} ;
8780 \node [highlight = (3-1) (3-last)] {} ;
8781 \end{tikzpicture}
8782 \Body
8783 a & a + b & a + b + c & L_1 \\
8784 a & a & a + b & L_2 \\
8785 a & a & a & L_3
8786 \end{pNiceArray}\]
8787
8788
8789
8790
8791 \subsection{Use of \texttt{\textbackslash SubMatrix} in the \texttt{\textbackslash CodeBefore}}
8792
8793 \label{submatrix-in-codebefore}
8794
8795 \index{SubMatrix@\texttt{\textbackslash SubMatrix} (command of
8796 \texttt{\textbackslash CodeAfter}\newline and
8797 \texttt{\textbackslash CodeBefore})|textit}
8798 \index{CodeBefore@\texttt{\textbackslash CodeBefore}...\texttt{\textbackslash Body}|textit}
8799 \index{CodeAfter@\texttt{\textbackslash CodeAfter}|textit}
8800 \index{create-cell-nodes (key of \texttt{\textbackslash CodeBefore})|textit}
8801
8802
8803 In the following example, we illustrate the mathematical product of two
8804 matrices.
8805
8806 The whole figure is an environment |{NiceArray}| and the three pairs of
8807 parenthesis have been added with |\SubMatrix| in the |\CodeBefore| (since you have put
8808 these |\SubMatrix| in the |\CodeBefore| --- and not the |\CodeAfter| --- the dotted leaders
8809 specified in the the matrix product $C$ will be limited to that matrix).
8810
8811 \tikzset{highlight/.style={rectangle,
8812 fill=red!15,
8813 rounded corners = 0.5 mm,
8814 inner sep=1pt,
8815 fit=#1}}%
8816 \[\begin{NiceArray}{*{6}{c}@{\hspace{6mm}}*{5}{c}}[xdots/nullify]
8817 \CodeBefore [create-cell-nodes]
8818 \SubMatrix({2-7}{6-last})
8819 \SubMatrix({7-2}{last-6})
8820 \SubMatrix({7-7}{last-last})
8821 \begin{tikzpicture}
8822 \node [highlight = (9-2) (9-6)] { } ;
8823 \node [highlight = (2-9) (6-9)] { } ;
8824 \end{tikzpicture}
8825 \Body
8826 & & & & & & & & \color{blue}\scriptstyle C_j \\
8827 & & & & & & b_{11} & \Cdots & b_{1j} & \Cdots & b_{1n} \\
8828 & & & & & & \Vdots & & \Vdots & & \Vdots \\
8829 & & & & & & & & b_{kj} \\
8830 & & & & & & & & \Vdots \\
8831 & & & & & & b_{n1} & \Cdots & b_{nj} & \Cdots & b_{nn} \\[3mm]
8832 & a_{11} & \Cdots & & & a_{1n} \\
8833 & \Vdots & & & & \Vdots & & & \Vdots \\
8834 \color{blue}\scriptstyle L_i
8835 & a_{i1} & \Cdots & a_{ik} & \Cdots & a_{in} & \Cdots & & c_{ij} \\
8836 & \Vdots & & & & \Vdots \\
8837 & a_{n1} & \Cdots & & & a_{nn} \\
8838 \CodeAfter
8839 \tikz \draw [gray,shorten > = 1mm, shorten < = 1mm] (9-4.north) to [bend left] (4-9.west) ;
8840 \end{NiceArray}\]
8841
8842
8843 \vspace{1cm}
8844 \begin{Verbatim}
8845 \tikzset{highlight/.style={rectangle,
8846 fill=red!15,
8847 rounded corners = 0.5 mm,
8848 inner sep=1pt,
8849 fit=~#1}}
8850 \end{Verbatim}
8851
8852 \begin{footnotesize}
8853 \begin{Code}
8854 \[\begin{NiceArray}{*{6}{c}@{\hspace{6mm}}*{5}{c}}[xdots/nullify]
8855 \CodeBefore [create-cell-nodes]
8856 \SubMatrix({2-7}{6-last})
8857 \SubMatrix({7-2}{last-6})
8858 \SubMatrix({7-7}{last-last})
8859 \begin{tikzpicture}
8860 \node [highlight = (9-2) (9-6)] { } ;
8861 \node [highlight = (2-9) (6-9)] { } ;
8862 \end{tikzpicture}
8863 \Body
8864 & & & & & & & & \color{blue}\scriptstyle C_j \\
8865 & & & & & & b_{11} & \Cdots & b_{1j} & \Cdots & b_{1n} \\
8866 & & & & & & \Vdots & & \Vdots & & \Vdots \\
8867 & & & & & & & & b_{kj} \\
8868 & & & & & & & & \Vdots \\
8869 & & & & & & b_{n1} & \Cdots & b_{nj} & \Cdots & b_{nn} \\[3mm]
8870 & a_{11} & \Cdots & & & a_{1n} \\
8871 & \Vdots & & & & \Vdots & & & \Vdots \\
8872 \color{blue}\scriptstyle L_i
8873 & a_{i1} & \Cdots & a_{ik} & \Cdots & a_{in} & \Cdots & & c_{ij} \\
8874 & \Vdots & & & & \Vdots \\
8875 & a_{n1} & \Cdots & & & a_{nn} \\
8876 \CodeAfter
8877 \tikz \draw [gray,shorten > = 1mm, shorten < = 1mm] (9-4.north) to [bend left] (4-9.west) ;
8878 \end{NiceArray}\]
8879 \end{Code}
8880 \end{footnotesize}
8881
8882
8883
8884 \subsection{A triangular tabular}
8885
8886 \label{triangular}
8887
8888 \index{pgf-node-code|textit}
8889 \index{Corners (the empty ---)|textit}
8890 \index{chessboardcolors@\texttt{\textbackslash chessboardcolors}!(commande
8891 du \texttt{\textbackslash CodeBefore})|textit}
8892 \index{CodeBefore@\texttt{\textbackslash CodeBefore}...\texttt{\textbackslash Body}|textit}
8893
8894 In the following example, we use the style PGF/TikZ |nicematrix/cell-node|
8895 to rotate the contents of the cells (and, then, we compensate that rotation by
8896 a rotation of the whole tabular with the command |\adjustbox| of the eponymous
8897 package, which must be loaded previously).
8898
8899
8900 \medskip
8901 \begin{Code}
8902 \pgfset
8903 {
8904 \emph{nicematrix/cell-node}/.append style =
8905 { text/rotate = 45, minimum size = 6 mm }
8906 }
8907
8908 \setlength{\tabcolsep}{0pt}
8909
8910 \emph{\adjustbox}{rotate = -45, set depth = 6mm + 1.414 \arrayrulewidth}
8911 {\begin{NiceTabular} [ hvlines, corners=SE, baseline = line-9 ] { cccccccc }
8912 \CodeBefore
8913 \chessboardcolors{red!15}{blue!15}
8914 \Body
8915 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
8916 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
8917 1 & 3 & 6 & 10 & 15 & 21 \\
8918 1 & 4 & 10 & 20 & 35 \\
8919 1 & 5 & 15 & 35 \\
8920 1 & 6 & 21 \\
8921 1 & 7 \\
8922 1
8923 \end{NiceTabular}}
8924 \end{Code}
8925
8926
8927 \begin{center}
8928 \pgfset
8929 {
8930 nicematrix/cell-node/.append style =
8931 { text/rotate = 45, minimum size = 6 mm }
8932 }%
8933 \setlength{\tabcolsep}{0pt}%
8934 \adjustbox{rotate = -45, set depth = 6mm + 1.414 \arrayrulewidth}
8935 {\begin{NiceTabular} [ hvlines, corners=SE, baseline = line-9 ] { cccccccc }
8936 \CodeBefore
8937 \chessboardcolors{red!15}{blue!15}
8938 \Body
8939 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
8940 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
8941 1 & 3 & 6 & 10 & 15 & 21 \\
8942 1 & 4 & 10 & 20 & 35 \\
8943 1 & 5 & 15 & 35 \\
8944 1 & 6 & 21 \\
8945 1 & 7 \\
8946 1
8947 \end{NiceTabular}}
8948 \end{center}
8949
8950 \medskip
8951 Of course, if you have to draw many diagrams like this one, you should consider using a
8952 dedicated package, such as \pkg{atableau}.
8953
8954
8955 \newpage
8956 \vspace{1cm}
8957 \section{History}
8958
8959 The development of the package \pkg{nicematrix} is done in the following GitHub
8960 depot:
8961
8962 \nobreak
8963 \nolinkurl{https://github.com/fpantigny/nicematrix}
8964
8965 \medskip
8966 The successive versions of the file |nicematrix.sty| provided by TeX Live are
8967 also available on the
8968 \textsc{svn} server of TeX Live:
8969
8970 \nobreak
8971 \smallskip
8972 {
8973 \small
8974 \nolinkurl{https:www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty}
8975 }
8976
8977
8978 \subsection*{Changes between version 7.8 and 7.9}
8979
8980 New keys |default-line| and |rules/fix-vertex|
8981
8982 \subsection*{Changes between version 7.7 and 7.8}
8983
8984 New key |draw-trees-in-col| (and keys |trees/color|, |trees/line-width| and
8985 |trees/rounded-corners|)
8986
8987 \subsection*{Changes between version 7.6 and 7.7}
8988
8989 New commands |\hdashedline|, |\cdashedline| and the letter |;|
8990
8991 New key |notes/no-print| and new command |\NiceTabularNotes|
8992
8993
8994 \subsection*{Changes between version 7.5 and 7.6}
8995
8996 New key |create-blocks-in-col|
8997
8998 \smallskip
8999 An ``additive syntax'' has been added for several keys: |cell-space-limits|,
9000 |xdots/brace-shift|, |xdots/shorten|, |notes/code-before|, |code-for-first-row|, etc.
9001
9002 That means that it's possible to write, for example :\enskip
9003 |cell-space-limits += 3pt|.
9004
9005 \subsection*{Changes between version 7.4 and 7.5}
9006
9007 New key |brace-shift| for the commands |\Hbrace| and |\Vbrace|.
9008
9009 \subsection*{Changes between version 7.3 and 7.4}
9010
9011 Negative values are now allowed for the keys |hlines| and |vlines|.
9012
9013
9014 \subsection*{Changes between version 7.2 and 7.3}
9015
9016 Simplification of the code by using the latest version of LaTeX : 2025-06-01
9017
9018 \subsection*{Changes between version 7.1 and 7.2}
9019
9020 A new key |V| is available in the columns of type |X|.
9021
9022 \subsection*{Changes between version 7.0 and 7.1}
9023
9024 New commands |\Hbrace| and |\Vbrace|.
9025
9026 New commands |\EmptyColumn| and |\EmptyRow| in the |\CodeBefore|.
9027
9028 \subsection*{Changes between version 6.29 and 7.0}
9029
9030 The package \pkg{nicematrix} is now compatible (for the tabulars) with the
9031 Tagging Project.
9032
9033 \subsection*{Changes between version 6.28 and 6.29}
9034
9035 Modification in order to be compatible with the next version of \pkg{array}
9036 (v. 2.6g).
9037
9038 \subsection*{Changes between version 6.27 and 6.28}
9039
9040 Sub-blocks with the character |&| (when the key |ampersand-in-block| is in
9041 force).
9042
9043 Keys |p| and |j| for the command |\Block|.
9044
9045 PGF nodes i.1, i.2, i.3, etc.
9046
9047 \subsection*{Changes between version 6.26 and 6.27}
9048
9049 New key |light-syntax-expanded|.
9050
9051 \subsection*{Changes between version 6.25 and 6.26}
9052
9053 Special color |nocolor|.
9054
9055 \subsection*{Changes between version 6.24 and 6.25}
9056
9057 Correction of several bugs.
9058
9059 An instruction |\rowlistcolors| in the tabular stops the effect of a previous
9060 |\rowlistcolors|.
9061
9062
9063 \subsection*{Changes between version 6.23 and 6.24}
9064
9065 New command |\TikzEveryCell| available in the |\CodeAfter| and the |\CodeBefore|
9066 to apply the same TikZ instruction to all the cells and blocks of the array.
9067
9068 New key |offset| in the key |tikz| of a command |\Block|.
9069
9070
9071 \subsection*{Changes between version 6.22 and 6.23}
9072
9073 The specifier ``\verb+|+'' in the preambles of the environments has now an
9074 optional argument.
9075
9076 Correction of several bugs.
9077
9078 \subsection*{Changes between version 6.21 and 6.22}
9079
9080 Key |opacity| for the command |\Block|.
9081
9082 It's now possible to put a label on a ``continuous dotted line'' with the
9083 specifier ``|:|''.
9084
9085
9086 \subsection*{Changes between version 6.20a and 6.21}
9087
9088 Key |c| for the command |\tabularnote|.
9089
9090 New commands |\rowcolors| and |\rowlistcolors| available in the array itself
9091 (previously, there were only two commands |\rowcolors| and |\rowlistcolors|
9092 available in the |\CodeBefore|.
9093
9094
9095 \subsection*{Changes between version 6.20 and 6.20a}
9096
9097 The value of the key |name| of an environment of \pkg{nicematrix} is expanded
9098 (in the TeX sens).
9099
9100 The labels of the tabular notes (created by the command |\tabularnote|) are now
9101 composed in an overlapping position \emph{only} when the horizontal alignment
9102 mode of the column is |c| or |r|.
9103
9104 \subsection*{Changes between version 6.19 and 6.20}
9105
9106 New key |xdots/horizontal-labels|.
9107
9108 \subsection*{Changes between version 6.18 and 6.19}
9109
9110 The command |\tabularnote| now supports an optional argument (between square
9111 brackets) to change the symbol of the reference of the note.
9112
9113 \subsection*{Changes between version 6.17 and 6.18}
9114
9115 New key |opacity| in the commands to color cells, rows and columns.
9116
9117 New key |rounded-corners| for a whole tabular.
9118
9119
9120 \subsection*{Changes between version 6.16 and 6.17}
9121
9122 New PGF/TikZ style |nicematrix/cell-node|.
9123
9124 New key |pgf-node-code|
9125
9126 \subsection*{Changes between version 6.15 and 6.16}
9127
9128 It's now possible to put any LaTeX extensible delimiter (|\lgroup|, |\langle|,
9129 etc.) in the preamble of an environment with preamble (such as |{NiceArray}|)
9130 by prefixing them by |\left| and |\right|.
9131
9132 New key |code| for the command |\SubMatrix| in the |\CodeAfter|.
9133
9134 \subsection*{Changes between version 6.14 and 6.15}
9135
9136 New key |transparent| for the command |\Block| (with that key, the rules are
9137 drawn within the block).
9138
9139 \subsection*{Changes between version 6.13 and 6.14}
9140
9141 New keys for the command |\Block| for the vertical position of the content of
9142 that block.
9143
9144 \subsection*{Changes between version 6.12 and 6.13}
9145
9146 New environment |{TabularNote}| in |{NiceTabular}| with the same semantic as
9147 the key |tabularnote| (for legibility).
9148
9149 The command |\Hline| nows accepts options (between square brackets).
9150
9151 \subsection*{Changes between version 6.11 and 6.12}
9152
9153 New keys |caption|, |short-caption| and |label| in the environment
9154 |{NiceTabular}|.
9155
9156 In |{NiceTabular}|, a caption specified by the key |caption| is wrapped to the
9157 width of the tabular.
9158
9159 Correction of a bug: it's now possible to use |\OverBrace| and |\UnderBrace|
9160 with \pkg{unicode-math} (with XeLaTeX or LuaLaTeX).
9161
9162 \subsection*{Changes between version 6.10 and 6.11}
9163
9164 New key |matrix/columns-type| to specify the type of columns of the matrices.
9165
9166 New key |ccommand| in |custom-line| and new command |\cdottedline|.
9167
9168 \subsection*{Changes between version 6.9 and 6.10}
9169
9170 New keys |xdots/shorten-start| and |xdots/shorten-end|.
9171
9172 It's possible to use |\line| in the |\CodeAfter| between two blocks (and not
9173 only two cells).
9174
9175 \subsection*{Changes between version 6.8 and 6.9}
9176
9177 New keys |xdots/radius| and |xdots/inter| for customisation of the continuous
9178 dotted lines.
9179
9180 New command |\ShowCellNames| available in the |\CodeBefore| and in the |\CodeAfter|.
9181
9182 \subsection*{Changes between version 6.7 and 6.8}
9183
9184 In the notes of a tabular (with the command |\tabularnote|), the duplicates
9185 are now detected: when several commands |\tabularnote| are used with the same
9186 argument, only one note is created at the end of the tabular (but all the
9187 labels are present, of course).
9188
9189 \subsection*{Changes between version 6.6 and 6.7}
9190
9191 Key |color| for |\OverBrace| and |\UnderBrace| in the |\CodeAfter|
9192
9193 Key |tikz| in the key |borders| of a command |\Block|
9194
9195 \subsection*{Changes between version 6.5 and 6.6}
9196
9197 Keys |tikz| and |width| in |custom-line|.
9198
9199 \subsection*{Changes between versions 6.4 and 6.5}
9200
9201 Key |custom-line| in |\NiceMatrixOptions|.
9202
9203 Key |respect-arraystretch|.
9204
9205 \subsection*{Changes between versions 6.3 and 6.4}
9206
9207 New commands |\UnderBrace| and |\OverBrace| in the |\CodeAfter|.
9208
9209 Correction of a bug of the key |baseline| (cf. question 623258 on TeX StackExchange).
9210
9211 Correction of a bug with the columns |V| of \pkg{varwidth}.
9212
9213 Correction of a bug: the use of |\hdottedline| and |:| in the preamble of the
9214 array (or another letter specified by |letter-for-dotted-lines|) was
9215 incompatible with the key |xdots/line-style|.
9216
9217 \subsection*{Changes between versions 6.2 and 6.3}
9218
9219 Keys |nb-rows|, |rowcolor| and |bold| for the command |\RowStyle|
9220
9221 Key |name| for the command |\Block|.
9222
9223 Support for the columns |V| of \pkg{varwidth}.
9224
9225 \subsection*{Changes between versions 6.1 and 6.2}
9226
9227 Better compatibility with the classes \cls{revtex4-1} (deprecated) and \cls{revtex4-2}.
9228
9229 Key |vlines-in-sub-matrix|.
9230
9231 \subsection*{Changes between versions 6.0 and 6.1}
9232
9233 Better computation of the widths of the |X| columns.
9234
9235 Key |\color| for the command |\RowStyle|.
9236
9237 \cleardoublepage
9238
9239 \phantomsection
9240 \addcontentsline{toc}{section}{Index}
9241
9242 \printindex
9243
9244
9245 \end{document}
9246
9247 % \endinput
9248 % Local Variables:
9249 % LaTeX-verbatim-environments-local: ("Code")
9250 % fill-column: 80
9251 % End:
9252
9253