Nicematrix
Nicematrix
F. Pantigny
                                              fpantigny@wanadoo.fr
                                                    April 28, 2025
                                                        Abstract
           The LaTeX package nicematrix provides new environments similar to the classical environ-
         ments {tabular}, {array} and {matrix} of array and amsmath but with extended features.
dimensions (cm)
                                                                                                     Price
                    C1    C2         Cn                      Product
                                                                            L         l          h
                                         
           L1       a11   a12       a1n
           L2  a21
                         a22       a2n 
                                                           small          3        5.5      1       30
                                                          standard       5.5      8        1.5     50.5
                                                            premium
                                       
           Ln       an1   an2       ann                                    8.5     10.5      2       80
                                                            extra          8.5     10        1.5     85.5
                                                            special       12       12        0.5     70
The package 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 nicematrix with a TeX distribution
such as MiKTeX, TeX Live or MacTeX.
Remark
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 nicematrix.1
This package can be used with xelatex, lualatex, pdflatex but also by the classical workflow
latex-dvips-ps2pdf (or Adobe Distiller). However, the file nicematrix.dtx of the present documen-
tation should be compiled with LuaLaTeX.
This package requires and loads the packages l3keys2e, array, amsmath, pgfcore and the module shapes
of pgf (tikz, which is a layer over pgf, is not loaded). The final user only has to load the package
with \usepackage{nicematrix}.
The idea of nicematrix is to create pgf nodes under the cells and the positions of the rules of the
tabular created by array and to use these nodes to develop new features. As usual with pgf, the
coordinates of these nodes are written in the aux to be used on the next compilation and that’s why
nicematrix may need several compilations2 . One must not use the command \nofiles (which
prevents the creation of the aux file).
Most features of nicematrix may be used without explicit use of pgf or TikZ (which, in fact, is not
loaded by default).
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).
  ∗ This    document corresponds to the version 7.1c of nicematrix, at the date of 2025/04/28.
  1 The    latest version of the file nicematrix.sty may be downloaded on the Github depot of nicematrix:
https://github.com/fpantigny/nicematrix/releases
  2 If   you use Overleaf, Overleaf will do automatically a sufficient number of compilations.
                                                             1
1 The environments of this package
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.
$\begin{pmatrix}
\frac{1}{2} & -\frac{1}{2} \\
                                                                    1
                                                                               − 12
                                                                                      
                                                                       2
\frac{1}{3} & \frac{1}{4} \\                                           1
                                                                       3
                                                                                1
                                                                                4
\end{pmatrix}$
Inspired by the package cellspace which deals with that problem, the package nicematrix provides two
keys cell-space-top-limit and cell-space-bottom-limit similar to the parameters of cellspace
called \cellspacetoplimit and \cellspacebottomlimit.
There is also a key 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 nicematrix the
same behaviour as those of array and amsmath. However, a value of 1 pt would probably be a good
choice and we suggest to set them with \NiceMatrixOptions.4
\NiceMatrixOptions{cell-space-limits = 1pt}
$\begin{pNiceMatrix}
\frac12 & -\frac12 \\
                                                                                        !
                                                                           1
                                                                           2     − 12
\frac13 & \frac14 \\                                                       1        1
                                                                           3        4
\end{pNiceMatrix}$
3 In fact, it’s possible to use directly the X columns in the environment {NiceTabular} (and the required width for
                                                          2
It’s also possible to change these parameters for only a few rows by using the command \RowStyle
provided by nicematrix (cf. p. 26).
The package nicematrix provides a option 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.
$A = \begin{pNiceMatrix}[baseline=2]
                                                                          1
\frac{1}{\sqrt{1+p^2}} & p & 1-p \\                                                 p       1−p
                                                                  p                           
                                                                         1+p2
1 & 1 & 1 \\                                                    A=      1          1        1 
1 & p & 1+p                                                              1          p       1+p
\end{pNiceMatrix}$
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 array.
The initial value of baseline is c.
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 array,
one must use \firsthline).
\begin{enumerate}
\item an item
\smallskip
\item \renewcommand{\arraystretch}{1.2}
                                                                 1. an item
$\begin{NiceArray}[t]{lcccccc}
\hline                                                           2. n     0     1       2    3    4   5
n   & 0 & 1 & 2 & 3 & 4 & 5 \\
                                                                    un    1     2       4    8    16 32
u_n & 1 & 2 & 4 & 8 & 16 & 32
\hline
\end{NiceArray}$
\end{enumerate}
However, it’s also possible to use the tools of booktabs5 : \toprule, \bottomrule, \midrule, etc.
\begin{enumerate}
\item an item
\smallskip
\item
$\begin{NiceArray}[t]{lcccccc}                                   1. an item
\toprule
n   & 0 & 1 & 2 & 3 & 4 & 5 \\                                   2. n     0     1       2    3    4   5
\midrule                                                           un     1     2       4    8    16 32
u_n & 1 & 2 & 4 & 8 & 16 & 32
\bottomrule
\end{NiceArray}$
\end{enumerate}
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-i where i is the number of the row following the horizontal
rule.
\NiceMatrixOptions{cell-space-limits=1pt}
                                                            3
$A=\begin{pNiceArray}{cc|cc}[baseline=line-3]
\dfrac{1}{A} & \dfrac{1}{B} & 0 & 0 \\                                  1           1
                                                                                                   
                                                                                        0       0
\dfrac{1}{C} & \dfrac{1}{D} & 0 & 0 \\                                A            B             
\hline
                                                                      1            1             
                                                                                       0       0
0 & 0 & A & B \\                                                        C           D
                                                                                                 
                                                                    A=                           
0 & 0 & D & D \\
                                                                      0            0   A       B
\end{pNiceArray}$                                                       0           0   D       D
4 The blocks
   • 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).
   • 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.
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.7
$\begin{bNiceArray}{cw{c}{1cm}c|c}[margin]
\Block{3-3}<\Large>{A} & & & 0 \\                                               
                                                                                                            0
                                                                                                                
0 & & & \Vdots \\
& & & 0 \\
                                                                                
                                                                                
                                                                                
                                                                                            A                 
                                                                                                              
                                                                                                              
\hline                                                                                                     0 
0 & \Cdots& 0 & 0                                                                   0                   0   0
\end{bNiceArray}$
                                                        4
In fact, the command \Block accepts as first optional argument (between square brackets) a list of
pairs key=value.
First, there are keys which are quick tools to control the apperance of the block.
   • the key fill takes in as value a color and fills the block with that color;
   • the key opacity sets the opacity of the filling color specified by fill;8
   • the key 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);
   • the key 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;
   • the keys hlines, vlines and hvlines draw all the corresponding rules in the block;9
   • the key line-width is the width of the rules (is relevant only when one of the keys draw,
     hvlines, vlines and hlines is used);
   • the key 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 pt10 ).
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, nicematrix does not load TikZ but only pgf, which is a
sublayer of TikZ.
   • The key 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={list} where list is a list of couples key=value of TikZ specifying the graphical
     characteristics of the lines that will be drawn (for an example, see p. 69).
   • When the key tikz is used, the TikZ path corresponding of the rectangle which delimits the
     block is executed with TikZ11 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
      offset . That key is not provided by TikZ but by 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. 63.
   • the key 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. 39);
   • the key respect-arraystretch prevents the setting of \arraystretch to 1 at the beginning
     of the block (which is the behaviour by default) ;
   • By default, the rules are not drawn in the blocks (see the section about the rules: section 5
     p. 11). However, if the key transparent is used, the rules are drawn. For an example, see
     section 18.1 on page 63. Caution: that key does not imply that the content of the block will be
     transparent!
8 Caution: that feature creates instructions of transparency in the pdf and some readers of pdf don’t support such
instructions.
   9 However, the rules are not drawn in the sub-blocks of the block, as always with nicematrix: the rules are not drawn
in the blocks, except when they have the key transparent (cf. section 5 p. 11).
  10 This value is the initial value of the rounded corners of TikZ.
  11 TikZ should be loaded (by default, nicematrix only loads pgf) and, if it’s not, an error will be raised.
                                                           5
There is also keys for the horizontal and vertical positions of the content of the block: cf. 4.5 p. 7.
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.
In the following example, we have had to enlarge by hand the columns 2 and 3 (with the construction
w{c}{...} of array).
\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 \\
   & & marigold \\
iris & & & lis \\
arum & periwinkle & forget-me-not & hyacinth
\end{NiceTabular}
  • 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.
  • 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. 4.5 p. 7.
  • 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).
\begin{NiceTabular}{@{}>{\bfseries}lr@{}} \hline
\Block{2-1}{John}    & 12 \\                                                                  12
                                                                                   John
                     & 13 \\ \hline                                                           13
Steph                & 8 \\ \hline                                                 Steph       8
\Block{3-1}{Sarah}   & 18 \\                                                                  18
                     & 17 \\                                                       Sarah      17
                     & 15 \\ \hline                                                           15
Ashley               & 20 \\ \hline                                                Ashley     20
Henry                & 14 \\ \hline                                                Henry      14
\Block{2-1}{Madison} & 15 \\                                                                  15
                     & 19 \\ \hline                                                Madison
                                                                                              19
\end{NiceTabular}
                                                   6
4.3    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
4.6, p. 9).
   • 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.12
   • It’s possible to draw one or several borders of the cell with the key borders.
\begin{NiceTabular}{cc}
\toprule
Writer & \Block[l]{}{year\\ of birth} \\                                               year
                                                                            Writer
\midrule                                                                               of birth
Hugo & 1802 \\                                                              Hugo        1802
Balzac & 1799 \\                                                            Balzac      1799
\bottomrule
\end{NiceTabular}
We recall that if the first mandatory argument of \Block is left blank, the block is mono-cell.13
By default, the horizontal position of the content of a block is computed by using the positions of
the 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).
12 If one simply wishes to color the background of a unique cell, there is no point using the command \Block: it’s
                                                        7
\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}
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
L , R and C of the command \Block.14
Here is the same example with the key C for the first block.
\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}
The command \Block supports also the keys p and j. With the key 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
a key l, c or r, and, in that case, the paragraph is formatted with \raggedright, \centering or
\raggedleft (or \RaggedRight, \Centering and \RaggedLeft when ragged2e) est chargée. With
the key j (which inforces the key p), the paragraph is justified.
14 Remark: The keys L, C and R require less computations than the keys l, c and r. If you are concernend about
                                                       8
It’s possible to put an environment {itemize} or {enumerate} in a block which uses the key p or
j (in the other case, you will have a LaTeX error: Not allowed in LR mode). For the following
example, we have loaded the package enumitem (for the key left of the environment {itemize}).
\begin{NiceTabular}[hvlines]{ccc}
one & two two & three three \\
one &
\Block[p]{*-2}{%
\begin{itemize}[left=0pt]
\item one two three four five
\item two
\item three
\end{itemize}
} \\
one & \\
one & \\
one & \\
one & \\
one & \\
one & \\
\end{NiceTabular}
  • with the key b, the baseline of the last row of the content of the block (we recall that the
    content of a block may contain several lines of text separated by \\) is aligned with the baseline
    of the last of the rows of the array involved in the block.
  • With the key T, the content of the block is set upwards.
      No vertical margin is added. However, the contents of the block is (always) composed by
      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...
  • With the key B, the content of the block is set downwards.
When no key is given, the key m applies (except in the mono-row blocks).
\NiceMatrixOptions{rules/color=[gray]{0.75}, hvlines}
                                                       9
\begin{NiceTabular}{ccc}
\Block[fill=red!10,t,l]{4-2}{two\\lines}
 & & \Huge Un\\
                                                                         two
                                                                         lines
                                                                                             Un
                                                                                             deux
 & & deux \\
                                                                                              trois
                                                                                          quatre
 & & trois \\
 & & \Huge quatre \\
text & text \\                                                           text    text
\end{NiceTabular}
\begin{NiceTabular}{ccc}
\Block[fill=red!10,b,r]{4-2}{two\\lines}
 & & \Huge Un\\
                                                                                             Un
                                                                                             deux
 & & deux \\
                                                                                              trois
                                                                                          quatre
 & & trois \\                                                                      two
 & & \Huge quatre \\                                                             lines
text & text \\                                                           text     text
\end{NiceTabular}
\begin{NiceTabular}{ccc}
\Block[fill=red!10,T,L]{4-2}{two\\lines}
 & & \Huge Un\\
                                                                        two
                                                                        lines                Un
                                                                                             deux
 & & deux \\
                                                                                              trois
                                                                                          quatre
 & & trois \\
 & & \Huge quatre \\
text & text \\                                                           text    text
\end{NiceTabular}
\begin{NiceTabular}{ccc}
\Block[fill=red!10,B,R]{4-2}{two\\lines}
 & & \Huge Un\\
                                                                                             Un
                                                                                             deux
 & & deux \\
                                                                                              trois
                                                                                          quatre
 & & trois \\                                                                      two
 & & \Huge quatre \\                                                              lines
text & text \\                                                           text    text
\end{NiceTabular}
The extension nicematrix provides the ability to use \\ and & directly in the content of a block (in
order to format its contents) but there is some rectrictions.
   • One must not use both \\ and & in the same block.
   • For \\, there is no other restriction. It’s possible to use \\ in a block to format a text on several
     lines.
   • In order to use &, the key ampersand-in-blocks (alias: &-in-blocks ) must been activated16 .
     Then, the block is divided in sub-blocks as illustrated below. Be careful: when ampersand-
     in-blocks is in force, the (main) argument of the command \Block is syntactically divided
     into sub-blocks by splitting on the ampersands &, the ampersands between curly braced are
     protected but not those in an environment.17
16 Otherwise, the use of & in the command \Block will raise a TeX error :
                                                      10
With the ampserand &, it’s possible to divide horizontally a block in sub-blocks of the same size.
\begin{NiceTabular}{ll}%
   [hvlines,ampersand-in-blocks]
                                                                   the five first naturels numbers
  & the five first naturels numbers \\
                                                              3      one          two        three
3 & \Block{}{one & two & three} \\
4 & \Block{}{one& two & three & four} \\                      4     one       two    three     four
5 & \Block{}{one & two & three & four & five} \\              5    one two three four five
\end{NiceTabular}
As we can see, the blocks (which was are in fact mono-cell blocks) are divided into sub-blocks of the
same size. However, maybe the following code would be prefered.
\begin{NiceTabular}{lccccc}%
   [hvlines,ampersand-in-blocks]
  & \Block{1-5}{the five first                                      the five first natural numbers
                  natural numbers} \\                         3       one          two       three
3 & \Block{1-5}{one & two & three} \\                         4     one       two     three    four
4 & \Block{1-5}{one& two & three & four} \\                   5    one two three four five
5 & one & two & three & four & five \\
\end{NiceTabular}
In this code, we have blocks of size 1-5 which are divided into three or four sub-blocks.
5 The rules
The usual techniques for the rules may be used in the environments of nicematrix (except \vline).
However, there is some small differences with the classical environments.
\begin{NiceTabular}{|c|c|} \hline
First & Second \\ \hline\hline                                       First       Second
Peter \\ \hline                                                      Peter
Mary & George\\ \hline                                               Mary        George
\end{NiceTabular}
However, the vertical rules are not drawn in the blocks (created by \Block: cf. p. 4) nor in the
corners (created by the key corner: cf. p. 14) nor in the potential exterior rows (created by the keys
first-row and last-row: cf. p. 29).
If you use booktabs (which provides \toprule, \midrule, \bottomrule, etc.) and if you actually want
to add vertical rules (which is not in the spirit of booktabs), you should notice that the vertical rules
drawn by nicematrix are compatible with booktabs. Remark that nicematrix does not load booktabs.
$\begin{NiceArray}{c|ccc} \toprule
a & b & c & d \\ \midrule                                              a     b   c   d
1 & 2 & 3 & 4 \\                                                       1     2   3   4
1 & 2 & 3 & 4 \\ \bottomrule                                           1     2   3   4
\end{NiceArray}$
                                                   11
However, it’s still possible to define a specifier (named, for instance, I) to draw vertical rules with
the standard behaviour of array.
\newcolumntype{I}{!{\vrule}}
In the environments of nicematrix, this situation is corrected (it’s still possible to go to the standard
behaviour of \cline with the key standard-cline ).
\setlength{\arrayrulewidth}{2pt}
\begin{NiceTabular}{cccc} \hline
                                                                        A    B   C    D
A&B&C&D \\ \cline{2}
A&B&C&D \\ \hline                                                       A    B   C    D
\end{NiceTabular}
In fact, in that example, instead of \hline, it would have a better choice to use \Hline, provided
by nicematrix and described just below, because it ensures a better output in the PDF viewers at the
low levels of zoom.
                                                    12
5.3     The tools of nicematrix for the rules
Here are the tools provided by nicematrix for the rules.
   • the keys hlines, vlines, hvlines and hvlines-except-borders;
   • the specifier “|” in the preamble (for the environments with preamble);
   • the command \Hline.
All these tools don’t draw the rules in the blocks nor in the empty corners (when the
key corners is used), nor in the exterior rows and columns.
   • These blocks are:
          – the blocks created by the command \Block18 presented p. 4;
          – the blocks implicitely delimited by the continuous dotted lines created by \Cdots, \Vdots,
            etc. (cf. p. 31).
   • The corners are created by the key corners explained below (see p. 14).
   • For the exterior rows and columns, see p. 29.
In particular, this remark exhibits a first difference between the standard command \hline and the
command \Hline provided by nicematrix.
Moreover, the key \Hline takes in an optional argument (between square brackets) which is a list of
key=value pairs. For the description of those keys, see custom-line on p. 16.19
As well as the command \Hline, the specifier “|” supports an optional argument between square
brackets for the characteristics of the rule.
\begin{NiceTabular}{ | c |[color=blue] c |}
\Hline
a & b \\
\Hline[color=red]                                                             a    b
c & d \\                                                                      c    d
\Hline
\end{NiceTabular}
When the key hlines is in force, it’s still possible to use \Hline\Hline to put a double horizontal
rule. As well, it’s possible to put || in the preamble (of an environment with preamble) to put a
double vertical rule, even when the key vlines is in force.
 18 And    also the command \multicolumn but it’s recommended to use instead \Block in the environments of nicematrix.
 19 Technical    remark: If the user wants to write a command over the command \Hline, it shall be ensured that this
new command is expandable in the TeX sens (by using, for instance, \NewExpandableDocumentCommand of LaTeX3,
\newcommand of LaTeX or \def of TeX). Example: \NewExpandableDocumentCommand}{}{\Hline[color=red]}
  20 It’s possible to put in that list some intervals of integers with the syntax i-j.
                                                         13
$\begin{NiceArray}{c||ccccc}[hlines,vlines]
  & a & b & c & d & e \\ \Hline\Hline                                                       a   b       c   d   e
x & 0 & 0 & 0 & 0 & 0 \\                                                            x       0   0       0   0   0
y & 0 & 0 & 0 & 0 & 0 \\                                                            y       0   0       0   0   0
z & 0 & 0 & 0 & 0 & 0 \\                                                            z       0   0       0   0   0
\end{NiceArray}$
It’s worth noting that, when the key rounded-corners is used for the environment {NiceTabular},
the key hvlines draws rounded corners for the exterior frame of the tabular: cf. part 14.1, p. 49.
The key hvlines-except-borders is similar to the key hvlines but does not draw the rules on the
horizontal and vertical borders of the array. For an example of use of that key, see the part “Use
with tcolorbox”, p. 64.
                                                                                                                    A
                                                                                                        A   A       A
                                                                                                            A
In the example on the right (where B is in the center of a                                              A   A       A   A
block of size 2×2), we have colored in blue the four (empty)                            A       A       A   A       A   A
corners of the array.                                                                   A       A       A   A       A   A
                                                                                                A       A   A
                                                                                                            A
                                                                                                    B
                                                                                                            A
When the key corners 22 is used, nicematrix computes the (empty) corners and these corners will be
taken into account by the tools for drawing the rules (the rules won’t be drawn in the corners).
21 For sake of completeness, we should also say that a cell contained in a block (even an empty cell) is not taken into
account for the determination of the corners. That behaviour is natural. The precise definition of a “non-empty cell”
is given below (cf. p. 61).
  22 The key corners that we describe now has no direct link with the key rounded-corners described in the part 14.1,
p. 49
                                                           14
\NiceMatrixOptions{cell-space-top-limit=3pt}
\begin{NiceTabular}{*{6}{c}}[corners,hvlines]                                                            A
  &   &   &   & A \\                                                                     A       A       A
  &   & A & A & A \\                                                                             A
  &   &   & A \\
                                                                                         A       A       A   A
  &   & A & A & A & A \\
A & A & A & A & A & A \\                                                     A   A       A       A       A   A
A & A & A & A & A & A \\                                                     A   A       A       A       A   A
  & A & A & A \\                                                                 A       A       A
  & \Block[C]{2-2}{B} & & A \\                                                                   A
  &   &   & A \\                                                                     B
                                                                                                 A
\end{NiceTabular}
It’s also possible to provide to the key corners a (comma-separated) list of corners (designed by NW,
SW, NE and SE).
\NiceMatrixOptions{cell-space-top-limit=3pt}
\begin{NiceTabular}{*{6}{c}}[corners=NE,hvlines]                             1
1\\
                                                                             1   1
1&1\\
                                                                             1   2   1
1&2&1\\
1&3&3&1\\                                                                    1   3   3       1
1&4&6&4&1\\                                                                  1   4   6       4       1
 & & & & &1                                                                                              1
\end{NiceTabular}
. The corners are also taken into account by the tools provided by nicematrix to color cells, rows
and columns. These tools don’t color the cells which are in the corners (cf. p. 19). The command
\TikzEveryCell available in the \CodeBefore and the \CodeAfter (cf. p. 44) takes also into account
the empty corners.
But it’s also possible to use \diagbox for the diagonal rule only (and the labels are put but the usual
way, that is to say in cells of the tabular).
                                                  15
$\begin{NiceArray}{*{5}{c}}[hvlines]
\Block{2-2}{\diagbox{}{}} & y & a & b & c \\                                  y   a    b   c
x &   & a & b & c \\                                                      x       a    b   c
a & a & e & c & b \\                                                      a   a   e    c   b
b & b & c & e & a \\                                                      b   b   c    e   a
c & c & b & a & e                                                         c   c   b    a   e
\end{NiceArray}$
Nevertheless, it’s always possible to draw whatever rule we wish with TikZ in the \CodeAfter (or
the \CodeBefore) by using the PGF/TikZ nodes created by nicematrix: cf. p. 54.
   • the key command is the name (without the backslash) of a command that will be created by
     nicematrix and that will be available for the final user in order to draw horizontal rules (similarly
     to \hline);
   • the key ccommand is the name (without the backslash) of a command that will be created by
     nicematrix and that will be available for the final user to order to draw partial horizontal rules
     (similarly to \cline, hence the name ccommand): the argument of that command is a list of
     intervals of columns specified by the syntax i or i-j.23
   • the key letter takes in as argument a letter24 that the user will use in the preamble of an
     environment with preamble (such as {NiceTabular} in order to specify a vertical rule.
We will now speak of the keys which describe the rule itself. Those keys may also be used in the
(optional) argument of an individual command \Hline or in the (optional) argument of a specifier
“|” in the preamble of an environment.
   • First possibility
        It’s possible to specify composite rules, with a color and a color for the inter-rule space (as
        possible with colortbl for instance).
          – the key multiplicity is the number of consecutive rules that will be drawn: for instance,
            a value of 2 will create double rules such those created by \hline\hline or || in the
            preamble of an environment;
          – the key color sets the color of the rules ;
          – the key sep-color sets the color between two successive rules (should be used only in
            conjonction with multiplicity). The name of that key is inspired by the command
            \doublerulesepcolor of colortbl.
        That system may be used, in particular, for the definition of commands and letters to draw
        rules with a specific color (and those rules will respect the blocks and corners as do all the rules
        of nicematrix).
23 It’s recommended to use such commands only once in a row because each use will create space between the rows
                                                       16
  \begin{NiceTabular}{lcIcIc}[custom-line = {letter=I, color=blue}]
  \hline
            & \Block{1-3}{dimensions} \\
            & L & l & h \\
  \hline
  Product A & 3 & 1 & 2 \\
  Product B & 1 & 3 & 4 \\
  Product C & 5 & 4 & 1 \\
  \hline
  \end{NiceTabular}
                                                dimensions
                                                L l H
                                      Product A 3 1 2
                                      Product B 1 3 4
                                      Product C 5 4 1
  The key sep-color with the value white may also be used in case of an horizontal double-rule
  on the top of a colored cell (if we want the space between both rules above the cell not colored
  by the color of the cell).
  \NiceMatrixOptions
    {
      custom-line =
       {
         command = DoubleRule ,
         multiplicity = 2 ,
         sep-color = white
                                                                      one    two    three
       }
    }                                                                 four   five    six
  \begin{NiceTabular}{ccc}
  one & two & three \\
  \DoubleRule
  four & \cellcolor{yellow} five & six \\
  \end{NiceTabular}
• Second possibility
  It’s possible to use the key tikz (if TikZ is loaded). In that case, the rule is drawn directly
  with TikZ by using as parameters the value of the key tikz which must be a list of key=value
  pairs which may be applied to a TikZ path.
  By default, no space is reserved for the rule that will be drawn with TikZ. It is possible to
  specify a reservation (horizontal for a vertical rule and vertical for an horizontal one) with the
  key total-width. That value of that key, is, in some ways, the width of the rule that will be
  drawn (nicematrix does not compute that width from the characteristics of the rule specified in
  tikz).
                                              17
      \NiceMatrixOptions
        {
          custom-line =
           {
             letter = I ,
             tikz = dotted ,
             total-width = \pgflinewidth                                          one       two     three
           }                                                                      four      five      six
        }                                                                        seven     eight     nine
      \begin{NiceTabular}{cIcIc}
      one & two & three \\
      four & five & six \\
      seven & eight & nine
      \end{NiceTabular}
      In the environments with an explicit preamble (like {NiceTabular}, {NiceArray}, etc.), it’s
      possible to draw a vertical dotted line with the specifier “:”.
      $\left(\begin{NiceArray}{cccc:c}
      1 & 2 & 3 & 4 & 5 \\
                                                                                                           
                                                                                   1     2   3 4          5
      6 & 7 & 8 & 9 & 10 \\                                                      6      7   8 9          10
      11 & 12 & 13 & 14 & 15                                                      11     12 13 14         15
      \end{NiceArray}\right)
25 However, it’s possible to overwrite those definitions with a custom-line (in order, for example, to switch to dashed
lines).
                                                           18
6 The color of the background of the rows and columns
   • The package colortbl patches array, leading to some incompatibilities (for instance with the
     command \hdotsfor).
   • The package colortbl constructs the array row by row, alterning colored rectangles, rules and
     contents of the cells. The resulting pdf is difficult to interpret by some pdf viewers and may
     lead to artefacts on the screen.
           – Some rules seem to disappear. This is because many PDF viewers give priority to graphical
             element drawn posteriorly (which is in the spirit of the “painting model” of PostScript and
             PDF). Concerning this problem, MuPDF (which is used, for instance, by SumatraPDF)
             gives better results than Adobe Reader.
           – A thin white line may appear between two cells of the same color. This phenomenon
             occurs when each cell is colored with its own instruction fill (the PostScript operator
             fill noted f in PDF). This is the case with colortbl: each cell is colored on its own, even
             when \columncolor or \rowcolor is used.
             As for this phenomenon, Adobe Reader gives better results than MuPDF (however, it
             seems, that, in recent versions of MuPDF, the problem has been solved...).
         The package nicematrix provides tools to avoid both problems.
                                                         19
These commands don’t color the cells which are in the “corners” if the key corners is used. That
key has been described p. 14.
These commands respect the rounded corners if the key rounded-corners (described in the part 14.1
at the page 49) has been used.
All these commands accept an optional argument, between square brackets and in first position. That
optional argument may contain two elements (separated by a comma)
   • the colorimetric space (RGB, rgb, HTML, etc) as specified by the the extension xcolor;
   • The command \cellcolor takes its name from the command \cellcolor of colortbl.
      This command takes in as mandatory arguments a color and a list of cells, each of which with
      the format i-j where i is the number of the row and j the number of the colummn of the cell.
      In fact, despite its name, this command may be used to color a whole row (with the syntax i-)
      or a whole column (with the syntax -j).
      \begin{NiceTabular}{ccc}[hvlines]
      \CodeBefore
        \cellcolor[HTML]{FFFF88}{3-1,2-2,-3}
                                                                                    a    b   c
      \Body
      a & b & c \\                                                                  e    f   g
      e & f & g \\                                                                  h    i   j
      h & i & j \\
      \end{NiceTabular}
   • The command \rectanglecolor takes three mandatory arguments. The first is the color. The
     second is the upper-left cell of the rectangle and the third is the lower-right cell of the rectangle.
      \begin{NiceTabular}{ccc}[hvlines]
      \CodeBefore
        \rectanglecolor{blue!15}{2-2}{3-3}
                                                                                    a    b   c
      \Body
      a & b & c \\                                                                  e    f   g
      e & f & g \\                                                                  h    i   j
      h & i & j \\
      \end{NiceTabular}
   • The command \arraycolor takes in as mandatory argument a color and color the whole
     tabular with that color (except the potential exterior rows and columns: cf. p. 29). It’s only a
     particular case of \rectanglecolor.
   • The command \chessboardcolors takes in as mandatory arguments two colors and it colors
     the cells of the tabular in quincunx with these colors.
29 Caution: that feature creates instructions of transparency in the pdf and some readers of pdf don’t support such
instructions.
                                                         20
     $\begin{pNiceMatrix}[r,margin]
     \CodeBefore
       \chessboardcolors{red!15}{blue!15}
     \Body                                                                                       
     1 & -1 & 1 \\                                                              1      −1       1
                                                                              −1       1      −1 
     -1 & 1 & -1 \\
     1 & -1 & 1                                                                 1      −1       1
     \end{pNiceMatrix}$
We have used the key r which aligns all the columns rightwards (cf. p. 51).
 • The command \rowcolor takes its name from the command \rowcolor of colortbl. Its first
   mandatory argument is the color and the second is a comma-separated list of rows or interval
   of rows with the form a-b (an interval of the form a- represent all the rows from the row a until
   the end).
     $\begin{NiceArray}{lll}[hvlines]
     \CodeBefore
       \rowcolor{red!15}{1,3-5,8-}
     \Body
     a_1 & b_1 & c_1 \\                                                       a1     b1     c1
     a_2 & b_2 & c_2 \\                                                       a2     b2     c2
     a_3 & b_3 & c_3 \\                                                       a3     b3     c3
     a_4 & b_4 & c_4 \\                                                       a4     b4     c4
     a_5 & b_5 & c_5 \\                                                       a5     b5     c5
     a_6 & b_6 & c_6 \\                                                       a6     b6     c6
     a_7 & b_7 & c_7 \\                                                       a7     b7     c7
     a_8 & b_8 & c_8 \\                                                       a8     b8     c8
     a_9 & b_9 & c_9 \\                                                       a9     b9     c9
     a_{10} & b_{10} & c_{10} \\                                              a10    b10    c10
     \end{NiceArray}$
 • The command \columncolor takes its name from the command \columncolor of colortbl. Its
   syntax is similar to the syntax of \rowcolor.
 • The command \rowcolors (with a s) takes its name from the command \rowcolors of colortbl.
   The s emphasizes the fact that there is two colors. This command colors alternately the rows
   of the tabular with the two colors (provided in second and third argument), beginning with the
   row whose number is given in first (mandatory) argument. One of the arguments of color may
   be empty (no color is applied in the corresponding rows).
     In fact, the first (mandatory) argument is, more generally, a comma separated list of intervals
     describing the rows involved in the action of \rowcolors (an interval of the form i- describes
     in fact the interval of all the rows of the tabular, beginning with the row i).
     The last argument of \rowcolors is an optional list of pairs key=value (the optional argument
     in the first position corresponds to the colorimetric space). The available keys are cols, restart
     and respect-blocks.
        – The key cols describes a set of columns. The command \rowcolors will color only the
          cells of these columns. The value is a comma-separated list of intervals of the form i-j
          (where i or j may be replaced by *).
        – With the key restart , each interval of rows (specified by the first mandatory argument)
          begins with the same color.30
30 Otherwise, the color of a given row relies only upon the parity of its absolute number.
                                                           21
          – With the key respect-blocks the “rows” alternately colored may extend over several
            rows if they have to incorporate blocks (created with the command \Block: cf. p. 4).
     \begin{NiceTabular}{clr}[hvlines]
     \CodeBefore
       \rowcolors[gray]{2}{0.8}{}[cols=2-3,restart]
     \Body
     \Block{1-*}{Results} \\
                                                                                             Results
     John & 12 \\
     Stephen & 8 \\                                                                         John         12
                                                                                      A
     Sarah & 18 \\                                                                          Stephen       8
     Ashley & 20 \\                                                                         Sarah        18
     Henry & 14 \\                                                                          Ashley       20
                                                                                      B
     Madison & 15                                                                           Henry        14
     \end{NiceTabular}                                                                      Madison      15
     \begin{NiceTabular}{lr}[hvlines]
     \CodeBefore
       \rowcolors{1}{blue!10}{}[respect-blocks]
                                                                                                    12
     \Body                                                                            John
                                                                                                    13
     \Block{2-1}{John}    & 12 \\
                                                                                      Steph          8
                          & 13 \\
                                                                                                    18
     Steph                & 8 \\
     \Block{3-1}{Sarah}   & 18 \\                                                     Sarah         17
                          & 17 \\                                                                   15
                          & 15 \\                                                     Ashley        20
     Ashley               & 20 \\                                                     Henry         14
     Henry                & 14 \\                                                                   15
                                                                                      Madison
     \Block{2-1}{Madison} & 15 \\                                                                   19
                          & 19
     \end{NiceTabular}
 • The extension nicematrix provides also a command \rowlistcolors. This command generalises
   the command \rowcolors: instead of two successive arguments for the colors, this command
   takes in an argument which is a (comma-separated) list of colors. In that list, the symbol =
   represent a color identical to the previous one.
     \begin{NiceTabular}{c}
     \CodeBefore
       \rowlistcolors{1}{red!15,blue!15,green!15}
     \Body                                                                              Peter
     Peter \\                                                                           James
     James \\                                                                          Abigail
     Abigail \\                                                                       Elisabeth
     Elisabeth \\                                                                     Claudius
     Claudius \\                                                                         Jane
     Jane \\                                                                          Alexandra
     Alexandra \\
     \end{NiceTabular}
     It’s also possible to use in the command \rowlistcolors a color series defined by the command
     \definecolorseries of xcolor (and initialized with the command \resetcolorseries31 ).
31 For the initialization, in the following example, you have used the counter iRow (which corresponds to the internal
                                                           22
      \begin{NiceTabular}{c}
      \CodeBefore
         \definecolorseries{BlueWhite}{rgb}{last}{blue}{white}
         \resetcolorseries[\value{iRow}]{BlueWhite}
         \rowlistcolors{1}{BlueWhite!!+}                                                         Peter
      \Body                                                                                      James
      Peter \\                                                                                  Abigail
      James \\                                                                                 Elisabeth
      Abigail \\                                                                               Claudius
      Elisabeth \\                                                                                Jane
      Claudius \\                                                                              Alexandra
      Jane \\
      Alexandra \\
      \end{NiceTabular}
We recall that all the color commands we have described don’t color the cells which are in the
“corners”. In the following example, we use the key corners to require the determination of the
corner north east (NE).
\begin{NiceTabular}{ccccccc}[corners=NE,margin,hvlines,first-row,first-col]
\CodeBefore
  \rowlistcolors{1}{blue!15, }
                                                     0 1 2      3   4 5 6
\Body
                                                0    1
  & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\
                                                1    1 1
0 & 1 \\
                                                2    1 2 1
1 & 1 & 1 \\
2 & 1 & 2 & 1 \\                                3    1 3 3      1
3 & 1 & 3 & 3 & 1 \\                            4    1  4   6   4   1
4 & 1 & 4 & 6 & 4 & 1 \\                        5    1 5 10 10 5 1
5 & 1 & 5 & 10 & 10 & 5 & 1 \\                  6    1 6 15 20 15 6 1
6 & 1 & 6 & 15 & 20 & 15 & 6 & 1 \\
\end{NiceTabular}
The previous example uses the keys first-row and first-col which are described in the chapter
concerning the «exterior» rows and columns (cf. p. 29).
As one can see, by default, the coloring commands that we have described don’t apply in those exterior
rows and columns.
However, it may still be possible to color in those rows and columns by providing explicity the numbers
of those rows and columns.
In the following example, we require a color in the column 0 (which is the «first column» and which
exists because the key first-col has been used).
TeX counter \c@iRow) which, when used in the \CodeBefore (and in the \CodeAfter) corresponds to the number of
rows of the array: cf. p 52. That leads to an adjustement of the gradation of the colors to the size of the tabular.
                                                        23
\begin{NiceTabular}{ccccccc}[corners=NE,margin,hvlines,first-row,first-col]
\CodeBefore
  \rowlistcolors{1}{blue!15, }
  \columncolor{red!15}{0}                            0 1 2      3   4 5 6
\Body                                           0    1
  & 0 & 1 & 2 & 3 & 4 & 5 & 6 \\                1    1 1
0 & 1 \\                                        2    1 2 1
1 & 1 & 1 \\                                    3    1 3 3      1
2 & 1 & 2 & 1 \\                                4    1 4 6      4   1
3 & 1 & 3 & 3 & 1 \\                            5    1 5 10 10 5 1
4 & 1 & 4 & 6 & 4 & 1 \\                        6    1 6 15 20 15 6 1
5 & 1 & 5 & 10 & 10 & 5 & 1 \\
6 & 1 & 6 & 15 & 20 & 15 & 6 & 1 \\
\end{NiceTabular}
One should remark that all the previous commands are compatible with the commands of booktabs
(\toprule, \midrule, \bottomrule, etc). However, booktabs is not loaded by nicematrix.
\begin{NiceTabular}[c]{lSSSS}
\CodeBefore
  \rowcolor{red!15}{1-2}
  \rowcolors{3}{blue!15}{}
\Body
\toprule
\Block{2-1}{Product} &                                                dimensions (cm)
                                                                                                 Price
                                                        Product
\Block{1-3}{dimensions (cm)} & & &                                        L          l     h
\Block{2-1}{\rotate Price} \\
                                                         small        3           5.5     1      30
\cmidrule(rl){2-4}
                                                         standard     5.5         8       1.5    50.5
 & L & l & h \\
                                                         premium      8.5        10.5     2      80
\midrule
                                                         extra        8.5        10       1.5    85.5
small    & 3    & 5.5 & 1    & 30          \\
                                                         special     12          12       0.5    70
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}
We have used the type of column S of siunitx (which should be loaded by the user).
 New 7.1
It’s also possible, in the \CodeBefore, to use the commands \EmptyColumn and \EmptyRow. The
command \EmptyColumn takes in as argument a (comma-separated) list of numbers of columns and
requires that no rules nor background colors will be drawn in the corresponding columns. The
command \EmptyRow is similar for the rows.
\begin{NiceTabular}{ccccc}[hvlines,no-cell-nodes]
\CodeBefore
  \rowcolor{blue!15}{1}
  \EmptyColumn{3}                                                   one        two       three    four
\Body                                                                          two
                                                                    one                  three    four
   one & two && three & four \\                                               rows
   one & \Block{}{two\\ rows} && three & four \\
\end{NiceTabular}
                                                 24
These commands are the following several commands available (the first three ones are inspired by
the similar commands of colortbl).
   • \rowlistcolors which takes in as argument a color and color the rest of the tabular with the
     colors of that list of colors.34
These commands are compatible with the commands for the overlays of Beamer (\only, etc.)
\NewDocumentCommand { \Blue } { } { \columncolor{blue!15} }
\begin{NiceTabular}{>{\Blue}c>{\Blue}cc}
\toprule
\rowcolor{red!15}
Last name & First name & Birth day \\
\midrule
Achard & Jacques & 5 juin 1962 \\
Lefebvre & Mathilde & 23 mai 1988 \\
Vanesse & Stephany & 30 octobre 1994 \\
Dupont & Chantal & 15 janvier 1998 \\
\bottomrule
\end{NiceTabular}
Each use of the \rowlistcolors (or \rowcolors, which is, in fact, a special case of \rowlistcolors)
stops the potential coloring schemes35 specified by a previous command \rowlistcolors. In par-
ticular, it’s possible to start coloring the rows with \rowlistcolors{...} and stop coloring by a
command \rowlistcolors with an empty argument.
 32 That   command \cellcolor will delete the following spaces (which does not the command \cellcolor of colortbl).
Moreover, if one wishes to define a command above that command \cellcolor, it must be protected in the TeX
sens (whereas, if it were the command \cellcolor of colortbl, one should, no the contrary, write a fully expandable
command).
  33 If you want a commande to color the following n rows, consider the command \RowStyle and its key fillcolor,
p. 26
  34 When the command \rowlistcolors (or the command \rowcolors) is used in a cell of the column j of the array,
on different columns.
                                                          25
\begin{NiceTabular}{c}[hvlines]
one \\
two \\                                                                        one
\rowlistcolors{red!15}                                                        two
three \\                                                                     three
four \\                                                                       four
five \\                                                                       five
\rowlistcolors{}                                                               six
six \\                                                                       seven
seven \\
\end{NiceTabular}
The command \RowStyle takes in as argument some formatting intructions that will be applied to
each cell on the rest of the current row.
That command also takes in as optional argument (between square brackets) a list of key=value
pairs.
   • The key nb-rows sets the number of rows to which the specifications of the current command
     will apply (with the special value *, it will apply to all the following rows).
   • The keys cell-space-top-limit , cell-space-bottom-limit and cell-space-limits are
     available with the same meaning that the corresponding global keys (cf. p. 2).
   • The key fill (alias: rowcolor ) sets the color of the background and opacity 36 sets its opacity.
   • If the key rounded-corners is used, that background will have rounded-corners.
   • The key color sets the color of the text.37
   • The key bold enforces bold characters for the cells of the row, both in math and text mode.
\begin{NiceTabular}{cccc}
\hline
\RowStyle[cell-space-limits=3pt]{\rotate}
                                                                                                    second
                                                                                                                     fourth
                                                                                                             third
\RowStyle[nb-rows=2,fill=blue!50,color=white]{\sffamily}
1 & 2 & 3 & 4 \\                                                                             1        2        3       4
I & II & III & IV                                                                            I        II      III     IV
\end{NiceTabular}
36 Caution: that feature creates instructions of transparency in the pdf and some readers of pdf don’t support such
instructions.
  37 The key color uses the command \color but also inserts an instruction \leavevmode before. This instruction
prevents an extra vertical space in the cells which belong to columns of type p, b, m and X (which start in vertical
mode of LaTeX). For the columns V (of varwidth), that’s not enough, except when LuaLaTeX is used with the package
luacolor (see question 460489 on TeX StackExchange).
                                                         26
8 The width of the columns
In the environments of nicematrix, it’s also possible to fix the minimal width of all the columns (except
the potential exterior columns: cf. p. 29) directly with the key columns-width.
$\begin{pNiceMatrix}[columns-width = 1cm]
1 & 12 & -123 \\
                                                                                                                
                                                                                1                12         −123
12 & 0 & 0     \\                                                             12                 0          0 
4 & 1 & 2                                                                       4                 1          2
\end{pNiceMatrix}$
Note that the space inserted between two columns (equal to 2 \tabcolsep in {NiceTabular} and
to 2 \arraycolsep in the other environments) is not suppressed (of course, it’s possible to suppress
this space by setting \tabcolsep or \arraycolsep equal to 0 pt before the environment).
It’s possible to give the special value auto to the option columns-width: all the columns of the array
will have a width equal to the widest cell of the array.38
$\begin{pNiceMatrix}[columns-width = auto]
1 & 12 & -123 \\
                                                                                                          
                                                                                1            12       −123
12 & 0 & 0     \\                                                             12             0        0 
4 & 1 & 2                                                                       4             1        2
\end{pNiceMatrix}$
Without surprise, it’s possible to fix the minimal width of the columns of all the arrays of a current
scope with the command \NiceMatrixOptions.
\NiceMatrixOptions{columns-width=10mm}
$\begin{pNiceMatrix}
a & b \\ c & d
\end{pNiceMatrix}
                                                                                                                   
                                                                        a            b                 1       1245
=                                                                                            =
                                                                        c            d                345        2
\begin{pNiceMatrix}
1   & 1245 \\ 345 & 2
\end{pNiceMatrix}$
It’s also possible to fix a zone where all the matrices will have their columns of the same width, equal
to the widest cell of all the matrices. This construction uses the environment {NiceMatrixBlock}
with the option auto-columns-width39 . The environment {NiceMatrixBlock} has no direct link
with the command \Block presented previously in this document (cf. p. 4).
38 The result is achieved with only one compilation (but PGF/TikZ will have written informations in the aux file and
future.
                                                         27
\begin{NiceMatrixBlock}[auto-columns-width]
$\begin{array}{c}
\begin{bNiceMatrix}                                                                         
                                                                         9            17
 9 & 17 \\ -2 & 5
                                                                         −2            5
 \end{bNiceMatrix} \\ \\
\begin{bNiceMatrix}                                                                         
                                                                          1        1245345
 1   & 1245345 \\ 345 & 2
                                                                         345          2
\end{bNiceMatrix} \\
\end{array}$
\end{NiceMatrixBlock}
\begin{NiceTabular}[width=9cm]{X[c,m]X[0.5,c,m]}[hvlines]
a rather long text which fits on several lines
& a rather long text which fits on several lines \\
a shorter text & a shorter text
\end{NiceTabular}
                                                                           a rather long
                             a rather long text which fits on
                                                                         text which fits on
                                       several lines
                                                                            several lines
                                       a shorter text                      a shorter text
ragged2e instead of the commands \raggedright, \centering and \raggedleft. That ensures a better output.
                                                           28
\fbox{%
\begin{varwidth}{8cm}
\begin{itemize}                              • first item
\item first item
\item second item                            • second item
\end{itemize}
\end{varwidth}}
\fbox{%
\begin{minipage}{8cm}
\begin{itemize}                              • first item
\item first item
\item second item                            • second item
\end{itemize}
\end{minipage}}
The package varwidth provides also the column type V. A column of type V{hdimi} encapsulates all
its cells in a {varwidth} with the argument hdimi (and does also some tuning).
When the package varwidth is loaded, the columns V of varwidth are supported by nicematrix.
\begin{NiceTabular}[corners=NW,hvlines]{V{3cm}V{3cm}V{3cm}}
& some text & some very very very long text \\
some very very very long text \\
some very very very long text
\end{NiceTabular}
Concerning nicematrix, one of the interests of this type of columns is that, for a cell of a column of
type V, the PGF/TikZ node created by nicematrix for the content of that cell has a width adjusted
to the content of the cell : cf. p. 56.
The columns V of nicematrix supports the keys t, p, m, b, l, c and r also supported by the columns
X: see their description in the section 8.2, p. 28.
One should remark that the extension varwidth (at least in its version 0.92) has some problems: for
instance, with LuaLaTeX, it does not work when the content begins with \color.
The options first-row , last-row, first-col and last-col allow the composition of exterior rows
and columns in the environments of nicematrix. It’s particularly interesting for the (mathematical)
matrices.
A potential “first row” (exterior) has the number 0 (and not 1). Idem for the potential “first column”.
                                                   29
$\begin{pNiceMatrix}[first-row,last-row,first-col,last-col,nullify-dots]
       & C_1    & \Cdots &        & C_4    &        \\
L_1    & a_{11} & a_{12} & a_{13} & a_{14} & L_1    \\
\Vdots & a_{21} & a_{22} & a_{23} & a_{24} & \Vdots \\
       & a_{31} & a_{32} & a_{33} & a_{34} &        \\
L_4    & a_{41} & a_{42} & a_{43} & a_{44} & L_4    \\
       & C_1    & \Cdots &        & C_4    &
\end{pNiceMatrix}$
                                         C1                      C4 
                                      L1 a11     a12        a13   a14 L1
                                        a21     a22        a23   a24 
                                                                     
                                        a31     a32        a33   a34 
                                      L4 a41     a42        a43   a44 L4
                                          C1                      C4
The dotted lines have been drawn with the tools presented p. 31.
   • One may wonder how nicematrix determines the number of rows and columns which are needed
     for the composition of the “last row” and “last column”.
         – For the environments with explicit preamble, like {NiceTabular} and {pNiceArray}, the
           number of columns can obviously be computed from the preamble.
         – When the option light-syntax (cf. p. 53) is used, nicematrix has, in any case, to load the
           whole body of the environment (and that’s why it’s not possible to put verbatim material
           in the array with the option light-syntax). The analysis of this whole body gives the
           number of rows and the number of columns.
         – In the other cases, nicematrix compute the number of rows and columns during the first
           compilation and write the result in the aux file for the next run.
           However, it’s possible to provide the number of the last row and the number of the last
           column as values of the options last-row and last-col, tending to an acceleration of the
           whole compilation of the document. That’s what we will do throughout the rest of the
           document.
It’s possible to control the appearance of these rows and columns with options code-for-first-row,
code-for-last-row , code-for-first-col and code-for-last-col. These options specify tokens
that will be inserted before each cell of the corresponding row or column.
\NiceMatrixOptions{code-for-first-row = \color{red},
                         code-for-first-col = \color{blue},
                         code-for-last-row = \color{green},
                         code-for-last-col = \color{magenta}}
\begin{displaymath}
\begin{pNiceArray}{cc|cc}[first-row,last-row=5,first-col,last-col,nullify-dots]
         & C_1       & \multicolumn1c{\Cdots} &               & C_4     &         \\
L_1      & a_{11} & a_{12} & a_{13} & a_{14} & L_1              \\
\Vdots & a_{21} & a_{22} & a_{23} & a_{24} & \Vdots \\
\hline
43 The users wishing exterior columns with another type of alignment should consider the command \SubMatrix
                                                       30
       & a_{31} & a_{32} & a_{33} & a_{34} &                                \\
L_4    & a_{41} & a_{42} & a_{43} & a_{44} & L_4                            \\
       & C_1     & \multicolumn1c{\Cdots} &                               & C_4        &
\end{pNiceArray}
\end{displaymath}
                                              C1                       C4 
                                           L1 a11      a12        a13   a14 L1
                                             a21      a22        a23   a24 
                                                                           
                                             a31      a32        a33   a34 
                                           L4 a41      a42        a43   a44 L4
                                               C1                       C4
Remarks
   • As shown in the previous example, the horizontal and vertical rules don’t extend in the exterior
     rows and columns. This remark also applies to the customized rules created by the key custom-
     line (cf. p. 16).
   • A specification of color present in code-for-first-row also applies to a dotted line drawn in
     that exterior “first row” (except if a value has been given to xdots/color). Idem for the other
     exterior rows and columns.
   • Logically, the potential option columns-width (described p. 27) doesn’t apply to the “first
     column” and “last column”.
   • For technical reasons, it’s not possible to use the option of the command \\ after the “first row”
     or before the “last row”. The placement of the delimiters would be wrong. If you are looking for
     a workaround, consider the command \SubMatrix in the \CodeAfter (and the \CodeBefore)
     described p. 40.
Inside the environments of the package nicematrix, new commands are defined: \Ldots , \Cdots ,
\Vdots , \Ddots and \Iddots . These commands are intended to be used in place of \dots, \cdots,
\vdots, \ddots and \iddots.44
Each of them must be used alone in the cell of the array and it draws a dotted line between the
first non-empty cells45 on both sides of the current cell. Of course, for \Ldots and \Cdots, it’s an
horizontal line; for \Vdots, it’s a vertical line and for \Ddots and \Iddots diagonal ones. It’s possible
to change the color of these lines with the option color.46
\begin{bNiceMatrix}                                                                                      
                                                                                  a1                 a1
a_1      & \Cdots &        & & a_1    \\
\Vdots   & a_2    & \Cdots & & a_2    \\
                                                                                                       
                                                                                      a2            a2 
         & \Vdots & \Ddots[color=red] \\
                                                                                                       
                                                                                                       
\\
                                                                                                       
                                                                                                       
a_1      & a_2    &        & & a_n
                                                                                                       
\end{bNiceMatrix}                                                                 a1   a2            an
In order to represent the null matrix, one can use the following codage:
44 The command \iddots, defined in nicematrix, is a variant of \ddots with dots going forward. If mathdots is loaded,
                                                             31
\begin{bNiceMatrix}
0      & \Cdots & 0      \\
                                                                                          
                                                                               0          0
\Vdots &        & \Vdots \\                                                               
0      & \Cdots & 0
                                                                                          
                                                                               0          0
\end{bNiceMatrix}
However, one may want a larger matrix. Usually, in such a case, the users of LaTeX add a new row
and a new column. It’s possible to use the same method with nicematrix:
\begin{bNiceMatrix}                                                                                
                                                                               0                   0
0      & \Cdots & \Cdots            &   0      \\
\Vdots &        &                   &   \Vdots \\
                                                                                                   
                                                                                                   
\Vdots &        &                   &   \Vdots \\
                                                                                                   
                                                                                                   
0      & \Cdots & \Cdots            &   0
                                                                                                   
\end{bNiceMatrix}                                                              0                   0
In the first column of this example, there are two instructions \Vdots but, of course, only one dotted
line is drawn.
In fact, in this example, it would be possible to draw the same matrix more easily with the following
code:
\begin{bNiceMatrix}                                                                                
                                                                               0                   0
0       & \Cdots &                   & 0      \\
\Vdots &          &                  &        \\
                                                                                                   
                                                                                                   
        &         &                  & \Vdots \\
                                                                                                   
                                                                                                   
0       &         & \Cdots           & 0
                                                                                                   
\end{bNiceMatrix}                                                              0                   0
There are also other means to change the size of the matrix. Someone might want to use the optional
argument of the command \\ for the vertical dimension and a command \hspace* in a cell for the
horizontal dimension.47
However, a command \hspace* might interfer with the construction of the dotted lines. That’s why
the package nicematrix provides a command \Hspace which is a variant of \hspace transparent for
the dotted lines of nicematrix.
                                                                                   
$\begin{bNiceMatrix}                                              0               0
0       & \Cdots & \Hspace*{1cm} & 0              \\
                                                                                   
                                                                                   
\Vdots &            &                 & \Vdots \\[1cm]
                                                                                   
                                                                                   
0       & \Cdots &                    & 0
                                                                                   
                                                                                   
\end{bNiceMatrix}$
                                                                                   
                                                                  0               0
If we add \ldots instructions in the second row, the geometry of the matrix is modified.
47 In nicematrix, one should use \hspace* and not \hspace for such an usage because nicematrix loads array. One may
also remark that it’s possible to fix the width of a column by using the environment {NiceArray} (or one of its variants)
with a column of type w or W: see p. 27
                                                           32
$B = \begin{pmatrix}
h & i & j & k & l & m \\
                                                                                                                             
                                                                                       h i             j     k     l      m
x & \ldots & \ldots & \ldots & \ldots & x                                        B=
                                                                                        x ...         ...   ...   ...     x
\end{pmatrix}$
By default, with nicematrix, if we replace {pmatrix} by {pNiceMatrix} and \ldots by \Ldots, the
geometry of the matrix is not changed.
$C = \begin{pNiceMatrix}
h & i & j & k & l & m \\
                                                                                                                             
                                                                                          h   i       j     k         l   m
x & \Ldots & \Ldots & \Ldots & \Ldots & x                                        C=
                                                                                          x                               x
\end{pNiceMatrix}$
However, one may prefer the geometry of the first matrix A and would like to have such a geometry
with a dotted line in the second row. It’s possible by using the option nullify-dots (and only one
instruction \Ldots is necessary).
$D = \begin{pNiceMatrix}[nullify-dots]
h & i & j & k & l & m \\
                                                                                                                     
                                                                                          h i     j    k    l     m
x & \Ldots & & & & x                                                             D=
                                                                                          x                       x
\end{pNiceMatrix}$
The option nullify-dots smashes the instructions \Ldots (and the variants) horizontally but also
vertically.
Caution: the key nullify-dots has a name that may be confusing; that key does not imply that
the dotted rules won’t be drawn!
However, if these cells are empty, the dotted line extends only in the cells specified by the argument
of \Hdotsfor (by design).
$\begin{pNiceMatrix}
1 & 2 & 3 & 4 & 5 \\
                                                                            
                                                           1    2   3   4   5
  & \Hdotsfor{3} \\                                                         
1 & 2 & 3 & 4 & 5 \\
                                                                            
                                                       1       2   3   4   5
1 & 2 & 3 & 4 & 5                                        1      2   3   4   5
\end{pNiceMatrix}$
Remark: Unlike the command \hdotsfor of amsmath, the command \Hdotsfor may be used even
when the package colortbl48 is loaded (however, with nicematrix, loading colortbl is rather point-less
since nicematrix provides its own coloring tools: cf. p. 19).
48 We recall that when xcolor is loaded with the option table, the package colortbl is loaded.
                                                               33
The package nicematrix also provides a command \Vdotsfor similar to \Hdotsfor but for the vertical
dotted lines. The following example uses both \Hdotsfor and \Vdotsfor:
\begin{bNiceMatrix}
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)}] \\
\Vdots & \Ddots & \Vdots
  & \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
C[a_n,a_1] & \Cdots & C[a_n,a_n]
  & & C[a_n,a_1^{(p)}] & \Cdots & C[a_n,a_n^{(p)}] \\
\rule{0pt}{15mm}\NotEmpty & \Vdotsfor{1} & & \Ddots & & \Vdotsfor{1} \\
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)}] \\
\Vdots & \Ddots & \Vdots
  & \Hdotsfor{1} & \Vdots & \Ddots & \Vdots \\
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)}]
\end{bNiceMatrix}
                                                                           (p)                (p)
                                                                                                   
                C[a1 , a1 ]       C[a1 , an ]                    C[a1 , a1 ]          C[a1 , an ]
                                                                                                 
                                                                                                 
                                                                                                 
                                                                           (p)                (p) 
             C[an , a1 ]         C[an , an ]                    C[an , a1 ]          C[an , an ] 
            
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                (p)                  (p)                             (p)   (p)           (p) (p) 
            C[a1 , a1 ]         C[a1 , an ]                    C[a1 , a1 ]           C[a1 , an ]
            
                                                                                                 
                                                                                                 
                                                                                                 
                (p)                  (p)                             (p)   (p)           (p) (p)
             C[an , a1 ]         C[an , an ]                    C[an , a1 ]           C[an , an ]
Therefore, with the keys renew-dots and renew-matrix, a classical code gives directly the ouput of
nicematrix.
49 The options renew-dots, renew-matrix can be fixed with the command \NiceMatrixOptions like the other options.
                                                       34
\NiceMatrixOptions{renew-dots,renew-matrix}
\begin{pmatrix}
                                                                                              
                                                                    1                         1
1      & \cdots & \cdots & 1      \\                               
                                                                   0
                                                                                               
0      & \ddots &        & \vdots \\
                                                                                               
                                                                                              
\vdots & \ddots & \ddots & \vdots \\
                                                                                              
                                                                                              
0      & \cdots & 0      & 1                                        0                    0    1
\end{pmatrix}
$\begin{bNiceMatrix}
                                                                                             
                                                                    1                        0
1 & \hspace*{1cm}            & 0 \\[8mm]                                 n
                                                                              ti
                                                                                              
                                                                                m
                                                                                             
  & \Ddots^{n \text{ times}} &   \\                                
                                                                                   es
                                                                                              
                                                                                              
0 &                          & 1                                                             
\end{bNiceMatrix}$
                                                                                             
                                                                    0                        1
$\begin{bNiceMatrix}
                                                                                     
                                                                   1                 0
1 & \hspace*{1cm}            & 0 \\[8mm]                          
                                                                             n times 
                                                                                      
  & \Ddots[horizontal-label]^{n \text{ times}} &               \\ 
                                                                  
                                                                                      
                                                                                      
0 &                          & 1                                                     
\end{bNiceMatrix}$
                                                                                     
                                                                   0                 1
For an individual command, it’s possible to write horizontal-label (in the singular).
These options may also be fixed with \NiceMatrixOptions, as options of \CodeAfter or at the level
of a given environment but, in those cases, they must be prefixed by xdots (xdots to remind that it
works for \Cdots, \Ldots, \Vdots, etc.), and, thus have for names:
  • xdots/horizontal-labels;
  • xdots/color;
  • xdots/radius;
                                                  35
   • xdots/shorten-start, xdots/shorten-end and xdots/shorten;
   • xdots/inter;
   • xdots/line-style.
For the clarity of the explanations, we will use those names.
With the key xdots/horizontal-labels, the labels (introduced by _, ^ and :) stay horizontal.
The option xdots/color fixes the color or the dotted line. It’s possible to use a color definied “on
the fly” (e.g.: xdots/color = { [RGB]{204,204,255} }). One should remark that the dotted lines
drawn in the exterior rows and columns have a special treatment: cf. p. 29.
The option radius fixes the radius of the dots. The initial value is 0.53 pt.
The keys xdots/shorten-start and xdots/shorten-end fix the margin at the extremities of the
line. The key xdots/shorten fixes both parameters. The initial value is 0.3 em (it is recommanded
to use a unit of length dependent of the current font).50
The option xdots/inter fixes the length between the dots. The initial value is 0.45 em (it is
recommanded to use a unit of length dependent of the current font).
at the level of an environment (such as {pNiceMatrix}), those keys only apply to the extremeties of dotted lines
corresponding to a non-empty content of a cell. When they are used for a command such as \Cdots (and, in that case,
their names are shorten, shorten-start and shorten-end), they apply to all the extremities.
  51 The first reason of this behaviour is that the pdf format includes a description for dashed lines. The lines specified
with this descriptor are displayed very efficiently by the pdf readers. It’s easy, starting from these dashed lines, to
create a line composed by square dots whereas a line of rounded dots needs a specification of each dot in the pdf file.
Nevertheless, you can have a look at the following page to see how to have dotted rules with rounded dots in TikZ:
https://tex.stackexchange.com/questions/52848/tikz-line-with-large-dots
                                                            36
10.6    The commands \Hbrace and \Vbrace
New 7.1
Since, as said in the previous part, it’s possible to use, with the commands \Cdots, \Ldots, \Vdots,
etc. all the styles of lines provided by TikZ, one may wish to use those commands to draw braces
with the decoration brace provided by the library decorations.pathreplacing of TikZ.
In order to facilitate that use, nicematrix provides two commands \Hbrace and \Vbrace . Those
commands are available only if TikZ has been loaded with its library decorations.pathreplacing (before
or after the loading of nicematrix). Otherwise, a (non-fatal) error will be raised.
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
The commands \Hbrace and \Vbrace have the same syntax. Both commands take in three arguments:
  • an optional argument, between square brackets, which contains a list of key=value pairs: the
    keys allowed are color, horizontal-labels, shorten, shorten-start and shorten-end.
  • a mandatory argument which is the number of columns (for \Hbrace) or the number of rows
    (for \Vbrace) over which the command applies;
$\begin{NiceArray}{ccccc}%
  [ hvlines ,
    first-row ,
    last-row = 6,
                                                                                   p               q
    first-col ,
    last-col ,                                                             1   1        134    1       1
    xdots/horizontal-labels ]                                          p   1   1        134    1       1   p
& \Hbrace{3}{p} & \Hbrace{2}{q} \\                                         1   1       13456   1       1
\Vbrace{3}{p} & 1 & 1 & 134 & 1 & 1 & \Vbrace{3}{p} \\                     1   1        134    1       1
                                                                       q                                   q
& 1 & 1 & 134 & 1 & 1 \\                                                   1   1        134    1       1
& 1 & 1 & 13456 & 1 & 1 \\                                                         p               q
\Vbrace{2}{q} & 1 & 1 & 134 & 1 & 1 & \Vbrace{2}{q}\\
& 1 & 1 & 134 & 1 & 1 \\
& \Hbrace{3}{p} & \Hbrace[color=blue]{2}{q} \\
\end{NiceArray}$
The TikZ style used by nicematrix to draw those braces is called nicematrix/brace. Here is the
initial value of that style:
decoration = { brace , raise = -0.15 em } ,
decorate
The final user can change that style TikZ as he wishes (respecting the structure with the keys
decorate and decoration).
For another example of use of \Hbrace and \Vbrace, see the section “Dotted lines that are no longer
dotted”, p. 67.
                                                 37
vlines, hvlines and hvlines-except-borders and by the tools created by custom-line are not
drawn within the blocks).52
$\begin{bNiceMatrix}[margin,hvlines]
\Block{3-3}<\LARGE>{A} & & & 0 \\
                                                                                                       
                                                                                                    0
& \hspace*{1cm} & & \Vdots \\                                                  
                                                                                       A             
                                                                                                      
& & & 0 \\                                                                                           
                                                                                                    0 
0 & \Cdots& 0 & 0
                                                                               
                                                                                   0            0   0
\end{bNiceMatrix}$
In the environments with preamble ({NiceArray}, {pNiceArray}, etc.), it’s possible to put vertical
delimiters directly in the preamble of the environment.53
The opening delimiters should be prefixed by the keyword \left and the closing delimiters by the
keyword \right . It’s not mandatory to use \left and \right pair-wise.
All the vertical extensible delimiters of LaTeX are allowed.
Here is a example which uses the delimiters \lgroup and \rgroup.
$\begin{NiceArray}{\left\lgroup ccc\right\rgroup l}
1 & 2 & 3 &
4 & 1 & 6 &
7 & 8 & 9 & \scriptstyle L_3 \gets L_3 + L_1 + L_2
\end{NiceArray}$
                                                         
                                            1       2   3
                                          
                                                        
                                            4       1   6
                                          
                                          
                                          
                                                        
                                                         
                                                         
                                            7       8   9 L3 ←L3 +L1 +L2
                                          
For this example, it would also have been possible to use the environment {NiceArrayWithDelims}
(cf. the section 14.10, p. 54) and the key last-col (cf. p. 29).
There is a particular case: for the delimiters (, [ and \{54 , and the corresponding closing delimiters,
the prefixes \left et \right are optional.55
Here is an example with a left delimiter \{ in a {NiceTabular} (remark the compatibility with the
key t).
When there are two successive delimiters (necessarily a closing one following by an opening one for
another submatrix), a space equal to \enskip is automatically inserted.
 52 On   the other side, the command \line in the \CodeAfter (cf. p. 39) does not create block.
 53 This  syntax is inspired by the extension blkarray.
  54 For the braces, the protection by a backslash is mandatory (that’s why we have written \{).
  55 For the delimiters [ and ], the prefixes remain mandatory when there is a conflict of notation with the square
                                                          38
$\begin{pNiceArray}{(c)(c)(c)}
a_{11} & a_{12}                                     & a_{13} \\
a_{21} & \displaystyle \int_0^1\dfrac{1}{x^2+1}\,dx & a_{23} \\
a_{31} & a_{32}                                     & a_{33}
\end{pNiceArray}$
                                                         
                                           a11      a12        a13
                                        1 1 Z            
                                       a21
                                                      dx  a23 
                                                                  
                                               x 2+1           
                                                 0
                                         a31        a32        a33
For more complex constructions, in particular with delimiters spanning only a subset of the rows
of the array, one should consider the command \SubMatrix available in the \CodeAfter (and the
\CodeBefore). See the section 12.2, p. 40.
12 The \CodeAfter
The option code-after may be used to give some code that will be executed after the construction
of the matrix.56
For the legibility of the code, an alternative syntax is provided: it’s possible to give the instructions of
the code-after at the end of the environment, after the keyword \CodeAfter (the key code-after
is of course mandatory in the \AutoNiceMatrix and the similar commands). Although \CodeAfter
is a keyword, it takes in an optional argument (between square brackets).57
The experienced users may, for instance, use the PGF/TikZ nodes created by nicematrix in the
\CodeAfter. These nodes are described further beginning on p. 54.
The \CodeAfter provides several special commands: \line, \SubMatrix, \OverBrace, \UnderBrace
and \TikzEveryCell. We will now present these commands.
One should avoid spurious spaces in that \CodeAfter.58
   • a specification of cell of the form i-j where is the number of the row and j is the number of the
     column;
   • the name of a block (created by the command \Block with the key name of that command).
The options available for the customisation of the dotted lines created by \Cdots, \Vdots, etc. are
also available for this command (cf. p. 35).
This command may be used, for example, to draw a dotted line between two adjacent cells.
                                                       39
\NiceMatrixOptions{xdots/shorten = 0.6 em}
\begin{pNiceMatrix}                                                                                  
                                                                                     I   0        0
I       & 0       & \Cdots &0     \\
0       & I       & \Ddots &\Vdots\\
                                                                                                   
                                                                                 0      I          
\Vdots &\Ddots & I         &0     \\
                                                                                                   
                                                                                                   
0       &\Cdots & 0        &I
                                                                                             I   0
\CodeAfter \line{2-2}{3-3}                                                         0          0   I
\end{pNiceMatrix}
It can also be used to draw a diagonal line not parallel to the other diagonal lines (by default, the
dotted lines drawn by \Ddots are “parallelized”: cf. p. 60).
\begin{bNiceMatrix}
1      & \Cdots &   & 1      & 2      & \Cdots                             & 2      \\
0      & \Ddots &   & \Vdots & \Vdots & \hspace*{2.5cm}                    & \Vdots \\
\Vdots & \Ddots &   &        &        &                                    &        \\
0      & \Cdots & 0 & 1      & 2      & \Cdots                             & 2
\CodeAfter \line[shorten=6pt]{1-5}{4-7}
\end{bNiceMatrix}
                                                                            
                                 1             1   2                        2
                                                                            
                                0                                           
                                                                            
                                                                            
                                                                            
                                 0         0   1   2                        2
59 There is no optional argument between square brackets in first position because a square bracket just after
\SubMatrix must be interpreted as the first (mandatory) argument of the command \SubMatrix: that bracket is
the left delimiter of the sub-matrix to construct (eg.: \SubMatrix[{2-2}{4-7}]).
                                                       40
Eventually, in this example, it would probably have been easier to put the delimiters directly in the
preamble of {NiceArray} (see section 11, p. 38) with the following construction.
$\begin{NiceArray}{(ccc)(c)}[cell-space-limits=2pt]                                         
                                                                            1       1     1    x
 1          & 1           & 1           & x \\                            1        1     1
\dfrac{1}{4} & \dfrac{1}{2} & \dfrac{1}{4} & y \\
                                                                                              
                                                                                            y 
                                                                          4        2     4  
 1          & 2           & 3           & z
                                                                            1       2     3    z
\end{NiceArray}$
In fact, the command \SubMatrix also takes in two optional arguments specified by the traditional
symbols ^ and _ for material in superscript and subscript (but no space is reserved for that material).
$\begin{bNiceMatrix}[right-margin=1em]
1 & 1 & 1 \\
1 & a & b \\
                                                                                          
                                                                          1 1          1
1 & c & d
                                                                                          T
                                                                         1 a           b 
\CodeAfter                                                                1 c           d
  \SubMatrix[{2-2}{3-3}]^{T}
\end{bNiceMatrix}$
All these keys are also available in \NiceMatrixOptions, at the level of the environments of nicematrix
or as option of the command \CodeAfter with the prefix sub-matrix which means that their names
are therefore sub-matrix/left-xshift, sub-matrix/right-xshift, sub-matrix/xshift, etc.
$\begin{NiceArray}{cc@{\hspace{5mm}}l}[cell-space-limits=2pt]
  &   & \frac{1}{2} \\
  &   & \frac{1}{4} \\[1mm]                                                             1
                                                                                                    !
a & b & \frac{1}{2}a+\frac{1}{4}b \\                                                    2
c & d & \frac{1}{2}c+\frac{1}{4}d \\
                                                                                        1
                                                                                        4
\CodeAfter
                                                                                    !               !
                                                                                        1      1
                                                            a                   b       2a +   4b
  \SubMatrix({1-3}{2-3})                                                                1      1
  \SubMatrix({3-1}{4-2})                                    c                   d       2c +   4d
  \SubMatrix({3-3}{4-3})
\end{NiceArray}$
                                                  41
Here is the same example with the key slim used for one of the submatrices.
$\begin{NiceArray}{cc@{\hspace{5mm}}l}[cell-space-limits=2pt]
  &   & \frac12 \\
  &   & \frac14 \\[1mm]                                                           1
                                                                                   !
a & b & \frac12a+\frac14b \\                                                      2
c & d & \frac12c+\frac14d \\
                                                                                  1
                                                                                  4
\CodeAfter
                                                                              !               !
                                                                                  1      1
                                                            a             b       2a +   4b
  \SubMatrix({1-3}{2-3})[slim]                                                    1      1
  \SubMatrix({3-1}{4-2})                                    c             d       2c +   4d
  \SubMatrix({3-3}{4-3})
\end{NiceArray}$
There is also a key name which gives a name to the submatrix created by \SubMatrix. That name is
used to create PGF/TikZ nodes: cf p. 59.
Despite its name, the command \SubMatrix may also be used within a {NiceTabular}. Here is an
example (which uses \bottomrule and \toprule of booktabs).
\begin{NiceTabular}{@{}ll@{}}
\toprule
Part A              & the first part \\
\Block{2-1}{Part B} & a first sub-part \\                       Part A  the first part
                    & a second sub-part \\                               a first sub-part
\bottomrule                                                     Part B a second sub-part
\CodeAfter
  \SubMatrix{\lbrace}{2-2}{3-2}{.}
\end{NiceTabular}
The command \SubMatrix is, in fact, also available in the \CodeBefore. By using \SubMatrix in
the \CodeBefore, the delimiters drawn by those commands \SubMatrix are taken into account to
limit the continuous dotted lines (drawn by \Cdots, \Vdots, etc.) which have an open extremity.
For an example, see voir 18.9 p. 75.
Caution : The following functionnality is fragile and does not work with latex–dvips–ps2pdf.
The key code of the command \SubMatrix allows the insertion of code after the construction of
the submatrix. It’s meant to be used to insert TikZ instructions because, in the TikZ instructions
inserted by that code, the nodes of the form i-j.anchor or i-|j are interpreted with i and j as
numbers of row and column relative to the submatrix.60
$\begin{NiceArray}{ccc@{}w{c}{5mm}@{}ccc}
    &   &   && -1 & 1 & 2 \\
    &   &   && 0 & 3 & 4 \\
    &   &   && 0 & 0 & 5 \\
  1 & 2 & 3 && -1 & 7 & 25 \\
  0 & 4 & 5 && 0 & 12 & 41 \\
  0 & 0 & 6 && 0 & 0 & 30
\CodeAfter
  \NewDocumentCommand{\MyDraw}{}{\tikz \draw [blue] (2-|1) -| (3-|2) -|
      (4-|3) ;}
  \SubMatrix({1-5}{3-7})[code = \MyDraw ]
  \SubMatrix({4-1}{6-3})[code = \MyDraw ]
  \SubMatrix({4-5}{6-7})[code = \MyDraw ]
\end{NiceArray}$
                                                    42
                                                                    
                                                      −1     1    2
                                                      0     3    4
                                                    0     0    5
                                         1    2   3 −1       7    25
                                        0    4   5  0    12    41 
                                         0    0   6    0     0    30
As we see, the drawing done by our command \MyDraw is relative to the submatrix to which it is
applied.
\begin{pNiceMatrix}
1 & 2 & 3 & 4 & 5 & 6 \\                                                 A          B
11 & 12 & 13 & 14 & 15 & 16 \\                                   z      }|    {z   }|     {
                                                                       1 2    3   4 5    6
\CodeAfter
                                                                      11 12   13 14 15   16
  \OverBrace{1-1}{2-3}{A}
  \OverBrace{1-4}{2-6}{B}
\end{pNiceMatrix}
Caution: There is no vertical space reserved for those braces and their labels.61
In fact, the commands \OverBrace and \UnderBrace take in an optional argument (in first position
and between square brackets) for a list of key=value pairs. The available keys are:
  • left-shorten and right-shorten which do not take in value; when the key left-shorten is
    used, the abscissa of the left extremity of the brace is computed with the contents of the cells
    of the involved sub-array, otherwise, the position of the potential vertical rule is used (idem for
    right-shorten).
  • shorten , which is the conjunction of the keys left-shorten and right-shorten;
  • yshift , which shifts vertically the brace (and its label);
  • color, which sets the color of the brace (and its label).
\begin{pNiceMatrix}
1 & 2 & 3 & 4 & 5 & 6 \\                                              A             B
11 & 12 & 13 & 14 & 15 & 16 \\                                   z   }|       { z  }|    {
                                                                    1 2       3   4 5    6
\CodeAfter
                                                                   11 12      13 14 15   16
  \OverBrace[shorten,yshift=3pt]{1-1}{2-3}{A}
  \OverBrace[shorten,yshift=3pt]{1-4}{2-6}{B}
\end{pNiceMatrix}
61 See: https://tex.stackexchange.com/questions/685755
                                                     43
12.4    The command \TikzEveryCell in the \CodeAfter
The command \TikzEveryCell executes with TikZ the rectangular path corresponding to each cell
of the tabular with parameters of TikZ the argument of \TikzEveryCell. That argument must be a
list of key=value pairs which may be applied to a TikZ path. In fact, the command applies to each of
the tabular, except those in the exterior rows and columns (cf. p. 29) and those in the empty corners
(when the key corners is used: cf. p. 14). It applies in fact to each block (excepted those with the
key transparent) and does not apply to the individual cells located within these blocks.
In fact, in the list of keys provided as argument of \TikzEveryCell, it’s possible to put a key
offset . That key is not provided by TikZ but by 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 argument of \TikzEveryCell.
\renewcommand{\arraystretch}{1.3}
\begin{NiceTabular}{ccc}[corners]
  & \Block{1-2}{columns} \\
  \Block{2-1}{rows}                                                     columns
  & cell 1 1 & cell 1 2 \\                                          cell 1 1       cell 1 2
  & cell 2 1 & cell 2 2                                      rows
                                                                    cell 2 1       cell 2 2
\CodeAfter
  \TikzEveryCell{offset=1pt,draw}
\end{NiceTabular}
The command \TikzEveryCell has two optional keys, available between square brackets.
  • with the key empty , the command only acts on the empty cells (the exact definition of an
    “empty cell” is given in part 17.2, p. 61);
• with key non-empty , the command only acts on the non-empty cells.
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{cccccc}[hvlines]
  P & O & U & R & V & U \\                                    P     O   U      R     V    U
  O &   &   & E & I &   \\                                    O                E      I
  M & O & R & F & A & L \\
                                                              M     O   R      F     A    L
  E & T & A & L &   & E \\
  L & A & S & E & R & S \\                                    E     T   A      L          E
  O &   & E & X & I & T                                       L     A   S      E     R        S
\CodeAfter
  \TikzEveryCell[empty]{fill=gray,draw}                       O         E      X      I   T
\end{NiceTabular}
                                                 44
By default, the caption is composed below the tabular. With the key caption-above , available in
\NiceMatrixOptions, the caption will be composed above the tabular.
The key short-caption corresponds to the optional argument of the clasical command \caption
and the key label corresponds, of course, to the command \label.
See table 1, p. 47, for an example of use the keys caption and label.
These functionnalities are compatible with the extension caption.
                                                  45
   • If you have several successive commands \tabularnote{...} with no space at all between
     them, the labels of the corresponding notes are composed together, separated by commas (this
     is similar to the option multiple of footmisc for the footnotes).
   • If a command \tabularnote{...} is exactly at the end of a cell (with no space at all after)
     and if the alignment mode of the column is c or r, the label of the note is composed in an
     overlapping position (towards the right). This structure may provide a better alignment of the
     cells of a given column.
   • If the key notes/para is used, the notes are composed at the end of the array in a single
     paragraph (as with the key para of threeparttable).
   • There is a key tabularnote which provides a way to insert some text in the zone of the notes
     before the numbered tabular notes.
      An alternative syntax is available with the environment {TabularNote}. That environment
      should be used at the end of the environment {NiceTabular} (but before a potential instruction
      \CodeAfter).
   • If the package booktabs has been loaded (before or after nicematrix), the key notes/bottomrule
     draws a \bottomrule of booktabs after the notes.
   • The command \tabularnote may be used before the environment of nicematrix. Thus, it’s
     possible to use it on the title inserted by \caption in an environment {table} of LaTeX (or
     in a command \captionof of the package caption). It’s also possible, as expected, to use
     the command \tabularnote in the caption provided by the key caption of the environment
     {NiceTabaular}.
      If several commands \tabularnote are used in a tabular with the same argument, only one
      note is inserted at the end of the tabular (but all the labels are composed, of course). It’s
      possible to control that feature with the key notes/detect-duplicates.62
   • It’s possible to create a reference to a tabular note created by \tabularnote (with the usual
     command \label used after the \tabularnote).
   • The command \tabularnote has an optional argument (between square brackets) to change
     the symbol of the reference of the note.
      Example: \tabularnote[$\star$]{A footnote...}
For an illustration of some of those remarks, see table 1, p. 47. This table has been composed with
the following code (the package caption has been loaded in this document).
\begin{table}
\centering
\NiceMatrixOptions{caption-above}
\begin{NiceTabular}{@{}llc@{}
  [
    caption = A tabular whose caption has been specified by the key
      \texttt{caption}\tabularnote[$\star$]{It's possible to put a tabular
      note in the caption.} ,
    label = t:tabularnote ,
    tabularnote = Some text before the notes. ,
    notes/bottomrule
  ]
\toprule
Last name & First name & Length of life \\
\midrule
Churchill & Wiston & 91\\
Nightingale\tabularnote{Considered as the first nurse of history}%
\tabularnote{Nicknamed ``the Lady with the Lamp''.}
62 For technical reasons, the final user is not allowed to put several commands \tabularnote with exactly the same
                                                        46
& Florence\tabularnote{This note is shared by two references.} & 90 \\
Schoelcher & Victor & 89\tabularnote{The label of the note is overlapping.}\\
Touchet & Marie\tabularnote{This note is shared by two references.} & 89 \\
Wallis & John & 87 \\
\bottomrule
\end{NiceTabular}
\end{table}
  • notes/label-in-tabular
  • notes/label-in-list
  • notes/enumitem-keys
  • notes/enumitem-keys-para
  • notes/code-before
For sake of commodity, it is also possible to set these keys in \NiceMatrixOptions via a key notes
which takes in as value a list of pairs key=value where the name of the keys need no longer be prefixed
by notes:
                                                  47
                                 \NiceMatrixOptions
                                   {
                                     notes =
                                      {
                                        bottomrule ,
                                        style = ... ,
                                        label-in-tabular = ... ,
                                        enumitem-keys =
                                         {
                                           labelsep = ... ,
                                           align = ... ,
                                           ...
                                         }
                                      }
                                   }
  • The key notes/para requires the composition of the notes (at the end of the tabular) in a
    single paragraph.
     Initial value: false
     That key is also available within a given environment.
  • The key notes/bottomrule adds a \bottomrule of booktabs after the notes. Of course, that
    rule is drawn only if there is really notes in the tabular. The package booktabs must have been
    loaded (before or after the package nicematrix). If it is not, an error is raised.
     Initial value: false
     That key is also available within a given environment.
  • The key notes/style is a command whose argument is specified by #1 and which gives the
    style of numerotation of the notes. That style will be used by \ref when referencing a tabular
    note marked with a command \label. The labels formatted by that style are used, separated
    by commas, when the user puts several consecutive commands \tabularnote. The marker #1
    is meant to be the name of a LaTeX counter.
     Initial value: \textit{\alph{#1}}
     Another possible value should be a mere \arabic{#1}
The command \nobreak is for the event that the option para is used.
                                                48
  • The notes are composed at the end of the tabular by using internally a style of list of enumitem.
    This style of list is defined as follows (with, of course, keys of enumitem):
       noitemsep , leftmargin = * , align = left , labelsep = 0pt
       The specification align = left in that style requires a composition of the label leftwards in
       the box affected to that label. With that tuning, the notes are composed flush left, which is
       pleasant when composing tabulars in the spirit of booktabs (see for example the table 1, p. 47).
       The key notes/enumitem-keys specifies a list of pairs key=value (following the specifications
       of enumitem) to customize that style of list (it uses internally the command \setlist* of
       enumitem).
  • The key notes/enumitem-keys-para is similar to the previous one but corresponds to the type
    of list used when the option para is in force. Of course, when the option para is used, a list
    of type inline (as called by enumitem) is used and the pairs key=value should correspond to
    such a list of type inline.
       Initially, the style of list is defined by: afterlabel = \nobreak, itemjoin = \quad
  • The key notes/code-before is a token list inserted by nicematrix just before the composition
    of the notes at the end of the tabular.
       Initial value: empty
       For example, if one wishes to compose all the notes in gray and \footnotesize, he should use
       that key:
14 Other features
                                                  49
The key rounded-corners specifies that the tabular should have rounded corners with a radius equal
to the value of that key (the default value is 4 pt63 ). More precisely, that key has two effects that we
describe now.
   • All the commands for coloring the cells, columns and rows (in the \CodeBefore but also directly
     in the array will respect those rounded corners.
   • When the key hvlines is used, the exterior rules will be drawn with rounded corners.64
That key is available in all the environments and commands (e.g. \pAutoNiceMatrix) of nicematrix
and also in the command \NiceMatrixOptions.
\begin{NiceTabular}
  [hvlines,rounded-corners]
  {ccc}
\CodeBefore
                                                                  Last name       First name    Profession
  \rowcolor{red!15}{1}
\Body                                                               Arvy           Jacques      Physicist
Last name & First name & Profession \\                              Jalon         Amandine      Physicist
Arvy & Jacques & Physicist \\
Jalon & Amandine & Physicist
\end{NiceTabular}
On the other hand, the d columns of the package dcolumn are not supported by nicematrix.
                                                      50
14.4        Default column type in {NiceMatrix}
The environments without preamble ({NiceMatrix}, {pNiceMatrix}, {bNiceMatrix}, etc.) and the
commande \pAutoNiceMatrix (and its variants) provide an option columns-type to specify the type
of column which will be used (the initial value is, of course, c).
The keys l and r are shortcuts for columns-type=l and columns-type=r.
$\begin{bNiceMatrix}[r]
\cos x & - \sin x \\
                                                                                    
                                                                  cos x    − sin x
\sin x & \cos x                                                    sin x    cos x
\end{bNiceMatrix}$
The key columns-type is available in \NiceMatrixOptions but with the prefix matrix, which means
that its name is, within \NiceMatrixOptions : matrix/columns-type.
\NiceMatrixOptions%
  {code-for-first-row = \scriptstyle \rotate \text{image of },
image of e1
image of e2
                                                                                                                     image of e3
   code-for-last-col = \scriptstyle }
$A = \begin{pNiceMatrix}[first-row,last-col=4]
e_1 & e_2 & e_3        \\
1    & 2   & 3   & e_1 \\
                                                                                                                          
                                                                                     1                     2             3 e1
4    & 5   & 6   & e_2 \\                                                       A = 4                     5             6  e2
7    & 8   & 9   & e_3                                                               7                     8             9 e3
\end{pNiceMatrix}$
If the command \rotate is used in the “last row” (exterior to the matrix), the corresponding elements
are aligned upwards as shown below.
\NiceMatrixOptions%
  {code-for-last-row = \scriptstyle \rotate ,                                        1
                                                                                         
                                                                                                          2
                                                                                                                       
                                                                                                                      3 e1
   code-for-last-col = \scriptstyle }                                           A = 4                    5           6e2
$A = \begin{pNiceMatrix}[last-row=4,last-col=4]                                      7                    8           9 e3
1    & 2   & 3   & e_1 \\
                                                                                         image of e1
e2
e3
The command \rotate has a key c: \rotate[c] (spaces are deleted after \rotate[c]). When that
key is used, the content is composed in a \vcenter and, therefore, in most cases, we will have a
vertical alignment.
                                                      51
14.6    The option small
With the option small, the environments of the package nicematrix are composed in a way similar to
the environment {smallmatrix} of the package amsmath (and the environments {psmallmatrix},
{bsmallmatrix}, etc. of the package mathtools).
$\begin{bNiceArray}{cccc|c}[small,
                            last-col ,
                            code-for-last-col = \scriptscriptstyle,
                            columns-width = 3mm ]
1 & -2 & 3 & 4 & 5 \\
0 & 3 & 2 & 1 & 2 & L_2 \gets 2 L_1 - L_2 \\
0 & 1 & 1 & 2 & 3 & L_3 \gets L_1 + L_3
\end{bNiceArray}$
                                            h1    −2 3   4    5   i
                                              0   3 2    1    2       L2 ←2L1 −L2
                                              0   1 1    2    3       L3 ←L1 +L3
One should note that the environment {NiceMatrix} with the option small is not composed exactly
as the environment {smallmatrix}. Indeed, all the environments of nicematrix are constructed upon
{array} (of the package array) whereas the environment {smallmatrix} is constructed directly with
an \halign of TeX.
In fact, the option small corresponds to the following tuning:
  • the cells of the array are composed with \scriptstyle;
  • \arraystretch is set to 0.47;
  • \arraycolsep is set to 1.45 pt;
  • the characteristics of the dotted lines are also modified.
When the key small is in force, some functionalities of nicematrix are no longer available: for example,
it’s no longer possible to put vertical delimiters directly in the preamble of an environment with
preamble (cf. section 11, p. 38).
66 There counters are actual LaTeX counters: the underlying TeX counters are \c@iRow and \c@jCol
                                                             52
If LaTeX counters called iRow and jCol are defined in the document by packages other than nicematrix
(or by the final user), they are shadowed in the environments of nicematrix.
The package nicematrix also provides commands in order to compose automatically matrices from a
general pattern. These commands are \AutoNiceMatrix, \pAutoNiceMatrix, \bAutoNiceMatrix ,
\vAutoNiceMatrix , \VAutoNiceMatrix et \BAutoNiceMatrix.
These commands take in two mandatory arguments. The first is the format of the matrix, with the
syntax n-p where n is the number of rows and p the number of columns. The second argument is the
pattern (it’s a list of tokens which are inserted in each cell of the constructed matrix).
$C = \pAutoNiceMatrix{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$
                                                                      
                                                C1,1       C1,2   C1,3
                                           C = C2,1       C2,2   C2,3 
                                                C3,1       C3,2   C3,3
There exists also \AutoNiceArrayWithDelims similar to {NiceArrayWithDelims}.
It’s possible to change the character used to mark the end of rows with the option end-of-row. As
said before, the initial value is a semicolon.
When the option light-syntax is used, it is not possible to put verbatim material (for example with
the command \verb) in the cells of the array.67
The key light-syntax-expanded has the same behaviour as the key light-syntax but the body
of the environment is expanded (in the TeX sens68 ) before being splitted in rows (but after the
extraction of a potential \CodeAfter).
This color also applies to the delimiters drawn by the command \SubMatrix (cf. p. 40) and for the
delimiters directly specified in the preamble of the environments with preamble (cf. p. 38).
67 The reason is that, when the option light-syntax is used, the whole content of the environment is loaded as a TeX
argument to be analyzed. The environment doesn’t behave in that case as a standard environment of LaTeX which
only put TeX commands before and after the content.
  68 More precisely, it’s a expansion of type e of L3.
                                                         53
14.10 The environment {NiceArrayWithDelims}
In fact, the environment {pNiceArray} and its variants are based upon a more general environment,
called {NiceArrayWithDelims} . The first two mandatory arguments of this environment are the left
and right delimiters used in the construction of the matrix.
It’s possible to use {NiceArrayWithDelims} if we want to use atypical or asymetrical delimiters.
$\begin{NiceArrayWithDelims}
   {\downarrow}{\uparrow}{ccc}[margin]                                            
                                                                                   1
                                                                                                 x
                                                                                         2   3
1 & 2 & 3 \\
                                                                                                 
                                                                                                
                                                                                   4    5   6
4 & 5 & 6 \\
                                                                                                 
                                                                                                
                                                                                  y 7    8   9
7 & 8 & 9
                                                                                                 
\end{NiceArrayWithDelims}$
69 We recall that TikZ is a layer over PGF. The extension nicematrix loads PGF but does not load TikZ. We speak of
PGF/TikZ nodes to emphase the fact that the PGF nodes created by nicematrix may be used with PGF but also with
TikZ. The final user will probably prefer to use TikZ rather than PGF.
  70 One should note that, with that command, the cell is considered as non-empty, which has consequencies for the
continuous dotted lines (cf. p. 31) and the computation of the “corners” (cf. p. 14).
  71 The value of the key name is expanded (in the TeX sens).
                                                        54
$\begin{pNiceMatrix}[name=mymatrix]
1 & 2 & 3 \\
4 & 5 & 6 \\
                                                                                
                                                                        1 2    3
7 & 8 & 9                                                              4 5    6
\end{pNiceMatrix}$                                                      7 8    9
\tikz[remember picture,overlay]
     \draw (mymatrix-2-2) circle (2mm) ;
In the \CodeAfter, the things are easier : one must refer to the nodes with the form i-j (we don’t
have to indicate the environment which is of course the current environment).
$\begin{pNiceMatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
                                                                                
                                                                        1 2    3
7 & 8 & 9                                                              4 5    6
\CodeAfter                                                              7 8    9
  \tikz \draw (2-2) circle (2mm) ;
\end{pNiceMatrix}$
The nodes of the last column (except the potential “last column” specified by last-col72 ) may also
be indicated by i-last. Similarly, the nodes of the last row may be indicated by last-j.
In the following example, we have underlined all the nodes of the matrix.
                                                          
                                       a a+b a+b+c
                                     a      a       a+b 
                                       a     a        a
Since those nodes are PGF nodes, one won’t be surprised to learn that they are drawn by using a
specific PGF style. That style is called nicematrix/cell-node and its definition in the source file
nicematrix.sty is as follows:
\pgfset
  {
     nicematrix / cell-node /.style =
       {
         inner sep = 0 pt ,
         minimum width = 0 pt
       }
  }
The final user may modify that style by changing the values of the keys text/rotate, inner xsep,
inner ysep, inner sep, outer xsep, outer ysep, outer sep, minimum width, minimum height
and minimum size.
For an example of utilisation, see part 18.10, p. 76.
                                                     55
15.1.2    The columns V of varwidth
When the extension varwidth is loaded, the columns of the type V defined by varwidth are supported
by nicematrix. It may be interessant to notice that, for a cell of a column of type V, the PGF/TikZ
node created by nicematrix for the content of that cell has a width adjusted to the content of the cell.
This is in contrast to the case of the columns of type p, m or b for which the nodes have always a
width equal to the width of the column. In the following example, the command \lipsum is provided
by the eponymous package.
\begin{NiceTabular}{V{10cm}}
\bfseries \large
Titre \\
\lipsum[1][1-4]
\CodeAfter
  \tikz \draw [rounded corners] (1-1) -| (last-|2) -- (last-|1) |- (1-1) ;
\end{NiceTabular}
                                                    Titre
                   Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
                   elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
                   dictum gravida mauris. Nam arcu libero, nonummy eget, con-
                   sectetuer id, vulputate a, magna.
We have used the nodes corresponding to the position of the potential rules, which are described
below (cf. p. 58).
The names of the “large nodes” are constructed by adding the suffix “-large” to the names of the
“normal nodes”. In the following example, we have underlined the “large nodes”. We consider that
this example is self-explanatory.74
                                                        
                                      a a+b a+b+c
                                     a     a     a+b 
                                      a     a       a
The “large nodes” of the first column and last column may appear too small for some usage. That’s
why it’s possible to use the options left-margin and right-margin to add space on both sides of
73 There is also an option create-extra-nodes which is an alias for the conjonction of create-medium-nodes and
create-large-nodes.
  74 There is no “large nodes” created in the exterior rows and columns (for these rows and columns, cf. p. 29).
                                                      56
the array and also space in the “large nodes” of the first column and last column. In the following
example, we have used the options left-margin and right-margin.75
                                                             
                                        a a+b a+b+c
                                      a     a       a+b 
                                        a    a         a
It’s also possible to add more space on both side of the array with the options extra-left-margin
and extra-right-margin. These margins are not incorporated in the “large nodes”. It’s possible to
fix both values with the option extra-margin and, in the following example, we use extra-margin
with the value 3 pt.                                         
                                         a a+b a+b+c
                                      a      a       a+b     
                                         a    a         a
Be careful : These nodes are reconstructed from the contents of the contents cells of the array.
Usually, they do not correspond to the cells delimited by the rules (if we consider that these rules are
drawn).
The nodes we have described are not available by default in the \CodeBefore (described p. 19).
It’s possible to have these nodes available in the \CodeBefore by using the key create-cell-nodes
of the keyword \CodeBefore (in that case, the nodes are created first before the construction of the
array by using informations written on the aux file and created a second time during the contruction
of the array itself; this mechanism is not activated by default for efficiency reasons).
\begin{NiceArray}{c@{\;}c@{\;}c@{\;}c@{\;}c}[create-medium-nodes]
    u_1 &-& u_0 &=& r     \\
    u_2 &-& u_1 &=& r     \\
    u_3 &-& u_2 &=& r     \\
75 The options left-margin and right-margin take dimensions as values but, if no value is given, the default value
is used, which is \arraycolsep (by default: 5 pt). There is also an option margin to fix both left-margin and
right-margin to the same value.
                                                        57
    u_4 &-& u_3 &=& r     \\
    \phantom{u_5} & & \phantom{u_4}      &\smash{\vdots} &                            \\
    u_n &-& u_{n-1} &=& r \\[3pt]
    \hline
    u_n &-& u_0 &=& nr \\
\CodeAfter
    \tikz[very thick, red, opacity=0.4, name suffix = -medium]
    \draw (1-1.north west) -- (2-3.south east)
    (2-1.north west) -- (3-3.south east)
    (3-1.north west) -- (4-3.south east)
    (4-1.north west) -- (5-3.south east)
    (5-1.north west) -- (6-3.south east) ;
\end{NiceArray}
                                             u1   −       u0    =    r
                                             u2   −       u1    =    r
                                             u3   −       u2    =    r
                                             u4   −       u3    ..
                                                                =    r
                                                                 .
                                             un − un−1          =    r
                                             un − u0 = nr
If we use TikZ (we remind that nicematrix does not load TikZ by default, by only pgf, which is a
sub-layer of TikZ), we can access, in the \CodeAfter but also in the \CodeBefore, to the intersection
of the (potential) horizontal rule i and the (potential) vertical rule j with the syntax (i-|j).
\begin{NiceMatrix}
\CodeBefore
  \tikz \draw [fill=red!15] (7-|4) |- (8-|5) |- (9-|6) |- cycle ;
\Body
1 \\
1 & 1 \\
1 & 2 & 1 \\
1 & 3 & 3 & 1 \\
1 & 4 & 6 & 4 & 1 \\
1 & 5 & 10 & 10 & 5 & 1 \\
1 & 6 & 15 & 20 & 15 & 6 & 1 \\
1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 \\
1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1
\end{NiceMatrix}
                                                          58
                                    1
                                    1   1
                                    1   2   1
                                    1   3   3     1
                                    1   4   6     4 1
                                    1   5   10   10 5      1
                                    1   6   15   20 15     6   1
                                    1   7   21   35 35     21 7 1
                                    1   8   28   56 70     56 28 8       1
The “decimal” nodes (like i.4) may be used, for example to cross a row of a matrix (if TikZ is loaded).
$\begin{pNiceArray}{ccc|c}
2 & 1 & 3 & 0 \\
3 & 3 & 1 & 0 \\
                                                                                             
                                                                                2 1      3   0
3 & 3 & 1 & 0                                                                  3 3      1   0
\CodeAfter                                                                      3 3      1   0
  \tikz \draw [red] (3.4-|1) -- (3.4-|last) ;
\end{pNiceArray}$
The package nicematrix provides two variables which are internal but public76 :
   • \g_nicematrix_code_before_tl ;
   • \g_nicematrix_code_after_tl.
These variables contain the code of what we have called the “code-before” (usually specified at the
beginning of the environment with the syntax using the keywords \CodeBefore and \Body) and the
“code-after” (usually specified at the end of the environment after the keyword \CodeAfter). The
developer can use them to add code from a cell of the array (the affectation must be global, allowing
to exit the cell, which is a TeX group).
One should remark that the use of \g_nicematrix_code_before_tl needs one compilation more
(because the instructions are written on the aux file to be used during the next run).
76 According to the LaTeX3 conventions, each variable with name beginning with \g_nicematrix ou \l_nicematrix
is public and each variable with name beginning with \g__nicematrix or \l__nicematrix is private.
                                                      59
Example : We want to write a command \crossbox to draw a cross in the current cell. This command
will take in an optional argument between square brackets for a list of pairs key-value which will be
given to TikZ before the drawing.
It’s possible to program such command \crossbox as follows, explicitely using the public variable
\g_nicematrix_code_before_tl.
\ExplSyntaxOn
\cs_new_protected:Nn \__pantigny_crossbox:nnn
   {
      \tikz \draw [ #3 ]
             ( #1 -| \int_eval:n { #2 + 1 } ) -- ( \int_eval:n { #1 + 1 } -| #2 )
             ( #1 -| #2 ) -- ( \int_eval:n { #1 + 1 } -| \int_eval:n { #2 + 1 } ) ;
   }
\NewDocumentCommand \crossbox { ! O { } }
  {
    \tl_gput_right:Nx \g_nicematrix_code_before_tl
      {
        \__pantigny_crossbox:nnn
          { \int_use:c { c@iRow } }
          { \int_use:c { c@jCol } }
          { \exp_not:n { #1 } }
      }
    \ignorespaces
  }
\ExplSyntaxOff
We have used the LaTeX counters iRow and jCol provided by nicematrix (cf. p. 52).
17 Technical remarks
First remark: the package underscore must be loaded before nicematrix. If it is loaded after, an error
will be raised.
77 We speak of the lines created by \Ddots and not the lines created by a command \line in the \CodeAfter.
                                                         60
Example with parallelization        (default):
$A = \begin{pNiceMatrix}
                                                                                              
                                                                                     1        1
1      & \Cdots &                    & 1      \\                                              
                                                                             a + b
a+b    & \Ddots &                    & \Vdots \\
                                                                                               
                                                                           A=                 
\Vdots & \Ddots &                    &        \\
                                                                                              
                                                                                              
a+b    & \Cdots & a+b                & 1                                       a+b        a+b 1
\end{pNiceMatrix}$
$A = \begin{pNiceMatrix}                                                                      
                                                                                     1        1
1      & \Cdots &                    & 1      \\
a+b    &        &                    & \Vdots \\
                                                                                              
                                                                             a + b            
\Vdots & \Ddots & \Ddots             &        \\                           A=
                                                                             
                                                                                               
                                                                                               
a+b    & \Cdots & a+b                & 1
                                                                                              
\end{pNiceMatrix}$                                                             a+b        a+b 1
It’s possible to turn off the parallelization with the option parallelize-diags set to false:
                                                                                         
                                                                        1                1
                                                                                         
                                                                     a + b
The same example without parallelization:
                                                                                          
                                                                 A= 
                                                                                          
                                                                                          
                                                                                         
                                                                       a+b       a+b 1
It’s possible to specify the instruction \Ddots which will be drawn first (and which will be used to
draw the other diagonal dotted lines when the parallelization is in force) with the key draw-first:
\Ddots[draw-first].
       \begin{pmatrix}
       a & b \\
       c \\
       \end{pmatrix}
  • For the columns of type p, m, b, V78 and X79 , the cell is empty if (and only if) its content in the
    TeX code is empty (there is only spaces between the ampersands &).
  • For the columns of type c, l, r and w{...}{...}, the cell is empty if (and only if) its TeX
    output has a width equal to zero.
  • A cell containing the command \NotEmpty is not empty (and a PGF/TikZ node is created in
    that cell).
 78 The    columns of type V are provided by varwidth, which must be loaded: cf. p. 28.
 79 See   p. 28
                                                           61
   • A cell with only a command \Hspace (or \Hspace*) is empty. This command \Hspace is a
     command defined by the package nicematrix with the same meaning as \hspace except that
     the cell where it is used is considered as empty. This command can be used to fix the width of
     some columns of the matrix without interfering with nicematrix.
17.4     Incompatibilities
There might be incompatibilities between nicematrix and babel with the language which activate (in
the TeX sens) some characters, in particular the character <.
Par exemple, for Spanish, it’s recommended to deactivate the abreviations at load-time with the
instruction:
\usepackage[spanish,es-noshorthands]{babel}
The extension nicematrix is usually not compatible with the classes and packages that redefine the
environments {tabular} and {array}. In particular, it’s the case of the class socg-lipics-v2021.
However, in that case, it’s possible to load the class with the key notab which requires that the
environment {tabular} is not redefined.
The package nicematrix is not compatible with the class ieeeaccess because that class is not compatible
with PGF/TikZ. However, there is a simple workaround by writing:82
\let\TeXyear\year
\documentclass{IEEEaccess}
\let\year\TeXyear
In order to use nicematrix with the class aastex631 (of the American Astronomical Society), you have
to add the following instructions in the preamble of your document :
\BeforeBegin{NiceTabular}{\let\begin\BeginEnvironment\let\end\EndEnvironment}
\BeforeBegin{NiceArray}{\let\begin\BeginEnvironment}
\BeforeBegin{NiceMatrix}{\let\begin\BeginEnvironment}
The package nicematrix is not fully compatible with the packages and classes of LuaTeX-ja: the
detection of the empty corners (cf. p. 14) may be wrong in some circonstances.
The package nicematrix is not fully compatible with the package arydshln (because this package
redefines many internals of array) and does not support the columns V of boldline (because the letter V
is reserved for the columns V of varwidth). By any means, nicematrix provides, with the key custom-
line (cf. part 5.3.5, p. 16), tools to draw dashed rules and rules of different widths.
The columns d of dcolumn are not supported (but it’s possible to use the colums S of siunitx).
80 In the documentation of amsmath, we can read: The extra space of \arraycolsep that array adds on each side is a
waste so we remove it [in {matrix}] (perhaps we should instead remove it from array in general, but that’s a harder
task).
  81 And not by inserting @{} on both sides of the preamble of the array. As a consequence, the length of the \hline
is not modified and may appear too long, in particular when using square brackets.
  82 See https://tex.stackexchange.com/questions/528975
                                                        62
17.5       Compatibility with the Tagging Project of LaTeX
 New 7.0
Since the version 7.0, the extension nicematrix is compatible with the Tagging Project of LaTeX (whose
aim is to create tagged PDF). At this time, only simple standard tabulars are correctly tagged.
Here is a example of code which will produce a generate tagged PDF.
\DocumentMetadata{
  lang        = en,
  pdfversion = 2.0,
  pdfstandard = ua-2,
  pdfstandard = a-4f,
  testphase   = {phase-III, table, math}
}
\documentclass{article}
\usepackage{lmodern}
\usepackage{nicematrix}
\begin{document}
\begin{center}
\tagpdfsetup{table/header-rows=1}
\begin{NiceTabular}{ccc}[hvlines]
First name & Last name & Age \\
Paul       & Imbert    & $66$ \\
John       & Sarrus    & $23$ \\
Liz        & Taylor    & $100$ \\
George     & Adams     & $34$
\end{NiceTabular}
\end{center}
\end{document}
18 Examples
\usetikzlibrary{patterns}
\ttfamily \small
\begin{NiceTabular}{X[m]X[m]X[m]}[hvlines,cell-space-limits=3pt,rounded-corners]
  \Block[tikz={pattern=grid,pattern color=lightgray}]{}
    {pattern = grid,\\ pattern color = lightgray}
& \Block[tikz={pattern = north west lines,pattern color=blue}]{}
    {pattern = north west lines,\\ pattern color = blue}
& \Block[tikz={outer color = red!50, inner color=white }]{2-1}
    {outer color = red!50,\\ inner color = white} \\
  \Block[tikz={pattern = sixpointed stars, pattern color = blue!15}]{}
    {pattern = sixpointed stars,\\ pattern color = blue!15}
& \Block[tikz={left color = blue!50}]{}
    {left color = blue!50} \\
\end{NiceTabular}
                                                            63
        pattern = grid,                  pattern = north west lines,
   pattern color = lightgray                pattern color = blue                   outer color = red!50,
  pattern = sixpointed stars,                                                       inner color = white
                                             left color = blue!50
    pattern color = blue!15
In the following example, we use the key tikz to hatch a row of the tabular. Remark that you use
the key transparent of the command \Block in order to have the rules drawn in the block.84
\begin{NiceTabular}{ccc}[hvlines]
\CodeBefore
  \columncolor[RGB]{169,208,142}{2}
\Body
one & two & three \\
\Block[transparent, tikz={pattern = north west lines, pattern color = gray}]{1-*}{}
four & five & six \\
seven & eight & nine
\end{NiceTabular}
\tcbox
  [
    left = 0mm ,
    right = 0mm ,
    top = 0mm ,
    bottom = 0mm ,
    boxsep = 0mm ,
    toptitle = 0.5mm ,
    bottomtitle = 0.5mm ,
    title = My table
  ]
  {
    \renewcommand{\arraystretch}{1.2}% <-- the % is mandatory here
    \begin{NiceTabular}{rcl}[hvlines-except-borders,rules/color=blue!50!black]
    \CodeBefore
       \rowcolor{red!15}{1}
    \Body
84 By default, the rules are not drawn in the blocks created by the command \Block (cf. section 5 p. 11): with the
key transparent, they are drawn (the block becomes transparent to the exterior rules).
                                                        64
        One & Two & Three \\
        Men & Mice & Lions \\
        Upper & Middle & Lower
      \end{NiceTabular}
  }
                                                         My table
                                                 One        Two         Three
                                                 Men        Mice        Lions
                                                Upper      Middle       Lower
 85 Of    course, it’s realistic only when there is very few notes in the tabular.
 86 In   fact: the value of its argument.
                                                              65
Vanesse & Stephany & 30 octobre 1994 \\
Dupont & Chantal & 15 janvier 1998 \\
\bottomrule
\end{NiceTabular}
\setlength{\extrarowheight}{1mm}
\[\begin{vNiceArray}{cccc:ccc}[columns-width=6mm]
a_0   &      &&       &b_0    &      &     \\
a_1   &\Ddots&&       &b_1    &\Ddots&     \\
\Vdots&\Ddots&&       &\Vdots &\Ddots&b_0 \\
a_p   &      &&a_0    &       &      &b_1   \\
      &\Ddots&&a_1    &b_q    &      &\Vdots\\
      &      &&\Vdots &       &\Ddots&      \\
      &      &&a_p     &       &      &b_q
\end{vNiceArray}\]
                               a0                     b0
                               a1                     b1
                                                                 b0
                               ap                a0              b1
                                                 a1   bq
ap bq
$\begin{pNiceArray}{*6{c}|c}[nullify-dots,last-col,code-for-last-col=\scriptstyle]
1      & 1 & 1 &\Cdots &   & 1      & 0      & \\
0      & 1 & 0 &\Cdots &   & 0      &        & L_2 \gets L_2-L_1 \\
0      & 0 & 1 &\Ddots &   & \Vdots &        & L_3 \gets L_3-L_1 \\
       &   &   &\Ddots &   &        & \Vdots & \Vdots \\
\Vdots &   &   &\Ddots &   & 0      & \\
0      &   &   &\Cdots & 0 & 1      & 0      & L_n \gets L_n-L_1
\end{pNiceArray}$
                                                 66
                                                           
                                  1   1   1            1   0
                                0    1   0            0    L2 ←L2 −L1
                                                           
                                0    0   1                 L3 ←L3 −L1
                                                           
                                                           
                                                           
                                                      0    
                                  0               0    1   0 Ln ←Ln −L1
\setcounter{MaxMatrixCols}{12}
\newcommand{\blue}{\color{blue}}
\[\begin{pNiceMatrix}[last-row,last-col,nullify-dots,xdots/line-style={dashed,blue}]
1& & & \Vdots & & & & \Vdots \\
& \Ddots[line-style=standard] \\
& & 1 \\
\Cdots & & & \blue 0 & \Cdots & & & \blue 1 & & & \Cdots & \blue \leftarrow i \\
& & & & 1 \\
& & &\Vdots & & \Ddots[line-style=standard] & & \Vdots \\
& & & & & & 1 \\
\Cdots & & & \blue 1 & \Cdots & & \Cdots & \blue 0 & & & \Cdots & \blue \leftarrow j \\
& & & & & & & & 1 \\
& & & & & & & & & \Ddots[line-style=standard] \\
& & & \Vdots & & & & \Vdots & & & 1 \\
& & & \blue \overset{\uparrow}{i} & & & & \blue \overset{\uparrow}{j} \\
\end{pNiceMatrix}\]
                                                                   
                                1
                                                                   
                                                                   
                            
                                     1                             
                                                                    
                                         0                1        ← i
                                                                   
                            
                                             1                     
                                                                    
                                                                   
                                                                   
                            
                                                      1            
                                                                    
                                         1                0        ← j
                                                                   
                            
                                                              1    
                                                                    
                                                                   
                                                                   1
                                          ↑                ↑
                                          i                j
                                                      67
In fact, it’s even possible to draw solid lines with the commands \Cdots, \Vdots, etc.87
\NiceMatrixOptions{xdots={horizontal-labels,line-style = <->}}
$\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
\Hdotsfor{3}^{3} & \Hdotsfor{2}^{2} \\                                                       3           2
If you want the label on the line, you should use the special token “:” instead of “^”:
\NiceMatrixOptions{xdots={horizontal-labels,line-style = <->}}
$\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
\Hdotsfor{3}:{3} & \Hdotsfor{2}:{2} \\
2 & 1 & 1 & 1 & 1 & \Vdotsfor{3}:{3} \\                                                     3           2       
                                                                                         2   1   1   1       1
1 & 1 & 1 & 1 & 1 \\
                                                                                         1   1   1   1       1   3
1 & 1 & 1 & 1 & 1 \\
                                                                                     
                                                                                                                
                                                                                         1   1   1   1       1
\Hline
                                                                                                                
                                                                                                                
                                                                                         1   1   1   1       1
1 & 1 & 1 & 1 & 1 &                                                                                                      lignes
                                                                                                                
                                                                                                                     2
\Vdotsfor{2}:{2 \rlap{ \smash{rows}}} \\                                                 1   1   1   1       1
1 & 1 & 1 & 1 & 1 \\
\end{pNiceArray}$
If one prefers the braces of the library decorations.pathreplacing of TikZ, the best way is to use the
commands \Hbrace and \Vbrace provided by nicematrix (cf. p. 37).88
\NiceMatrixOptions{xdots/horizontal-labels}
$\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]                                       3           2
\Hbrace{3}{3} & \Hbrace{2}{2} \\                                                                                
                                                                                         2   1   1   1       1
2 & 1 & 1 & 1 & 1 & \Vbrace{3}{3} \\
                                                                                         1   1   1   1       1           3
1 & 1 & 1 & 1 & 1 \\
                                                                                                                
                                                                                                                
                                                                                         1   1   1   1       1
1 & 1 & 1 & 1 & 1 \\
                                                                                                                
                                                                                                                
\Hline
                                                                                        1   1   1   1       1   
                                                                                                                         2
1 & 1 & 1 & 1 & 1 & \Vbrace{2}{2} \\                                                     1   1   1   1       1
1 & 1 & 1 & 1 & 1 \\
\end{pNiceArray}$
 87 Inthis document, the TikZ library arrows.meta has been loaded, which impacts the shape of the arrow tips.
 88 Remark  that those commands are available only if TikZ has been loaded with the library decorations.pathreplacing:
\usepackage{TikZ} \usetikzlibrary{decorations.pathreplacing}.
                                                         68
It’s possible to change the TikZ style of those braces by changing the TikZ style nicematrix/brace.
In the following example, we assume that the TikZ extension calligraphy has been loaded:
\usetikzlibrary{calligraphy}
\NiceMatrixOptions{xdots/horizontal-labels}
\tikzset
  {
    nicematrix/brace/.style =
      {
         decoration =
           {
             calligraphic brace ,
             amplitude = 0.4 em ,
             raise = -0.25 em
           } ,
         line width = 0.1 em ,
         decorate ,
      }
  }
$\begin{pNiceArray}{ccc|cc}[first-row,last-col,margin]
\Hbrace{3}{3} & \Hbrace{2}{2} \\                                                3             2
If one prefers the curly braces of the current mathematical font of LaTeX, one should use the com-
mands \SubMatrix, \OverBrace and \UnderBrace in the \CodeAfter.
$\begin{pNiceArray}{ccc|cc}[margin,last-col]
2 & 1 & 1 & 1 & 1 & \Block{3-1}{\quad 3} \\
1 & 1 & 1 & 1 & 1 \\                                                        3             2
1 & 1 & 1 & 1 & 1 \\                                                      z }| {        z }| {
\Hline
                                                                                                 
                                                                          2 1 1         1 1        
1 & 1 & 1 & 1 & 1 & \Block{2-1}{\quad 2} \\                              1 1 1         1 1        3
1 & 1 & 1 & 1 & 1 \\
                                                                                                 
                                                                         1 1 1         1 1       
\CodeAfter
                                                                                                 
                                                                         1 1 1         1 1       
  \OverBrace[shorten,yshift=1.5mm]{1-1}{1-3}{3}                                                      2
                                                                          1 1 1         1 1
  \OverBrace[shorten,yshift=1.5mm]{1-4}{1-5}{2}
  \SubMatrix{.}{1-1}{3-5}{\rbrace}[xshift=3.5mm]
  \SubMatrix{.}{4-1}{5-5}{\rbrace}[xshift=3.5mm]
\end{pNiceArray}$
Or course, the output may seem disappointing. That’s why, for this type of use, we recommend
the use of the commands \Hbrace and \Vbrace (provided by nicematrix), as shown in the previous
examples.
                                                69
\begin{pNiceMatrix}
\Block[borders={bottom,right,tikz=dashed}]{2-2}{}
1 & 2 & 0 & 0 & 0 & 0 \\
4 & 5 & 0 & 0 & 0 & 0 \\
0 & 0 & \Block[borders={bottom,top,right,left,tikz=dashed}]{2-2}{}
        7 & 1 & 0 & 0 \\
0 & 0 & -1 & 2 & 0 & 0 \\
0 & 0 & 0 & 0 & \Block[borders={left,top,tikz=dashed}]{2-2}{}
                  3 & 4 \\
0 & 0 & 0 & 0 & 1 & 4
\end{pNiceMatrix}
                                                              
                                       1   2   0     0   0   0
                                     4    5   0     0   0   0
                                                              
                                     0    0   7     1   0   0
                                                              
                                     0
                                          0   −1    2   0   0
                                     0    0   0     0   3   4
                                       0   0   0     0   1   4
\quad $\begin{pNiceMatrix}
12 -8 7 5      3 {} ;
 3 -18 12 1    4    ;
-3 -46 29 -2 -15    ;
 9 10 -5 4     7
\end{pNiceMatrix}$
\smallskip
\quad $\begin{pNiceMatrix}
12 -8    7 5    3 ;
0   64 -41 1 19 { L_2 \gets L_1-4L_2 } ;
0 -192 123 -3 -57 { L_3 \gets L_1+4L_3 } ;
0 -64   41 -1 -19 { L_4 \gets 3L_1-4L_4 } ;
\end{pNiceMatrix}$
\smallskip
\quad $\begin{pNiceMatrix}
12 -8   7 5 3 ;
0 64 -41 1 19 ;
0   0   0 0 0 { L_3 \gets 3 L_2 + L_3 }
\end{pNiceMatrix}$
\smallskip
                                                70
\quad $\begin{pNiceMatrix}
12 -8   7 5 3 {} ;
0 64 -41 1 19      ;
\end{pNiceMatrix}$
\end{NiceMatrixBlock}
                                       
      12      −8       7      5       3
                                       
  
      3     −18      12      1       4
  
     −3     −46      29     −2     −15
       9      10      −5      4       7
                                       
       12     −8      7       5       3
                                       
  
       0     64    −41       1      19L2 ←L1 −4L2
  
       0   −192    123      −3     −57L3 ←L1 +4L3
        0    −64     41      −1     −19 L4 ←3L1 −4L4
                                       
       12     −8      7        5      3
        0     64    −41        1     19
                                       
  
        0      0      0        0      0 L3 ←3L2 +L3
                                        !
       12     −8      7        5      3
        0     64    −41        1     19
However, one can see that the last matrix is not perfectly aligned with others. That’s why, in LaTeX,
the parenthesis have not exactly the same width (smaller parenthesis are a bit slimer).
In order the solve that problem, it’s possible to require the delimiters to be composed with the
maximal width, thanks to the boolean key delimiters/max-width .
\begin{NiceMatrixBlock}[auto-columns-width]
\NiceMatrixOptions
  {
    delimiters/max-width,
    light-syntax,
    last-col, code-for-last-col = \color{blue}\scriptstyle,
    vlines = 5 ,
    matrix/columns-type = r ,
    no-cell-nodes % only for speedup
  }
\setlength{\extrarowheight}{1mm}
\quad $\begin{pNiceMatrix}
12 -8 7 5      3 {} ;
 3 -18 12 1    4    ;
-3 -46 29 -2 -15    ;
 9 10 -5 4     7
\end{pNiceMatrix}$
...
\end{NiceMatrixBlock}
                                      
      12      −8       7      5       3
                                      
  
      3     −18      12      1       4
                                       
  
     −3     −46      29     −2     −15
                                       
       9      10      −5      4       7
                                      
       12     −8      7       5       3
                                      
  
       0     64    −41       1      19
                                       L2 ←L1 −4L2
  
       0   −192    123      −3     −57
                                       L3 ←L1 +4L3
        0    −64     41      −1     −19 L4 ←3L1 −4L4
                                                 71
                                        
       12     −8       7        5      3
        0     64     −41        1     19
                                        
  
        0      0       0        0      0 L3 ←3L2 +L3
                                         !
       12     −8       7        5      3
        0     64     −41        1     19
If you wish an alignment of the different matrices without the same width for all the columns, you can
construct a unique array and place the parenthesis with commands \SubMatrix in the \CodeAfter.
Of course, that array can’t be broken by a page break.
\setlength{\extrarowheight}{1mm}
\[\begin{NiceMatrix}[r, last-col=6,        code-for-last-col = \scriptstyle \color{blue}]
12 & -8 & 7 & 5 & 3 \\
 3 & -18 & 12 & 1 & 4 \\
-3 & -46 & 29 &-2 &-15 \\
 9 & 10   &-5 &4 & 7 \\[1mm]
12 & -8   & 7 &5 & 3 \\
0 & 64    &-41 & 1 & 19 & L_2 \gets        L_1-4L_2 \\
0 & -192 &123 &-3 &-57 & L_3 \gets         L_1+4L_3 \\
0 & -64 & 41 &-1 &-19 & L_4 \gets          3L_1-4L_4 \\[1mm]
12 & -8   &7   &5 & 3 \\
0 & 64    &-41 &1 &19 \\
0 & 0     &0   &0 & 0 & L_3 \gets          3L_2+L_3 \\[1mm]
12 & -8   &7   &5 & 3 \\
0 & 64    &-41 & 1 & 19 \\
\CodeAfter [sub-matrix/vlines=4]
   \SubMatrix({1-1}{4-5})
   \SubMatrix({5-1}{8-5})
   \SubMatrix({9-1}{11-5})
   \SubMatrix({12-1}{13-5})
\end{NiceMatrix}\]
                                                          
                              12      −8     7  5        3
                             3      −18    12  1        4
                                                          
                                                          
                             −3     −46    29 −2      −15 
                               9      10    −5  4         7
                                                          
                              12       −8   7  5         3
                             0        64 −41  1        19  L2 ←L1 −4L2
                                                          
                                                          
                             0      −192 123 −3       −57  L3 ←L1 +4L3
                               0      −64  41 −1       −19 L4 ←3L1 −4L4
                                                          
                              12      −8   7       5     3
                                      64 −41
                                                          
                             0                    1    19 
                               0       0   0       0      0       L3 ←3L2 +L3
                                                              !
                                12    −8   7       5      3
                                 0    64 −41       1     19
In this tabular, the instructions \SubMatrix are executed after the composition of the tabular and,
thus, the vertical rules are drawn without adding space between the columns.
In fact, it’s possible, with the key vlines-in-sub-matrix , to choice a letter in the preamble of the
array to specify vertical rules which will be drawn in the \SubMatrix only (by adding space between
the columns).
                                                 72
\setlength{\extrarowheight}{1mm}
\[\begin{NiceArray}
   [
     vlines-in-sub-matrix=I,
     last-col,
     code-for-last-col = \scriptstyle \color{blue}
   ]
  {rrrrIr}
12 & -8 & 7 & 5 & 3 \\
 3 & -18 & 12 & 1 & 4 \\
-3 & -46 & 29 &-2 &-15 \\
 9 & 10    &-5 &4 & 7 \\[1mm]
12 & -8    & 7 &5 & 3 \\
0 & 64     &-41 & 1 & 19 & L_2 \gets L_1-4L_2 \\
0 & -192 &123 &-3 &-57 & L_3 \gets L_1+4L_3 \\
0 & -64 & 41 &-1 &-19 & L_4 \gets 3L_1-4L_4 \\[1mm]
12 & -8    &7   &5 & 3 \\
0 & 64     &-41 &1 &19 \\
0 & 0      &0   &0 & 0 & L_3 \gets 3L_2+L_3 \\[1mm]
12 & -8    &7   &5 & 3 \\
0 & 64     &-41 & 1 & 19 \\
\CodeAfter
   \SubMatrix({1-1}{4-5})
   \SubMatrix({5-1}{8-5})
   \SubMatrix({9-1}{11-5})
   \SubMatrix({12-1}{13-5})
\end{NiceArray}\]
                                                                  
                                  12       −8       7  5         3
                                 3       −18      12  1         4
                                                                  
                                                                  
                                 −3      −46      29 −2       −15 
                                   9       10      −5  4         7
                                                                  
                                  12       −8   7  5             3
                                 0        64 −41  1            19  L2 ←L1 −4L2
                                                                  
                                                                  
                                 0      −192 123 −3           −57  L3 ←L1 +4L3
                                   0      −64  41 −1           −19       L4 ←3L1 −4L4
                                                                    
                                  12       −8   7          5      3
                                           64 −41
                                                                   
                                 0                        1     19 
                                   0        0   0          0      0 L3 ←3L2 +L3
                                                                    !
                                    12     −8   7          5      3
                                     0     64 −41          1     19
In order to highlight a cell of a matrix, it’s possible to “draw” that cell with the key draw of the
command \Block (this is one of the uses of a mono-cell block89 ).
89 We recall that, if the first mandatory argument of the command \Block is left empty, that means that the block is
a mono-cell block
                                                         73
$\begin{pNiceArray}{>{\strut}cccc}[margin,rules/color=blue,no-cell-nodes]
\Block[draw]{}{a_{11}} & a_{12} & a_{13} & a_{14} \\
a_{21} & \Block[draw]{}{a_{22}} & a_{23} & a_{24} \\
a_{31} & a_{32} & \Block[draw]{}{a_{33}} & a_{34} \\
a_{41} & a_{42} & a_{43} & \Block[draw]{}{a_{44}} \\
\end{pNiceArray}$
                                                                          
                                             a11      a12    a13       a14
                                            a21
                                                     a22    a23       a24 
                                                                           
                                            a31      a32    a33       a34 
                                             a41      a42    a43       a44
We should remark that the rules we have drawn are drawn after the construction of the array and thus,
they don’t spread the cells of the array. We recall that, on the other side, the commands \hline and
\Hline, the specifier “|” and the options hlines, vlines, hvlines and hvlines-except-borders
spread the cells.90
It’s possible to color a row with \rowcolor in the code-before (or with \rowcolor in the first cell
of the row.
\begin{pNiceArray}{>{\strut}cccc}% <-- % mandatory
   [margin, extra-margin=2pt,no-cell-nodes]
  \rowcolor{red!15}A_{11} & A_{12} & A_{13} & A_{14} \\
  A_{21} & \rowcolor{red!15}A_{22} & A_{23} & A_{24} \\
  A_{31} & A_{32} & \rowcolor{red!15}A_{33} & A_{34} \\
  A_{41} & A_{42} & A_{43} & \rowcolor{red!15}A_{44}
\end{pNiceArray}
                                                                          
                                            A11       A12        A13   A14
                                           A21       A22        A23   A24 
                                                                          
                                           A31       A32        A33   A34 
                                            A41       A42        A43   A44
However, it’s not possible to do a fine tuning. That’s why we describe now a method to highlight a
row of the matrix.
That example and the following ones require TikZ (by default, nicematrix only loads pgf, which is
a sub-layer of TikZ) and the TikZ library fit. The following instructions in the preamble of your
document do the job:
\usepackage{tikz}
\usetikzlibrary{fit}
We create a rectangular TikZ node which encompasses the nodes of the second row by using the tools
of the TikZ library fit. Those nodes are not available by default in the \CodeBefore (for efficiency).
We have to require their creation with the key create-cell-nodes of the keyword \CodeBefore.
\tikzset{highlight/.style={rectangle,
                           fill=red!15,
                           rounded corners = 0.5 mm,
                           inner sep=1pt,
                           fit=#1}}
$\begin{bNiceMatrix}
\CodeBefore [create-cell-nodes]
  \tikz \node [highlight = (2-1) (2-last)] {} ;
                                                            74
\Body
0 & \Cdots & 0 \\
1 & \Cdots & 1 \\
0 & \Cdots & 0 \\
\end{bNiceMatrix}$
                                                    
                                           0        0
                                          1        1
                                           0        0
We consider now the following matrix. If we want to highlight each row of this matrix, we can use
the previous technique three times.
\begin{pNiceArray}{ccc}[last-col, margin = 2pt]
\CodeBefore [create-cell-nodes]
  \begin{tikzpicture}
  \node [highlight = (1-1) (1-last)] {} ;
  \node [highlight = (2-1) (2-last)] {} ;
  \node [highlight = (3-1) (3-last)] {} ;
  \end{tikzpicture}
\Body
a & a + b & a + b + c & L_1 \\
a & a       & a + b       & L_2 \\
a & a       & a           & L_3
\end{pNiceArray}
                                                       
                                    a    a + b a + b + c L1
                                   a      a     a + b L2
                                    a      a       a      L3
The result may seem disappointing. We can improve it by using the “medium nodes” instead of the
“normal nodes”.
\[\begin{pNiceArray}{ccc}[last-col, margin = 2pt, create-medium-nodes]
\CodeBefore [create-cell-nodes]
  \begin{tikzpicture} [name suffix = -medium]
  \node [highlight = (1-1) (1-last)] {} ;
  \node [highlight = (2-1) (2-last)] {} ;
  \node [highlight = (3-1) (3-last)] {} ;
  \end{tikzpicture}
\Body
a & a + b & a + b + c & L_1 \\
a & a      & a + b       & L_2 \\
a & a      & a           & L_3
\end{pNiceArray}\]
                                                       
                                    a    a + b a + b + c L1
                                   a      a     a + b L2
                                    a      a       a      L3
                                               75
                                                                 Cj
                                                                                  
                                                           b11   b1j         b1n
                                                                                  
                                                                                  
                                                       
                                                                bkj               
                                                                                   
                                                                                  
                                                           bn1   bnj         bnn
                                                                                
                                  a11           a1n
                                                                                
                                                                                
                               ai1
                           Li          aik     ain             cij
                                                                                  
                                                                                 
                                                                                
                                an1             ann
\tikzset{highlight/.style={rectangle,
                           fill=red!15,
                           rounded corners = 0.5 mm,
                           inner sep=1pt,
                           fit=~#1}}
\[\begin{NiceArray}{*{6}{c}@{\hspace{6mm}}*{5}{c}}[nullify-dots]
\CodeBefore [create-cell-nodes]
  \SubMatrix({2-7}{6-last})
  \SubMatrix({7-2}{last-6})
  \SubMatrix({7-7}{last-last})
  \begin{tikzpicture}
    \node [highlight = (9-2) (9-6)] { } ;
    \node [highlight = (2-9) (6-9)] { } ;
  \end{tikzpicture}
\Body
    &        &        &         &       &        &        &            &   \color{blue}\scriptstyle   C_j \\
    &        &        &         &       &        & b_{11} & \Cdots     &   b_{1j} & \Cdots & b_{1n}   \\
    &        &        &         &       &        & \Vdots &            &   \Vdots &        & \Vdots   \\
    &        &        &         &       &        &        &            &   b_{kj} \\
    &        &        &         &       &        &        &            &   \Vdots \\
    &        &        &         &       &        & b_{n1} & \Cdots     &   b_{nj} & \Cdots & b_{nn}   \\[3mm]
    & a_{11} & \Cdots &         &       & a_{1n} \\
    & \Vdots &        &         &       & \Vdots &        &            & \Vdots \\
\color{blue}\scriptstyle L_i
    & a_{i1} & \Cdots & a_{ik} & \Cdots & a_{in} & \Cdots &            & c_{ij} \\
    & \Vdots &        &         &       & \Vdots \\
    & a_{n1} & \Cdots &         &       & a_{nn} \\
\CodeAfter
\tikz \draw [gray,shorten > = 1mm, shorten < = 1mm] (9-4.north) to     [bend left] (4-9.west) ;
\end{NiceArray}\]
\setlength{\tabcolsep}{0pt}
                                                  76
{\begin{NiceTabular} [ hvlines, corners=SE, baseline = line-9 ] { cccccccc }
 \CodeBefore
   \chessboardcolors{red!15}{blue!15}
 \Body
   1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\
   1 & 2 & 3 & 4 & 5 & 6 & 7 \\
   1 & 3 & 6 & 10 & 15 & 21 \\
   1 & 4 & 10 & 20 & 35 \\
   1 & 5 & 15 & 35 \\
   1 & 6 & 21 \\
   1 & 7 \\
   1
 \end{NiceTabular}}
                                               1
                                          1         1
                                     1         2         1
                                1         3         3         1
                            1        4         6         4         1
                        1       5         10        10        5        1
                    1       6        15        20        15        6       1
                1       7       21        35        35        21       7       1
                                               77
19 History
The development of the package nicematrix is done in the following GitHub depot:
https://github.com/fpantigny/nicematrix
The successive versions of the file nicematrix.sty provided by TeXLive are also available on the
svn server of TeXLive:
https:www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty
                                                 78
Changes between version 6.21 and 6.22
Key opacity for the command \Block.
It’s now possible to put a label on a “continuous dotted line” with the specifier “:”.
                                                  79
Changes between version 6.12 and 6.13
New environment {TabularNote} in {NiceTabular} with the same semantic as the key tabularnote
(for legibility).
The command \Hline nows accepts options (between square brackets).
                                                80
Changes between versions 6.2 and 6.3
Keys nb-rows, rowcolor and bold for the command \RowStyle
Key name for the command \Block.
Support for the columns V of varwidth.
                                                 81
Index
                                            82
enumitem (package required to use                     left-xshift (key of \SubMatrix), 41
          \tabularnote), 45, 65                       letter (key of “custom-line”), 16
enumitem-keys (subkey of “notes”), 47, 65             light-syntax, 53
enumitem-keys-para (subkey of “notes”), 47            light-syntax-expanded, 53
exterior-arraycolsep, 62                              \line (command of \CodeAfter), 39
extra-height (key of \SubMatrix), 41                  line-style (key for dotted rules), 35
extra-left-margin, 56                                 line-style (key for the dotted rules), 67
extra-right-margin, 56                                line-width (key of \Block), 5
                                                      Lines in the tabulars, see Rules
                F
fill                                                                  M
      key of \Block, 5                                mathdots (package), 31
      key of \RowStyle, 26                            max-width (subkey of “delimiters”), 71
first-col, 29                                         multiplicity (key of “custom-line”), 16
first-row, 29, 51
footnote (package), 45                                                 N
footnote (key), 45                                    name
footnotehyper (package), 45                                key for an environment, 54
footnotehyper (key), 45                                    key of \Block, 5
                                                           key of \SubMatrix, 59
                H                                     nb-rows (key of \RowStyle), 26
\Hbrace, 37                                           {NiceArrayWithDelims}, 54
\Hdotsfor, 33                                         {NiceMatrixBlock}, 27, 70
\hdottedline, 18                                      \NiceMatrixOptions, 1
highlight (TikZ style defined in                      {NiceTabularX}, 28
          an example), 74                             no-cell-nodes, 54
\Hline, 13                                            nocolor, 26
hlines, see Rules                                     Nodes of PGF/TikZ, 54–59
     key for an environment, 13                       non empty (key of \TikzEveryCell), 44
     key of \Block, 5                                 Notes in the tabulars, 45–49, 65
     key of \SubMatrix, 41                            \NotEmpty, 61
horizontal-label(s) (key for dotted rules), 35        notes (key to customize the notes of a
\Hspace, 32                                                     tabular), 65
hvlines, see Rules                                    nullify-dots, 32
     key for an environment, 14
     key of \Block, 5                                                O
     key of \SubMatrix, 41                            \OnlyMainNiceMatrix, 54
hvlines-except-borders, 14, 65                        opacity
                                                          key of \Block, 5
                 I                                        key of \RowStyle, 26
\Iddots, 31, 60                                           key of commands such as
Incompatibilities, 62                                         \rowcolor, etc., 20
inter (key for dotted rules), 35                      \OverBrace (command of \CodeAfter
iRow (LaTeX counter), 52                                      and \CodeBefore), 43
              J                                                        P
jCol (LaTeX counter), 52                              para (subkey of “notes”), 47
                                                      parallelize-diags, 60
                  L                                   \pAutoNiceMatrix, 53
label (key of {NiceTabular}), 44                      pgf-node-code, 55, 76
label-in-list (subkey of “notes”), 47
label-in-tabular (subkey of “notes”), 47                              R
last-col, 29, 51, 66                                  radius (key for dotted rules), 35
last-row, 29, 51                                      \rectanglecolor (in \CodeBefore), 19
\Ldots, 31                                            renew-dots, 34
\left : used by nicematrix for                        renew-matrix, 34
           delimiters in the preambles, 38            \resetcolorseries (command of xcolor), 22
left-margin, 56                                       respect-arraystretch (key of \Block), 5
left-shorten (key of \OverBrace and                   respect-blocks (key of \rowcolors du
           \UnderBrace), 43                                    \CodeBefore), 21
                                                 83
restart (key of \rowcolors of \CodeBefore), 21                        U
\right : used by nicematrix for                         \UnderBrace (command of \CodeAfter
          delimiters in the preambles, 38                       and \CodeBefore), 43
right-margin, 56
right-shorten (key of \OverBrace and                                    V
          \UnderBrace), 43                              V (the columns V of varwidth), 28, 56
right-xshift (key of \SubMatrix), 41                    v-center (key of \Block), 9
\rotate, 24, 26, 51                                     varwidth (package), 28, 56
rounded-corners                                         \VAutoNiceMatrix, 53
     key of \Block, 5                                   \vAutoNiceMatrix, 53
     key of \RowStyle, 26                               \Vbrace, 37
     key of {NiceTabular}, 49                           \Vdots, 31
\rowcolor                                               \Vdotsfor, 33
     command in tabular, 24, 74                         vlines, see Rules
     command of \CodeBefore, 19, 65                          key for an environment, 13
rowcolor (key of \RowStyle), 26                              key of \Block, 5
\rowcolors (command of \CodeBefore), 19                      key of \SubMatrix, 41
\rowlistcolors (command of \CodeBefore), 19             vlines-in-sub-matrix, 72
\RowStyle, 26
Rules in the tabulars, 11–19                                           W
rules (key for an environment), 12, 65                  width
                                                            key of {NiceTabular}, 28
                S                                           subkey of “rules”, 12
S (the columns S of siunitx), 24, 50                    Width of the columns, 27–29
sep-color (key of “custom-line”), 16
short-caption, 44                                                       X
shorten (key for dotted rules), 35                      X (the columns X), 28
shorten-end (key for dotted rules), 35                  xdots (and its subkeys), 31
shorten-start (key for dotted rules), 35                xshift (key of \SubMatrix), 41
\ShowCellNames (command of \CodeAfter
                                                                        Y
          and \CodeBefore), 50
                                                        yshift (key of \OverBrace and \UnderBrace), 43
siunitx (package), 50
slim (key of \SubMatrix), 41
small (key for an environment), 52
{smallmatrix} (environment of amsmath), 52
standard-cline, 12
style (subkey of “notes”), 47, 65
sub-matrix (key of \CodeAfter, with subkeys), 39
\SubMatrix (command of \CodeAfter
          and \CodeBefore), 40, 59, 72, 75
                 T
\tabularnote, 45, 65
{TabularNote}, 46
tabularnote (key of {NiceTabular}), 46
tabularx (package), 28
Tagging Project, 63
tcolorbox (package), 64
threeparttable (package), 49
tikz-braces (key at load-tome of nicematrix), 37
TikZ (utilisation with nicematrix), 54
\TikzEveryCell (command of \CodeAfter
          and \CodeBefore), 44
tikz
     key of \Block, 5, 63
     key of “borders” de \Block, 5, 69
     key of “custom-line”, 17
total-width (key of “custom-line”), 17
transparent (key of \Block), 5, 64
                                                   84
Contents
1 The environments of this package                                                                                                                     2
4 The blocks                                                                                                                                           4
  4.1  General case . . . . . . . . . . . .   . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    4
  4.2  The mono-column blocks . . . . .       . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    6
  4.3  The mono-row blocks . . . . . . .      . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    7
  4.4  The mono-cell blocks . . . . . . .     . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    7
  4.5  Horizontal position of the content     of the block    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    7
  4.6  Vertical position of the content of    the block .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    9
  4.7  \\ and & in the blocks . . . . . .     . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   10
5 The rules                                                                                                                                           11
  5.1   Some differences with the classical environments              .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   11
      5.1.1 The vertical rules . . . . . . . . . . . . . . .          .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   11
      5.1.2 The command \cline . . . . . . . . . . . . .              .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   12
  5.2   The thickness and the color of the rules . . . . .            .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   12
  5.3   The tools of nicematrix for the rules . . . . . . .           .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   13
      5.3.1 The keys hlines and vlines . . . . . . . . . .            .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   13
      5.3.2 The keys hvlines and hvlines-except-borders               .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   14
      5.3.3 The (empty) corners . . . . . . . . . . . . .             .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   14
      5.3.4 The command \diagbox . . . . . . . . . . .                .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   15
      5.3.5 Commands for customized rules . . . . . . .               .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   16
12 The \CodeAfter                                                                                                                                     39
   12.1 The command \line in the \CodeAfter . . . . . . . . . . . . . . . . .                                     .   .   .   .   .   .   .   .   .   39
   12.2 The command \SubMatrix in the \CodeAfter (and the \CodeBefore)                                            .   .   .   .   .   .   .   .   .   40
   12.3 The commands \OverBrace and \UnderBrace in the \CodeAfter . .                                             .   .   .   .   .   .   .   .   .   43
   12.4 The command \TikzEveryCell in the \CodeAfter . . . . . . . . . . .                                        .   .   .   .   .   .   .   .   .   44
                                                   85
13 Captions and notes in the tabulars                                                                                                                   44
   13.1 Caption of a tabular . . . . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   44
   13.2 The footnotes . . . . . . . . . . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   45
   13.3 The notes of tabular . . . . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   45
   13.4 Customisation of the tabular notes . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   47
   13.5 Use of {NiceTabular} with threeparttable        .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   49
14 Other features                                                                                                                                       49
   14.1 The key rounded-corners . . . . . . . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   49
   14.2 Command \ShowCellNames . . . . . . . .          .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   50
   14.3 Use of the column type S of siunitx . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   50
   14.4 Default column type in {NiceMatrix} . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   51
   14.5 The command \rotate . . . . . . . . . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   51
   14.6 The option small . . . . . . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   52
   14.7 The counters iRow and jCol . . . . . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   52
   14.8 The key light-syntax . . . . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   53
   14.9 Color of the delimiters . . . . . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   53
   14.10 The environment {NiceArrayWithDelims}          .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   54
   14.11 The command \OnlyMainNiceMatrix . . .          .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   54
17 Technical remarks                                                                                                                                    60
   17.1 Diagonal lines . . . . . . . . . . . . . . . . . . . .          .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   60
   17.2 The empty cells . . . . . . . . . . . . . . . . . . .           .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   61
   17.3 The option exterior-arraycolsep . . . . . . . . . .             .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   62
   17.4 Incompatibilities . . . . . . . . . . . . . . . . . .           .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   62
   17.5 Compatibility with the Tagging Project of LaTeX                 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   63
18 Examples                                                                                                                                             63
   18.1 Utilisation of the key ’tikz’ of the command \Block                 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   63
   18.2 Use with tcolorbox . . . . . . . . . . . . . . . . . .              .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   64
   18.3 Notes in the tabulars . . . . . . . . . . . . . . . . .             .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   65
   18.4 Dotted lines . . . . . . . . . . . . . . . . . . . . . .            .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   66
   18.5 Dotted lines which are no longer dotted . . . . . .                 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   67
   18.6 Dashed rules . . . . . . . . . . . . . . . . . . . . . .            .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   69
   18.7 Stacks of matrices . . . . . . . . . . . . . . . . . . .            .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   70
   18.8 How to highlight cells of a matrix . . . . . . . . . .              .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   73
   18.9 Utilisation of \SubMatrix in the \CodeBefore . . .                  .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   75
   18.10 A triangular tabular . . . . . . . . . . . . . . . . .             .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   76
19 History 78
Index 82
86