-
Notifications
You must be signed in to change notification settings - Fork 1
/
nicematrix.tex
8010 lines (6638 loc) · 254 KB
/
nicematrix.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% -*- coding: utf-8 ; -*- This file should be compiled with LuaLaTeX only
\documentclass[dvipsnames]{article}% dvipsnames is for xcolor (loaded by TikZ,
% loaded by nicematrix)
\usepackage{geometry}
\geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{fit,patterns,arrows.meta,decorations.pathmorphing}
\usepackage{enumitem}
\usepackage{siunitx}
\usepackage{verbatim}
\usepackage{caption}
\usepackage{tocloft}
\setlength{\cftsubsecnumwidth}{3em} % for the numbers of subsections of the TOC
% We use \MakeShortVerb of shortvrb and not \DefineShortVerb of fancyvrb
% because we don't want small elements in verbatim to be colored in gray
\usepackage{shortvrb}
\MakeShortVerb{\|}
\usepackage{fancyvrb}
\fvset{formatcom=\color{gray}}
\usepackage{titlesec}
\titlespacing*{\section}{0pt}{6.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}
\titlespacing*{\subsection}{0pt}{4.5ex plus 1ex minus .2ex}{2ex plus .2ex}
\def\interitem{\vspace{7mm plus 2 mm minus 3mm}}
\def\emphase{\bgroup\color{RoyalPurple}\let\next=}
\usepackage{footnote}
\usepackage{booktabs}
\usepackage{varwidth}
\usepackage{tcolorbox}
\usepackage{adjustbox}
\usepackage[auto-lang=false]{lipsum}
\NewDocumentEnvironment {scope} {} {} {}
\NewDocumentCommand {\pkg} {m} {\textsf{#1}}
\NewDocumentCommand {\cls} {m} {\textsf{#1}}
\setlength{\parindent}{0pt}
\skip \footins = 2 \bigskipamount
\NewDocumentCommand{\Definition}{m}
{{\setlength{\fboxsep}{1pt}\colorbox{gray!20}{\ttfamily \vphantom{gl}#1}}}
\NewDocumentCommand{\DefinitionCommand}{m}
{{\setlength{\fboxsep}{1pt}\colorbox{gray!20}{\ttfamily
\vphantom{gl}\textbackslash #1}}}
\usepackage{makeidx}
\makeindex
\usepackage{piton}
\PitonOptions{language = verbatim, detected-commands = {emph,textsl}, splittable = 4}
\SetPitonStyle{ Number = , Comment = }
\ExplSyntaxOn
\dim_new:N \l__pantigny_width_dim
\keys_define:nn { pantigny }
{ width .dim_set:N = \l__pantigny_width_dim }
\NewPitonEnvironment { Code } { O { } }
{
\char_set_catcode_other:N |
\cs_set_eq:NN \emph \emphase
\dim_zero:N \l__pantigny_width_dim
\keys_set:nn { pantigny } { #1 }
\color{gray}
\dim_compare:nNnT \l__pantigny_width_dim > \c_zero_dim
{
\PitonOptions { width = \l__pantigny_width_dim }
\begin{minipage}[c]{\l__pantigny_width_dim}
}
}
{ \dim_compare:nNnT \l__pantigny_width_dim > \c_zero_dim
{ \end{minipage} }
}
\ExplSyntaxOff
\NewDocumentCommand{\indexcommand}{m}{\index{#1@\texttt{\textbackslash #1}}}
\NewDocumentCommand{\indexenv}{m}{\index{#1@\texttt{\{#1\}}}}
\usepackage[hyperfootnotes = false]{hyperref}
\hypersetup
{
pdfinfo =
{
Title = The package 'nicematrix' ,
Subject = A LaTeX package ,
Author = F. Pantigny
}
}
\begin{document}
\VerbatimFootnotes
\title{The package \pkg{nicematrix}\thanks{This document corresponds to the
version~\myfileversion\space of \pkg{nicematrix}, at the date of~\myfiledate.}}
\author{F. Pantigny \\ \texttt{[email protected]}}
\maketitle
\begin{abstract}
The LaTeX package \pkg{nicematrix} provides new environments similar to the
classical environments |{tabular}|, |{array}| and |{matrix}| of \pkg{array}
and \pkg{amsmath} but with extended features.
\end{abstract}
\vspace{1cm}
\hspace{1cm}
$\begin{bNiceArray}{cccc}[first-row,first-col,
code-for-first-col=\color{blue}\scriptstyle,
code-for-first-row=\color{blue}\scriptstyle,
columns-width = auto]
& C_1 & C_2 & \Cdots & C_n \\
L_1 & a_{11} & a_{12} & \Cdots & a_{1n} \\
L_2 & a_{21} & a_{22} & \Cdots & a_{2n} \\
\Vdots & \Vdots & \Vdots & \Ddots & \Vdots\\
L_n & a_{n1} & a_{n2} & \Cdots & a_{nn}
\end{bNiceArray}$\hspace{2cm}
\begin{NiceTabular}{lSSSS}%
[code-before = \rowcolor{red!15}{1-2} \rowcolors{3}{blue!15}{}]
\toprule
\Block{2-1}{Product} & \multicolumn{3}{c}{dimensions (cm)}
& \Block{2-1}{\rotate Price} \\
\cmidrule(rl){2-4}
& L & l & h \\
\midrule
small & 3 & 5.5 & 1 & 30 \\
standard & 5.5 & 8 & 1.5 & 50.5 \\
premium & 8.5 & 10.5 & 2 & 80 \\
extra & 8.5 & 10 & 1.5 & 85.5 \\
special & 12 & 12 & 0.5 & 70 \\
\bottomrule
\end{NiceTabular}
\vspace{1cm}
The package \pkg{nicematrix} is entirely contained in the file
|nicematrix.sty|. This file may be put in the current directory or in a
|texmf| tree. However, the best is to install \pkg{nicematrix} with a TeX
distribution such as MiKTeX, TeX Live or MacTeX.
\medskip
\emph{Remark}\par\nobreak
If you use LaTeX via Internet with, for example, Overleaf, you
can upload the file |nicematrix.sty| in the repertory of your
project in order to take full advantage of the latest version de
\pkg{nicematrix}.\footnote{The latest version of the file
|nicematrix.sty| may be downloaded on the Github depot of \pkg{nicematrix}:\newline
\small
\url{https://github.com/fpantigny/nicematrix/releases}}
\medskip
This package can be used with |xelatex|, |lualatex|, |pdflatex| but also by
the classical workflow |latex|-|dvips|-|ps2pdf| (or Adobe Distiller).
\textsl{However, the file nicematrix.dtx of the present documentation should
be compiled with LuaLaTeX.}
\medskip
This package requires and \textbf{loads} the packages \pkg{l3keys2e},
\pkg{array}, \pkg{amsmath}, \pkg{pgfcore} and the module \pkg{shapes} of
\textsc{pgf} (\pkg{tikz}, which is a layer over \textsc{pgf}, is \emph{not}
loaded). The final user only has to load the package with
|\usepackage{nicematrix}|.
\medskip
The idea of \pkg{nicematrix} is to create \textsc{pgf} nodes under the cells
and the positions of the rules of the tabular created by \pkg{array} and to
use these nodes to develop new features. As usual with \textsc{pgf}, the
coordinates of these nodes are written in the |aux| to be used on the next
compilation and that's why \pkg{nicematrix} may need \textbf{several
compilations}\footnote{If you use Overleaf, Overleaf will do automatically
a sufficient number of compilations.}. One must not use the command |\nofiles|
(which prevents the creation of the |aux| file).
% \medskip
% Most features of \pkg{nicematrix} may be used without explicit use of
% \textsc{pgf} or TikZ (which, in fact, is not loaded by default).
\medskip
\indexcommand{NiceMatrixOptions}
A command |\NiceMatrixOptions| is provided to fix the options (the
scope of the options fixed by this command is the current TeX group: they are
semi-global).
\medskip
\colorbox{yellow!50}{\bfseries New 7.0}\enskip \pkg{nicematrix} is
compatible with the \emph{Tagging Project} : cf. p.~\pageref{Tagging Project}.
\newpage
\section{The environments of this package}
The package \pkg{nicematrix} defines the following new environments.
\medskip
\begin{ttfamily}
\setlength{\tabcolsep}{3mm}
\begin{tabular}{llll}
\{NiceTabular\} & \{NiceArray\} & \{NiceMatrix\} \\
\{NiceTabular*\} & \{pNiceArray\} & \{pNiceMatrix\} \\
\{NiceTabularX\} & \{bNiceArray\} & \{bNiceMatrix\} \\
& \{BNiceArray\} & \{BNiceMatrix\} \\
& \{vNiceArray\} & \{vNiceMatrix\} \\
& \{VNiceArray\} & \{VNiceMatrix\}
\end{tabular}
\end{ttfamily}
%
\medskip
The environments |{NiceArray}|, |{NiceTabular}| and |{NiceTabular*}| are
similar to the environments |{array}|, |{tabular}| and |{tabular*}| of the
package \pkg{array} (which is loaded by \pkg{nicematrix}).
\medskip
The environments |{pNiceArray}|, |{bNiceArray}|, etc. have no equivalent in
\pkg{array}.
\medskip
The environments |{NiceMatrix}|, |{pNiceMatrix}|, etc. are similar to the
corresponding environments of \pkg{amsmath} (which is loaded by
\pkg{nicematrix}): |{matrix}|, |{pmatrix}|, etc.
\medskip
The environment |{NiceTabularX}| is similar to the environment |{tabularx}|
from the eponymous package.\footnote{In fact, it's possible to use directly the
|X| columns in the environment |{NiceTabular}| (and the required
width for the tabular is fixed by the key |width|): cf. p.~\pageref{X-columns}}.
\medskip
\textbf{It's recommended to use primarily the classical environments and to use the
environments of \pkg{nicematrix} only when some feature provided by these
environments is used (this will save memory).}
\medskip
All the environments of the package \pkg{nicematrix} accept, between square
brackets, an optional list of \textsl{key=value} pairs. \textbf{There must be
no space before the opening bracket (|[|) of this list of options.}
\section{The vertical space between the rows}
\label{cell-space}
\index{cell-space-top-limit}
\index{cell-space-bottom-limit}
\index{cell-space-limits}
It's well known that some rows of the arrays created by default with LaTeX
are, by default, too close to each other. Here is a classical example.
\medskip
\begin{Code}[width=9cm]
$\begin{pmatrix}
\frac{1}{2} & -\frac{1}{2} \\
\frac{1}{3} & \frac{1}{4} \\
\end{pmatrix}$
\end{Code}
$\begin{pmatrix}
\frac{1}{2} & -\frac{1}{2} \\
\frac{1}{3} & \frac{1}{4} \\
\end{pmatrix}$
\bigskip
Inspired by the package \pkg{cellspace} which deals with that problem, the
package \pkg{nicematrix} provides two keys \Definition{cell-space-top-limit} and
\Definition{cell-space-bottom-limit} similar to the parameters of
\pkg{cellspace} called |\cellspacetoplimit| and
|\cellspacebottomlimit|.\index{cellspace@\pkg{cellspace} (package)}
There is also a key \Definition{cell-space-limits} to set both parameters at
once.
The initial value of these parameters is $0$~pt in order to have for the
environments of \pkg{nicematrix} the same behaviour as those of \pkg{array}
and \pkg{amsmath}. However, a value of $1$~pt would probably be a good choice
and we suggest to set them with |\NiceMatrixOptions|.\footnote{One should
remark that these parameters apply also to the columns of type |S| of
\pkg{siunitx} whereas the package \pkg{cellspace} is not able to act on such
columns of type~|S|.}
\medskip
\begin{Code}
\NiceMatrixOptions{\emph{cell-space-limits = 1pt}}
\end{Code}
\begin{Code}[width=9cm]
$\begin{pNiceMatrix}
\frac12 & -\frac12 \\
\frac13 & \frac14 \\
\end{pNiceMatrix}$
\end{Code}
\begin{scope}
\NiceMatrixOptions{cell-space-limits = 1pt}
$\begin{pNiceMatrix}
\frac12 & -\frac12 \\
\frac13 & \frac14 \\
\end{pNiceMatrix}$
\end{scope}
\bigskip
It's also possible to change these parameters for only a few rows by using the
command |\RowStyle| provided by \pkg{nicematrix} (cf.~p.~\pageref{RowStyle}).
\bigskip
\section{The vertical position of the arrays}
\index{baseline (key for an environment)}
The package \pkg{nicematrix} provides a option \Definition{baseline} for the
vertical position of the arrays. This option takes in as value an integer which
is the number of the row on which the array will be aligned.
\medskip
\begin{Code}[width=9cm]
$A = \begin{pNiceMatrix}[\emph{baseline=2}]
\frac{1}{\sqrt{1+p^2}} & p & 1-p \\
1 & 1 & 1 \\
1 & p & 1+p
\end{pNiceMatrix}$
\end{Code}
$A = \begin{pNiceMatrix}[baseline=2]
\frac{1}{\sqrt{1+p^2}} & p & 1-p \\
1 & 1 & 1 \\
1 & p & 1+p
\end{pNiceMatrix}$
\medskip
It's also possible to use the option |baseline| with one of the special values
|t|, |c| or |b|. These letters may also be used absolutely like the option of
the environments |{tabular}| and |{array}| of \pkg{array}. The initial value
of |baseline| is~|c|.
\medskip
In the following example, we use the option |t| (equivalent to |baseline=t|)
immediately after an |\item| of list. One should remark that the presence of a
|\hline| at the beginning of the array doesn't prevent the alignment of the
baseline with the baseline of the first row (with |{tabular}| or |{array}| of
\pkg{array}, one must use |\firsthline|).
\medskip
\begin{Code}[width=9cm]
\begin{enumerate}
\item an item
\smallskip
\item \renewcommand{\arraystretch}{1.2}
$\begin{NiceArray}\emph{[t]}{lcccccc}
\hline
n & 0 & 1 & 2 & 3 & 4 & 5 \\
u_n & 1 & 2 & 4 & 8 & 16 & 32
\hline
\end{NiceArray}$
\end{enumerate}
\end{Code}
\begin{minipage}{5cm}
\begin{enumerate}
\item an item
\smallskip
\item \renewcommand{\arraystretch}{1.2}
$\begin{NiceArray}[t]{lcccccc}
\hline
n & 0 & 1 & 2 & 3 & 4 & 5 \\
u_n & 1 & 2 & 4 & 8 & 16 & 32 \\
\hline
\end{NiceArray}$
\end{enumerate}
\end{minipage}
\medskip
However, it's also possible to use the tools of
\pkg{booktabs}\footnote{The extension \pkg{booktabs} is \emph{not} loaded
by \pkg{nicematrix}.}: |\toprule|,
|\bottomrule|, |\midrule|, etc.\par\nobreak
\smallskip
\begin{Code}[width=9cm]
\begin{enumerate}
\item an item
\smallskip
\item
$\begin{NiceArray}[t]{lcccccc}
\emph{\toprule}
n & 0 & 1 & 2 & 3 & 4 & 5 \\
\emph{\midrule}
u_n & 1 & 2 & 4 & 8 & 16 & 32
\emph{\bottomrule}
\end{NiceArray}$
\end{enumerate}
\end{Code}
\begin{minipage}{5cm}
\begin{enumerate}
\item an item
\smallskip
\item
$\begin{NiceArray}[t]{lcccccc}
\toprule
n & 0 & 1 & 2 & 3 & 4 & 5 \\
\midrule
u_n & 1 & 2 & 4 & 8 & 16 & 32 \\
\bottomrule
\end{NiceArray}$
\end{enumerate}
\end{minipage}
\bigskip
It's also possible to use the key |baseline| to align a matrix on an
horizontal rule (drawn by |\hline|). In this aim, one should give the value
|line-|\textsl{i} where \textsl{i} is the number of the row \emph{following} the
horizontal rule.
\smallskip
\begin{Verbatim}
\NiceMatrixOptions{cell-space-limits=1pt}
\end{Verbatim}
\smallskip
\begin{Code}[width=9cm]
$A=\begin{pNiceArray}{cc|cc}\emph{[baseline=line-3]}
\dfrac{1}{A} & \dfrac{1}{B} & 0 & 0 \\
\dfrac{1}{C} & \dfrac{1}{D} & 0 & 0 \\
\hline
0 & 0 & A & B \\
0 & 0 & D & D \\
\end{pNiceArray}$
\end{Code}
\begin{scope}
\NiceMatrixOptions{cell-space-limits=1pt}
\raisebox{-5mm}{$A=\begin{pNiceArray}{cc|cc}[baseline=line-3]
\dfrac{1}{A} & \dfrac{1}{B} & 0 & 0 \\
\dfrac{1}{C} & \dfrac{1}{D} & 0 & 0 \\
\hline
0 & 0 & A & B \\
0 & 0 & D & D \\
\end{pNiceArray}$}
\end{scope}
\section{The blocks}
\label{Block}
\index{Blocks@\textbf{Blocks in the tabulars}|(}
\indexcommand{Block}
\subsection{General case}
In the environments of \pkg{nicematrix}, it's possible to use the command
\DefinitionCommand{Block} in order to place an element in the center of a
rectangle of merged cells of the array.\footnote{The spaces after a command |\Block| are deleted.}
The command |\Block| must be used in the upper leftmost cell of the cells of the
block with two mandatory arguments.
\begin{itemize}
\item The first argument is the size of the block with the syntax
$i$|-|$j$ where $i$ is the number of rows of the block and $j$ its number
of columns.
If this argument is empty, its default
value is |1-1|. If the number of rows is not specified, or equal to |*|, the
block extends until the last row (idem for the columns).
\item The second argument is the content of the block. In |{NiceTabular}|,
|{NiceTabular*}| and |{NiceTabularX}|, the content of the block is composed in
text mode whereas, in the other environments, it is composed in math mode.
\end{itemize}
\interitem
Here is an example of utilisation of the command |\Block| in mathematical matrices.
\medskip
\begin{Code}[width=10.6cm]
$\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
\emph{\Block{3-3}{A}} & & & 0 \\
& & & \Vdots \\
& & & 0 \\
\hline
0 & \Cdots& 0 & 0
\end{bNiceArray}$
\end{Code}
$\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
\Block{3-3}{A} & & & 0 \\
& & & \Vdots \\
& & & 0 \\
\hline
0 & \Cdots& 0 & 0
\end{bNiceArray}$
\bigskip
One may wish to raise the size of the ``$A$'' placed in the block of the
previous example. Since this element is composed in math mode, it's not
possible to use directly a command like |\large|, |\Large| and |\LARGE|.
That's why the command |\Block| provides an option between angle brackets to
specify some TeX code which will be inserted before the beginning of the
math mode.\footnote{This argument between angular brackets may also be used to
insert a command of font such as |\bfseries| when the command |\\| is used in
the content of the block. It's also possible to put in that optional argument
the command |\rotate| provided by \pkg{nicematrix} (cf. part~\ref{rotate},
p.~\pageref{rotate}).}
\medskip
\begin{Code}[width=10.6cm]
$\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
\Block{3-3}\emph{<\Large>}{A} & & & 0 \\
0 & & & \Vdots \\
& & & 0 \\
\hline
0 & \Cdots& 0 & 0
\end{bNiceArray}$
\end{Code}
\begin{scope}
$\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
\Block{3-3}<\Large>{A} & & & 0 \\
& & & \Vdots \\
& & & 0 \\
\hline
0 & \Cdots& 0 & 0
\end{bNiceArray}$
\end{scope}
\interitem
In fact, the command |\Block| accepts as first optional argument (between
square brackets) a list of couples \textsl{key=value}.
First, there are keys which are quick tools to control the apperance of the block.
\begin{itemize}
\item \index{fill (key of \texttt{\textbackslash Block})}
the key \Definition{fill} takes in as value a color and fills the block
with that color;
\item \index{opacity!key of \texttt{\textbackslash Block}}
the key \Definition{opacity} sets the opacity of the filling color specified by
|fill|;\footnote{Caution: that feature creates instructions of
transparency in the \textsc{pdf} and some readers of \textsc{pdf} don't
support such instructions.}
\item \index{draw (key of \texttt{\textbackslash Block})}
the key \Definition{draw} takes in as value a color and strokes the
frame of the block with that color (the default value of that key is the
current color of the rules of the array);
\item \index{color!key of \texttt{\textbackslash Block}}
the key \Definition{color} takes in as value a color and apply that
color the content of the block but draws also the frame of the block with that
color;
\item \index{vlines!key of \texttt{\textbackslash Block}}
\index{hvlines!key of \texttt{\textbackslash Block}}
\index{hlines!key of \texttt{\textbackslash Block}}
the keys \Definition{hlines}, \Definition{vlines} and
\Definition{hvlines} draw all the corresponding rules in the
block;\footnote{However, the rules are not drawn in the sub-blocks of the
block, as always with \pkg{nicematrix}: the rules are not drawn in the blocks,
except when they have the key |transparent|
(cf. section~\ref{rules} p.~\pageref{rules}).}
\item \index{line-width (key of \texttt{\textbackslash Block})}
the key \Definition{line-width} is the width of the rules (is relevant
only when one of the keys |draw|, |hvlines|, |vlines| and |hlines| is used);
\item \index{rounded-corners!key of \texttt{\textbackslash Block}}
\index{Corners (rounded ---)!for a block}
the key \Definition{rounded-corners} requires rounded corners (for the
frame drawn by |draw| and the shape drawn by |fill|) with a radius equal to
the value of that key (the default value is 4~pt\footnote{This value is the
initial value of the \emph{rounded corners} of TikZ.}).
\end{itemize}
\medskip
Sometimes, these tools are not sufficient to control the appearance of the
block. The following keys are more powerful but also more difficult to use.
Moreover, the require the loading of TikZ by the user (with
|\usepackage{tikz}|). By default, \pkg{nicematrix} does not load TikZ but only
\textsc{pgf}, which is a sublayer of TikZ.
\begin{itemize}
\item \index{borders (key of \texttt{\textbackslash Block})}
\index{tikzz@tikz!key of ``borders'' de \texttt{\textbackslash Block}}
The key \Definition{borders} provides the ability to draw only some
borders of the blocks; the value of that key is a (comma-separated) list of
elements covered by |left|, |right|, |top| and |bottom|; it's possible, in
fact, in the list which is the value of the key |borders|, to add an entry of
the form |tikz={|\textsl{list}|}| where \textsl{list} is a list of couples
\textsl{key=value} of TikZ specifying the graphical characteristics of the
lines that will be drawn (for an example, see p.~\pageref{dashed}).
\item \index{tikzz@tikz!key of \texttt{\textbackslash Block}}
When the key \Definition{tikz} is used, the TikZ path corresponding of
the rectangle which delimits the block is executed with TikZ\footnote{TikZ
should be loaded (by default, \pkg{nicematrix} only loads \textsc{pgf}) and,
if it's not, an error will be raised.} by using as options the value of that
key |tikz| (which must be a list of keys allowed for a TikZ path).
In fact, in the list of the keys provided by the user as value of |tikz|, it's
possible to put a key \Definition{offset}. That key is not provided by TikZ but
by \pkg{nicematrix}. It will narrow the rectangular frame corresponding to the
block by a margin (horizontally and vertically) equal to the value (of that key
|offset|). That new frame, a bit narrower, will be executed by TikZ with options
which are the other keys in the list of keys provided as value to the key |tikz|
of |\Block|.
For examples, cf. p.~\pageref{tikz-key-examples}.
\end{itemize}
\medskip
There is also some technical keys:
\begin{itemize}
\item \index{name!key of \texttt{\textbackslash Block}}
the key \Definition{name} provides a name to the rectangular TikZ node
corresponding to the block; it's possible to use that name with TikZ in the
|\CodeAfter| of the environment (cf.~p.~\pageref{code-after});
\item \index{respect-arraystretch (key of \texttt{\textbackslash Block})}
the key \Definition{respect-arraystretch} prevents the setting of
|\arraystretch| to $1$ at the beginning of the block (which is the behaviour
by default) ;
\item \index{transparent (key of \texttt{\textbackslash Block})}
By default, the rules are not drawn in the blocks (see the section about
the rules: section~\ref{rules} p.~\pageref{rules}). However, if the key
\Definition{transparent} is used, the rules are drawn. For an example, see
section~\ref{tikz-key-examples} on page~\pageref{tikz-key-examples}. Caution:
that key does not imply that the content of the block will be transparent!
\end{itemize}
There is also keys for the horizontal and vertical positions of the content of
the block: cf.~\ref{horizontal-block} p.~\pageref{horizontal-block}.
\interitem
{\bfseries One must remark that, by default, the commands |\Blocks| don't create
space}. There is exception only for the blocks mono-column and the blocks
mono-row under some conditions as explained just below.
\medskip
In the following example, we have had to enlarge by hand the columns 2 and 3
(with the construction |w{c}{...}| of \pkg{array}).
\bigskip
\begin{Code}
\begin{NiceTabular}{cw{c}{2cm}w{c}{3cm}c}
rose & tulip & daisy & dahlia \\
violet
& \emph{\Block[draw=red,fill=[RGB]{204,204,255},rounded-corners]{2-2}
{\LARGE Some beautiful flowers}} & & marigold \\
& & marigold \\
iris & & & lis \\
arum & periwinkle & forget-me-not & hyacinth
\end{NiceTabular}
\end{Code}
\medskip
\begin{center}
\begin{NiceTabular}{cw{c}{2cm}w{c}{3cm}c}
rose & tulip & daisy & dahlia \\
violet & \Block[draw=red,fill=[RGB]{204,204,255},rounded-corners]{2-2}
{\LARGE Some beautiful flowers} & & marigold \\
iris & & & lis \\
arum & periwinkle & forget-me-not & hyacinth
\end{NiceTabular}
\end{center}
\subsection{The mono-column blocks}
The mono-column blocks have a special behaviour.
\begin{itemize}
\item The natural width of the contents of these blocks is taken into account
for the width of the current column.
In the columns with a fixed width (columns |w{...}{...}|, |W{...}{...}|,
|p{...}|, |b{...}|, |m{...}|, |V| and |X|), the content of the block is
formatted as a paragraph of that width.
\item The specification of the horizontal position provided by the type of
column (|c|, |r| or |l|) is taken into account for the blocks. For a block in a
column ot type |p{...}|, |b{...}|, |m{...}|, |V{...}| ou |X|, the alignment |c|
will be used by default. However, those types of columns may have an optional
argument for the horizontal alignment (eg: |p[l]{...}|) and, in that case, that
type of alignement is passed to the block.
Of course, the |\Block| may also have its own specification of alignment:
cf.~\ref{horizontal-block} p.~\pageref{horizontal-block}.
\item The specifications of font specified for the column by a construction
|>{...}| in the preamble of the array are taken into account for the
mono-column blocks of that column (this behaviour is probably expected).
\end{itemize}
\bigskip
\begin{scope}
\hfuzz=10cm
\begin{Code}[width=12cm]
\begin{NiceTabular}{@{}>{\bfseries}lr@{}} \hline
\Block{2-1}{John} & 12 \\
& 13 \\ \hline
Steph & 8 \\ \hline
\Block{3-1}{Sarah} & 18 \\
& 17 \\
& 15 \\ \hline
Ashley & 20 \\ \hline
Henry & 14 \\ \hline
\Block{2-1}{Madison} & 15 \\
& 19 \\ \hline
\end{NiceTabular}
\end{Code}
\begin{NiceTabular}{@{}>{\bfseries}lr@{}}[baseline=c] \hline
\Block{2-1}{John} & 12 \\
& 13 \\ \hline
Steph & 8 \\ \hline
\Block{3-1}{Sarah} & 18 \\
& 17 \\
& 15 \\ \hline
Ashley & 20 \\ \hline
Henry & 14 \\ \hline
\Block{2-1}{Madison} & 15 \\
& 19 \\ \hline
\end{NiceTabular}
\end{scope}
\subsection{The mono-row blocks}
For the mono-row blocks, the natural height and depth are taken into account
for the height and depth of the current row (as does a standard |\multicolumn|
of LaTeX), except when an option of vertical position has been used for the block
(one of the keys |t|, |b|, |m|, |T| and |B| described in the part
\ref{vertical-pos-block}, p.~\pageref{vertical-pos-block}).
\subsection{The mono-cell blocks}
A mono-cell block inherits all the properties of the mono-row blocks and
mono-column blocks.
\medskip
At first sight, one may think that there is no point using a mono-cell block.
However, there are some good reasons to use such a block.
\begin{itemize}
\item It's possible to use the command |\\| in a (mono-cell) block.
\item It's possible to use the option of horizontal alignment of the block in
derogation of the type of column given in the preamble of the array.
\item It's possible do draw a frame around the cell with the key |draw| of the
command |\Block| and to fill the background with rounded corners with the keys
|fill| and |rounded-corners|.\footnote{If one simply wishes to color the
background of a unique cell, there is no point using the command |\Block|:
it's possible to use the command |\cellcolor|.}
\item It's possible to draw one or several borders of the cell with the key |borders|.
\end{itemize}
\bigskip
\begin{Code}[width=10cm]
\begin{NiceTabular}{cc}
\toprule
Writer & \emph{\Block[l]{}{year\\ of birth}} \\
\midrule
Hugo & 1802 \\
Balzac & 1799 \\
\bottomrule
\end{NiceTabular}
\end{Code}
\begin{NiceTabular}{cc}
\toprule
Writer & \Block[l]{}{year\\ of birth} \\
\midrule
Hugo & 1802 \\
Balzac & 1799 \\
\bottomrule
\end{NiceTabular}
\medskip
We recall that if the first mandatory argument of |\Block| is left blank, the
block is mono-cell.\footnote{One may consider that the default value of the
first mandatory argument of |\Block| is |1-1|.}
\subsection{Horizontal position of the content of the block}
\label{horizontal-block}
The command |\Block| accepts the keys \Definition{l}, \Definition{c} and
\Definition{r} for the horizontal position of its content.
\medskip
\begin{Code}[width=10.6cm]
$\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
\Block\emph{[r]}{3-3}<\LARGE>{A} & & & 0 \\
& & & \Vdots \\
& & & 0 \\
\hline
0 & \Cdots& 0 & 0
\end{bNiceArray}$
\end{Code}
$\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
\Block[r]{3-3}<\LARGE>{A} & & & 0 \\
& & & \Vdots \\
& & & 0 \\
\hline
0 & \Cdots& 0 & 0
\end{bNiceArray}$
\medskip
By default, the horizontal position of the content of a block is computed
by using the positions of the \emph{contents} of the columns implied in that
block. That's why, in the following example, the header ``First group'' is
correctly centered despite the instruction |!{\qquad}| in the preamble which
has been used to increase the space between the columns (this
is not the behaviour of |\multicolumn|).
\medskip
\begin{center}
\begin{Code}
\begin{NiceTabular}{@{}c!{\qquad}ccc\emph{!{\qquad}}ccc@{}}
\toprule
Rank & \emph{\Block{1-3}{First group}} & & & \Block{1-3}{Second group} \\
& 1A & 1B & 1C & 2A & 2B & 2C \\
\midrule
1 & 0.657 & 0.913 & 0.733 & 0.830 & 0.387 & 0.893\\
2 & 0.343 & 0.537 & 0.655 & 0.690 & 0.471 & 0.333\\
3 & 0.783 & 0.885 & 0.015 & 0.306 & 0.643 & 0.263\\
4 & 0.161 & 0.708 & 0.386 & 0.257 & 0.074 & 0.336\\
\bottomrule
\end{NiceTabular}
\end{Code}
\end{center}
\bigskip
\begin{center}
\begin{NiceTabular}{@{}c!{\qquad}ccc!{\qquad}ccc@{}}
\toprule
Rank & \Block{1-3}{First group} & & & \Block{1-3}{Second group} \\
& 1A & 1B & 1C & 2A & 2B & 2C \\
\midrule
1 & 0.657 & 0.913 & 0.733 & 0.830 & 0.387 & 0.893\\
2 & 0.343 & 0.537 & 0.655 & 0.690 & 0.471 & 0.333\\
3 & 0.783 & 0.885 & 0.015 & 0.306 & 0.643 & 0.263\\
4 & 0.161 & 0.708 & 0.386 & 0.257 & 0.074 & 0.336\\
\bottomrule
\end{NiceTabular}
\end{center}
\medskip
In order to have an horizontal positionning of the content of the block computed
with the limits of the columns of the LaTeX array (and not with the contents of
those columns), one may use the key \Definition{L}, \Definition{R} and
\Definition{C} of the command |\Block|.
\medskip
Here is the same example with the key |C| for the first block.
\medskip
\begin{center}
\begin{Code}
\begin{NiceTabular}{@{}c!{\qquad}ccc\emph{!{\qquad}}ccc@{}}
\toprule
Rank & \emph{\Block[C]{1-3}{First group}} & & & \Block{1-3}{Second group} \\
& 1A & 1B & 1C & 2A & 2B & 2C \\
\midrule
1 & 0.657 & 0.913 & 0.733 & 0.830 & 0.387 & 0.893\\
2 & 0.343 & 0.537 & 0.655 & 0.690 & 0.471 & 0.333\\
3 & 0.783 & 0.885 & 0.015 & 0.306 & 0.643 & 0.263\\
4 & 0.161 & 0.708 & 0.386 & 0.257 & 0.074 & 0.336\\
\bottomrule
\end{NiceTabular}
\end{Code}
\end{center}
\bigskip
\begin{center}
\begin{NiceTabular}{@{}c!{\qquad}ccc!{\qquad}ccc@{}}
\toprule
Rank & \Block[C]{1-3}{First group} & & & \Block{1-3}{Second group} \\
& 1A & 1B & 1C & 2A & 2B & 2C \\
\midrule
1 & 0.657 & 0.913 & 0.733 & 0.830 & 0.387 & 0.893\\
2 & 0.343 & 0.537 & 0.655 & 0.690 & 0.471 & 0.333\\
3 & 0.783 & 0.885 & 0.015 & 0.306 & 0.643 & 0.263\\
4 & 0.161 & 0.708 & 0.386 & 0.257 & 0.074 & 0.336\\
\bottomrule
\end{NiceTabular}
\end{center}
\bigskip
\colorbox{yellow!50}{\bfseries New 6.28}\par\nobreak
\smallskip
The command |\Block| supports also the keys |p| and |j|. With the key
\Definition{p}, the content of the block is formatted like a paragraph (as in a
column of type |p|). That key may be used in conjunction with the key: |l|, |c|
or |r|, and, in that case, the paragraph is formatted with |\raggedright|,
|\centering| or |\raggedleft| (or |\RaggedRight|, |\Centering| and |\RaggedLeft|
when \pkg{ragged2e}) est chargée. With the key \Definition{j}, the paragraph is
justified.
\subsection{Vertical position of the content of the block}
\label{vertical-pos-block}
For the vertical position, the command |\Blocks| accepts the keys
|m|, |t|, |b|, |T| and |B|.
\begin{itemize}
\item \index{v-center (key of \texttt{\textbackslash Block})}
With the key \Definition{m}\footnote{That key has an alias: |v-center|.}, the content of the block is vertically centered.
\item With the key \Definition{t}, the baseline of the content of the block is aligned
with the baseline of the first row concerned by the block.
\item with the key \Definition{b}, the baseline of the last row of the content of the
block (we recall that the content of a block may contains several lines
separated by |\\|) is aligned with the baseline of the last of the rows of the
array involved in the block.
\item With the key \Definition{T}, the content of the block is set upwards.
No vertical margin is added. However, the contents of the block is (always)
composed by \pkg{nicematrix} in a |{minipage}|, a |{tabular}| or an |{array}|
and, hence, there will still remain a margin (in most cases). If needed, it's
always possible to add a |\strut|...
\item With the key \Definition{B}, the content of the block is set downwards.
\end{itemize}
When no key is given, the key |m| applies (except in the mono-row blocks).
\medskip
\begin{scope}
\NiceMatrixOptions{rules/color=[gray]{0.75}, hvlines}
\begin{BVerbatim}
\NiceMatrixOptions{rules/color=[gray]{0.75}, hvlines}
\end{BVerbatim}
\bigskip
\begin{Code}[width=10cm]
\begin{NiceTabular}{ccc}
\Block[fill=red!10,\emph{t},l]{4-2}{two\\lines}
& & \Huge Un\\
& & deux \\
& & trois \\
& & \Huge quatre \\
text & text \\
\end{NiceTabular}
\end{Code}
\begin{NiceTabular}{ccc}
\Block[fill=red!10,t,l]{4-2}{two\\lines}
& & \Huge Un\\
& & deux \\
& & trois \\
& & \Huge quatre \\
text & text \\
\end{NiceTabular}
\bigskip
\begin{Code}[width=10cm]
\begin{NiceTabular}{ccc}
\Block[fill=red!10,\emph{b},r]{4-2}{two\\lines}
& & \Huge Un\\