From ae777e8c9cd9b932a2ebcad4bc6af2c185ac09e5 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 27 May 2020 21:45:50 +0000 Subject: nicematrix (27may20) git-svn-id: svn://tug.org/texlive/trunk@55302 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/nicematrix/README.md | 3 +- .../doc/latex/nicematrix/nicematrix-french.pdf | Bin 349092 -> 355393 bytes .../doc/latex/nicematrix/nicematrix-french.tex | 3074 ++++++++------ .../texmf-dist/doc/latex/nicematrix/nicematrix.pdf | Bin 845357 -> 875835 bytes .../source/latex/nicematrix/nicematrix.dtx | 4469 +++++++++++--------- .../texmf-dist/tex/latex/nicematrix/nicematrix.sty | 721 ++-- 6 files changed, 4636 insertions(+), 3631 deletions(-) diff --git a/Master/texmf-dist/doc/latex/nicematrix/README.md b/Master/texmf-dist/doc/latex/nicematrix/README.md index 62c2d060890..f3183a5cfc4 100644 --- a/Master/texmf-dist/doc/latex/nicematrix/README.md +++ b/Master/texmf-dist/doc/latex/nicematrix/README.md @@ -26,4 +26,5 @@ For a manual installation: The file `nicematrix.sty` will be generated. -The file `nicematrix.sty` is the only file necessary to use the extension `nicematrix`. +The file `nicematrix.sty` is the only file necessary to use the extension `nicematrix`. +You have to put it in the same directory as your document or (best) in a `texmf` tree. diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf index 5e5910a1ed6..6acb7b9f282 100644 Binary files a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf and b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.pdf differ diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex index 7adcadf7389..d79a0f3727f 100644 --- a/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex +++ b/Master/texmf-dist/doc/latex/nicematrix/nicematrix-french.tex @@ -7,22 +7,14 @@ \usepackage{geometry} \geometry{left=2.8cm,right=2.8cm,top=2.5cm,bottom=2.5cm,papersize={21cm,29.7cm}} -\usepackage{amsmath} - -\usepackage{array} \usepackage{nicematrix} -% \usepackage{colortbl} \usepackage{tikz} \usetikzlibrary{fit} \usepackage{enumitem} - \usepackage{siunitx} - - -% \usepackage{arydshln} \usepackage{verbatim} % We use \MakeShortVerb of shortvrb and not \DefineShortVerb of fancyvrb @@ -45,9 +37,7 @@ \def\emphase{\bgroup\color{RoyalPurple}\let\next=} \usepackage{footnote} - \usepackage{booktabs} - \usepackage{varwidth} \usepackage[hyperfootnotes = false]{hyperref} @@ -83,38 +73,16 @@ \maketitle + \begin{abstract} L'extension LaTeX \pkg{nicematrix} fournit de nouveaux environnements similaires aux environnements classiques -|{tabular}|, |{array}| et |{matrix}| mais avec des fonctionnalités supplémentaires. Parmi ces fonctionnalités -figurent la possibilité de fixer la largeur des colonnes et de tracer des traits en pointillés continus entre les -cases du tableau. +|{tabular}|, |{array}| et |{matrix}| de \pkg{array} et \pkg{amsmath} mais avec des fonctionnalités plus étendues. \end{abstract} -\vspace{1cm} -\section{Présentation} - -Cette extension peut être utilisée avec |xelatex|, |lualatex| et |pdflatex| mais aussi avec le cheminement -classique |latex|-|dvips|-|ps2pdf| (ou Adobe Distiller). Deux ou trois compilations successives peuvent être -nécessaires. Cette extension nécessite et charge les extensions \pkg{expl3}, \pkg{l3keys2e}, \pkg{xparse}, -\pkg{array}, \pkg{amsmath} et \pkg{pgfcore} ainsi que le module \pkg{shapes} de \textsc{pgf} (l'extension -\pkg{tikz} n'est \emph{pas} chargée). L'utilisateur final n'a qu'à charger l'extension \pkg{nicematrix} avec -l'instruction habituelle : |\usepackage{nicematrix}|. - +\vspace{1cm} -\medskip -\begin{savenotes} -\begin{minipage}{0.6\linewidth} -Cette extension fournit quelques outils supplémentaires pour dessiner des matrices (au sens mathématique). Les -principales caractéristiques sont les suivantes : -\begin{itemize}\setlength{\itemsep}{0pt} -\item des lignes en pointillés continues ; -\item des rangées et colonnes extérieures pour les labels ; -\item un contrôle sur la largeur des colonnes. -\end{itemize} -\end{minipage} -\end{savenotes} -\hspace{1.4cm} +\hspace{1cm} $\begin{bNiceArray}{CCCC}[first-row,first-col, code-for-first-col=\color{blue}\scriptstyle, code-for-first-row=\color{blue}\scriptstyle, @@ -125,61 +93,58 @@ L_2 & a_{21} & a_{22} & \Cdots & a_{2n} \\ \Vdots & \Vdots & \Vdots & \Ddots & \Vdots \\ L_n & a_{n1} & a_{n2} & \Cdots & a_{nn} \end{bNiceArray}$ +\hspace{2cm} +\begin{NiceTabular}[c]{LSSSS}% +[code-before = \rowcolor{red!15}{1-2} \rowcolors{3}{blue!15}{}] +\toprule +\Block{2-1}{Produit} & \multicolumn{3}{C}{dimensions (cm)} & \Block{2-1}{\rotate Prix} \\ +\cmidrule(rl){2-4} + & L & l & h \\ +\midrule +petit & 3 & 5.5 & 1 & 30 \\ +standard & 5.5 & 8 & 1.5 & 50.5 \\ +premium & 8.5 & 10.5 & 2 & 80 \\ +extra & 8.5 & 10 & 1.5 & 85.5 \\ +spécial & 12 & 12 & 0.5 & 70 \\ +\bottomrule +\end{NiceTabular} +\vspace{1cm} -\medskip -Une commande|\NiceMatrixOptions| est fournie pour régler les options (la portée des options fixées par cette -commande est le groupe TeX courant). +L'extension \pkg{nicematrix} est entièrement contenue dans le fichier |nicematrix.sty|. Ce fichier peut être placé +dans le répertoire courant ou dans une arborescence |texmf|. Le mieux reste néanmoins d'installer \pkg{nicematrix} +avec une distribution TeX comme MiKTeX ou TeXlive. \bigskip -\textbf{Un exemple d'utilisation pour les lignes en pointillés continues} - -\medskip -\begin{minipage}{10cm} -Considérons par exemple le code suivant qui utilise un environnement |{pmatrix}| de l'extension \pkg{amsmath}. - -\smallskip -\begin{BVerbatim} -$A = \begin{pmatrix} -1 & \cdots & \cdots & 1 \\ -0 & \ddots & & \vdots \\ -\vdots & \ddots & \ddots & \vdots \\ -0 & \cdots & 0 & 1 -\end{pmatrix}$ -\end{BVerbatim} - -\smallskip -Ce code compose la matrice $A$ représentée à droite. -\end{minipage}\hspace{1cm} -$A = \begin{pmatrix} -1 &\cdots &\cdots &1 \\ -0 &\ddots & &\vdots \\ -\vdots &\ddots &\ddots &\vdots \\ -0 &\cdots &0 &1 -\end{pmatrix}$ +Cette extension peut être utilisée avec |xelatex|, |lualatex| et |pdflatex| mais aussi avec le cheminement +classique |latex|-|dvips|-|ps2pdf| (ou Adobe Distiller). +\bigskip +Cette extension nécessite et charge les extensions \pkg{l3keys2e}, \pkg{xparse}, \pkg{array}, \pkg{amsmath} et +\pkg{pgfcore} ainsi que le module \pkg{shapes} de \textsc{pgf} (l'extension \pkg{tikz}, qui est une surcouche de +\textsc{pgf} n'est \emph{pas} chargée). L'utilisateur final n'a qu'à charger l'extension \pkg{nicematrix} avec +l'instruction habituelle : |\usepackage{nicematrix}|. +\bigskip +L'idée de \pkg{nicematrix} est de créer des nœuds \textsc{pgf} derrière les cases et les positions des filets des +tableaux créés par \pkg{array} et de les utiliser pour développer de nouvelles fonctionnalités. Comme toujours avec +\textsc{pgf}, les coordonnées de ces nœuds sont écrites dans le fichier |.aux| pour être utilisées à la +compilation suivante. C'est pourquoi l'utilisation de \pkg{nicematrix} nécessite \textbf{plusieurs compilations + successives}. \bigskip -\begin{scope} -\NiceMatrixOptions{transparent} -\begin{minipage}{10cm} -Maintenant, si nous utilisons l'extension \pkg{nicematrix} avec l'option |transparent|, le même code va donner le -résultat ci-contre à droite. -\end{minipage}\hspace{1cm} -$A = \begin{pmatrix} -1 & \cdots & \cdots & 1 \\ -0 & \ddots & & \vdots \\ -\vdots & \ddots & \ddots & \vdots \\ -0 & \cdots & 0 & 1 -\end{pmatrix}$ -\end{scope} +La plupart des fonctionnalités de \pkg{nicematrix} sont accessibles sans avoir à utiliser explicitement +\textsc{pgf} ou Tikz (ce dernier n'est d'ailleurs pas chargé par défaut). +\bigskip +Une commande|\NiceMatrixOptions| est fournie pour régler les options (la portée des options fixées par cette +commande est le groupe TeX courant : elles sont semi-globales). +\newpage \section{Les environnements de cette extension} @@ -189,880 +154,913 @@ L'extension \pkg{nicematrix} définit les nouveaux environnements suivants : \begin{ttfamily} \setlength{\tabcolsep}{3mm} \begin{tabular}{llll} -\{NiceMatrix\} & \{NiceArray\} & \{NiceTabular\} \\ -\{pNiceMatrix\} & \{pNiceArray\} \\ -\{bNiceMatrix\} & \{bNiceArray\} \\ -\{BNiceMatrix\} & \{BNiceArray\} \\ -\{vNiceMatrix\} & \{vNiceArray\} \\ -\{VNiceMatrix\} & \{VNiceArray\} \\ - & \{NiceArrayWithDelims\} +\{NiceTabular\} & \{NiceArray\} & \{NiceMatrix\} \\ + & \{pNiceArray\} & \{pNiceMatrix\} \\ + & \{bNiceArray\} & \{bNiceMatrix\} \\ + & \{BNiceArray\} & \{BNiceMatrix\} \\ + & \{vNiceArray\} & \{vNiceMatrix\} \\ + & \{VNiceArray\} & \{VNiceMatrix\} \end{tabular} \end{ttfamily} -\medskip -Par défaut, les environnements |{NiceMatrix}|, |{pNiceMatrix}|, |{bNiceMatrix}|, |{BNiceMatrix}|, |{vNiceMatrix}| -et |{VNiceMatrix}| se comportent quasiment comme les environnements correspondants de \pkg{amsmath} : |{matrix}|, -|{pmatrix}|, |{bmatrix}|, |{Bmatrix}|, |{vmatrix}| et |{Vmatrix}|. - - \medskip Les environnements |{NiceArray}| et |{NiceTabular}| sont similaires aux environnements |{array}| et |{tabular}| de -l'extension |{array}|. Néanmoins, pour des raisons techniques, dans le préambule de ces environnements, -l'utilisateur doit utiliser les lettres |L|, |C| et~|R| au lieu de |l|, |c| et |r|. Il est possible d'utiliser les -constructions |p{...}|, |m{...}|, |b{...}|, |w{...}{...}|, |W{...}{...}|, \verb+|+, |>{...}|, |<{...}|, |@{...}|, -|!{...}| et |*{n}{...}|. - -Voir p.~\pageref{NiceArray} la partie concernant |{NiceArray}| et |{NiceTabular}|. - -\section{Les lignes en pointillés continues} - -À l'intérieur des environnements de l'extension \pkg{nicematrix}, de nouvelles commandes sont définies : |\Ldots|, -|\Cdots|, |\Vdots|, |\Ddots|, et |\Iddots|. Ces commandes sont conçues pour être utilisées à la place de |\dots|, -|\cdots|, |\vdots|, |\ddots| et |\iddots|.\footnote{La commande |\iddots|, définie dans \pkg{nicematrix}, est une - variante de |\ddots| avec les points allant vers le haut. Si \pkg{mathdots} est chargée, la - version de \pkg{mathdots} est utilisée. Elle correspond à la commande |\adots| de \pkg{unicode-math}.} -\newcounter{fniddots} -\setcounter{fniddots}{\thefootnote} - -\smallskip -Chacune de ces commandes doit être utilisée seule dans la case du tableau et elle trace une ligne en pointillés -entre les premières cases non vides\footnote{La définition précise de ce qui est considéré comme une «case vide» - est donnée plus loin (cf. p.~\pageref{empty-cells}).} situées de part et d'autre de la case courante. Bien -entendu, pour |\Ldots| et |\Cdots|, c'est une ligne horizontale ; pour |\Vdots|, c'est une ligne verticale et pour -|\Ddots| et |\Iddots|, ce sont des lignes diagonales. On peut changer la couleur d'une ligne avec -l'option~|color|.\footnote{Il est aussi possible de changer la couleur de toutes ces lignes pointillées avec - l'option |xdots/color| (\textsl{xdots} pour rappeler que cela s'applique à |\Cdots|, |\Ldots|, |Vdots|, etc.) : - cf. p.~\pageref{customization}). -}\par\nobreak - -\bigskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -\begin{bNiceMatrix} -a_1 & \Cdots & & & a_1 \\ -\Vdots & a_2 & \Cdots & & a_2 \\ - & \Vdots & \Ddots[color=red] \\ -\\ -a_1 & a_2 & & & a_n -\end{bNiceMatrix} -\end{BVerbatim} -$\begin{bNiceMatrix} -a_1 & \Cdots & & & a_1 \\ -\Vdots & a_2 & \Cdots & & a_2 \\ - & \Vdots & \Ddots[color=red] \\ -\\ -a_1 & a_2 & & & a_n -\end{bNiceMatrix}$ - - - - -\interitem -Pour représenter la matrice nulle, on peut choisir d'utiliser le codage suivant :\par\nobreak - -\bigskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -\begin{bNiceMatrix} -0 & \Cdots & 0 \\ -\Vdots & & \Vdots \\ -0 & \Cdots & 0 -\end{bNiceMatrix} -\end{BVerbatim} -$\begin{bNiceMatrix} -0 & \Cdots & 0 \\ -\Vdots & & \Vdots \\ -0 & \Cdots & 0 -\end{bNiceMatrix}$ - -\bigskip -On peut néanmoins souhaiter une matrice plus grande. Habituellement, dans un tel cas, les utilisateurs de LaTeX -ajoutent une nouvelle ligne et une nouvelle colonne. Il est possible d'utiliser la même méthode avec -\pkg{nicematrix} :\par\nobreak - -\bigskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -\begin{bNiceMatrix} -0 & \Cdots & \Cdots & 0 \\ -\Vdots & & & \Vdots \\ -\Vdots & & & \Vdots \\ -0 & \Cdots & \Cdots & 0 -\end{bNiceMatrix} -\end{BVerbatim} -$\begin{bNiceMatrix} -0 & \Cdots & \Cdots & 0 \\ -\Vdots & & & \Vdots \\ -\Vdots & & & \Vdots \\ -0 & \Cdots & \Cdots & 0 -\end{bNiceMatrix}$ +l'extension \pkg{array} (qui est chargée par \pkg{nicematrix}). -\bigskip -Dans la première colonne de cet exemple, il y a deux instructions |\Vdots| mais une seule ligne en pointillés sera -tracée (il n'y a pas d'objets qui se superposent dans le fichier \textsc{pdf} résultant\footnote{Et il n'est pas - possible de tracer une ligne |\Ldots| et une ligne |\Cdots| entre les mêmes cases.}). +\medskip +Il y a néanmoins quelques différences : +\begin{itemize} +\item Pour des raisons techniques, dans le préambule de ces environnements, l'utilisateur doit utiliser les lettres +|L|, |C| et~|R|\footnote{Les types de colonnes |L|, |C| et |R| sont définis localement à l'intérieur de + |{NiceTabular}| ou |{NiceArray}| avec la commande |\newcolumntype| de \pkg{array}. Cette définition masque une + éventuelle définition précédente.} au lieu de |l|, |c| et |r|, y compris dans les commandes |\multicolumn| et +dans les types de colonnes définis par |\newcolumntype|. + +\item Dans |{NiceArray}| (et ses variantes), les colonnes de type |w| (ex. : |wc{1cm}|) sont composées en mode +mathématique alors que dans |{array}| de \pkg{array}, elles sont composées en mode texte. +\end{itemize} -\bigskip -En fait, dans cet exemple, il aurait été possible de tracer la même matrice plus rapidement avec le codage suivant -:\par\nobreak +\medskip +Les environnements |{pNiceArray}|, |{bNiceArray}|, etc. n'ont pas d'équivalents dans \pkg{array}. -\bigskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -\begin{bNiceMatrix} -0 & \Cdots & & 0 \\ -\Vdots & & & \\ - & & & \Vdots \\ -0 & & \Cdots & 0 -\end{bNiceMatrix} -\end{BVerbatim} -$\begin{bNiceMatrix} -0 & \Cdots & & 0 \\ -\Vdots & & & \\ - & & & \Vdots \\ -0 & & \Cdots & 0 -\end{bNiceMatrix}$ +\medskip +Les environnements |{NiceMatrix}|, |{pNiceMatrix}|, etc. sont similaires aux environnements correspondants de +l'\pkg{amsmath} (qui est chargée par \pkg{nicematrix}) : |{matrix}|, |{pmatrix}|, etc. -\bigskip -Il y a aussi d'autres moyens de changer la taille d'une matrice. On pourrait vouloir utiliser l'argument optionnel -de la commande~|\\| pour l'espacement vertical et la commande~|\hspace*| dans une case pour l'espacement -horizontal.\footnote{Dans \pkg{nicematrix}, il faut utiliser |\hspace*| et non |\hspace| car \pkg{nicematrix} - utilise \pkg{array}. Remarquons aussi que l'on peut également régler la largeur des colonnes en utilisant l'environnement |{NiceArray}| (ou - une de ses variantes) avec une colonne de type~|w| ou |W|: cf. p.~\pageref{width}} +\medskip +Tous les environnements de l'extension \pkg{nicematrix} acceptent, entre crochets, une liste optionnelle de paires +de la forme \textsl{clé=valeur}. {\bfseries Il doit n'y avoir aucun espace devant le crochet ouvrant (|[|) de cette +liste d'options.} -Toutefois, une commande~|\hspace*| pourrait interférer dans la construction des lignes en pointillés. C'est -pourquoi l'extension \pkg{nicematrix} fournit une commande~|\Hspace| qui est une variante de |\hspace| transparente -pour la construction des lignes en pointillés de \pkg{nicematrix}.\par\nobreak -\bigskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -\begin{bNiceMatrix} -0 & \Cdots & ~emphase#\Hspace*{1cm}@ & 0 \\ -\Vdots & & & \Vdots \\~emphase#[1cm]@ -0 & \Cdots & & 0 -\end{bNiceMatrix} -\end{BVerbatim} -$\begin{bNiceMatrix} -0 & \Cdots & \Hspace*{1cm} & 0 \\ -\Vdots & & & \Vdots \\[1cm] -0 & \Cdots & & 0 -\end{bNiceMatrix}$ -\subsection{L'option nullify-dots} +\section{L'espace vertical entre les rangées} -Considérons la matrice suivante qui a été composée classiquement avec l'environnement |{pmatrix}| de -\pkg{amsmath}.\par\nobreak +Il est bien connu que certaines rangées des tableaux créés par défault avec LaTeX sont trop proches l'une de +l'autre. On en donne ci-dessous un exemple classique. \medskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -$A = \begin{pmatrix} -h & i & j & k & l & m \\ -x & & & & & x +\begin{BVerbatim}[baseline=c,boxwidth=9cm] +$\begin{pmatrix} +\frac12 & -\frac12 \\ +\frac13 & \frac14 \\ \end{pmatrix}$ \end{BVerbatim} -$A = \begin{pmatrix} -h & i & j & k & l & m \\ -x & & & & & x +$\begin{pmatrix} +\frac12 & -\frac12 \\ +\frac13 & \frac14 \\ \end{pmatrix}$ - \bigskip -Si nous ajoutons des instructions |\ldots| dans la seconde rangée, la géométrie de la matrice est -modifiée.\par\nobreak +En s'inspirant de l'extension \pkg{cellspace} qui traite de ce problème, l'extension \pkg{nicematrix} propose deux +clés |cell-space-top-limit| et |cell-space-bottom-limit| qui sont similaires aux deux paramètres +|\cellspacetoplimit| et |\cellspacebottomlimit| proposés par \pkg{cellspace}. La valeur initiale de ces paramètres +est $0$~pt pour que les environnements de \pkg{nicematrix} aient par défaut le même comportement que ceux de +\pkg{array} et de l'\pkg{amsmth} mais une valeur de $1$~pt serait un bon choix. On conseille de régler leurs +valeurs avec la commande |\NiceMatrixOptions|. \medskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -$B = \begin{pmatrix} -h & i & j & k & l & m \\ -x & \ldots & \ldots & \ldots & \ldots & x -\end{pmatrix}$ -\end{BVerbatim} -$B = \begin{pmatrix} -h & i & j & k & l & m \\ -x & \ldots & \ldots & \ldots & \ldots & x -\end{pmatrix}$ - -\bigskip -Par défaut, avec \pkg{nicematrix}, si nous remplaçons |{pmatrix}| par |{pNiceMatrix}| et |\ldots| par |\Ldots|, la -géométrie de la matrice n'est pas changée.\par\nobreak +\begin{Verbatim} +\NiceMatrixOptions{~emphase#cell-space-top-limit = 1pt,cell-space-bottom-limit = 1pt@} +\end{Verbatim} -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -$C = \begin{pNiceMatrix} -h & i & j & k & l & m \\ -x & \Ldots & \Ldots & \Ldots & \Ldots & x +\begin{BVerbatim}[baseline=c,boxwidth=9cm] +$\begin{pNiceMatrix} +\frac12 & -\frac12 \\ +\frac13 & \frac14 \\ \end{pNiceMatrix}$ \end{BVerbatim} -$C = \begin{pNiceMatrix} -h & i & j & k & l & m \\ -x & \Ldots & \Ldots & \Ldots & \Ldots & x +\begin{scope} +\NiceMatrixOptions{ + cell-space-top-limit = 1pt , + cell-space-bottom-limit = 1pt , +} +$\begin{pNiceMatrix} +\frac12 & -\frac12 \\ +\frac13 & \frac14 \\ \end{pNiceMatrix}$ +\end{scope} + \bigskip -On pourrait toutefois préférer la géométrie de la première matrice $A$ et vouloir avoir la même géométrie avec une -ligne en pointillés continue dans la seconde rangée. C'est possible en utilisant l'option |nullify-dots| (et une -seule instruction |\Ldots| suffit).\par\nobreak +\section{La clé baseline} + +L'extension \pkg{nicematrix} propose une option |baseline| pour la position verticale des tableaux. Cette +option |baseline| prend comme valeur un entier qui indique le numéro de rangée dont la ligne de base servira de +ligne de base pour le tableau. \medskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -$D = \begin{pNiceMatrix}[~emphase#nullify-dots@] -h & i & j & k & l & m \\ -x & \Ldots & & & & x +\begin{BVerbatim}[baseline=c,boxwidth=9cm] +$A = \begin{pNiceMatrix}[~emphase#baseline=2@] +\frac{1}{\sqrt{1+p^2}} & p & 1-p \\ +1 & 1 & 1 \\ +1 & p & 1+p \end{pNiceMatrix}$ \end{BVerbatim} -$D = \begin{pNiceMatrix}[nullify-dots] -h & i & j & k & l & m \\ -x & \Ldots & & & & x +$A = \begin{pNiceMatrix}[baseline=2] +\frac{1}{\sqrt{1+p^2}} & p & 1-p \\ +1 & 1 & 1 \\ +1 & p & 1+p \end{pNiceMatrix}$ + +\interitem +L'option |baseline| peut aussi prendre les trois valeurs spéciales |t|, |c| et |b|. Ces trois lettres peuvent aussi +être utilisées de manière absolue comme pour l'option des environnements |{tabular}| et |{array}| de \pkg{array}. +La valeur initiale de |baseline| est~|c|. + + +\bigskip +Dans l'exemple suivant, on utilise l'option |t| (synonyme de |baseline=t|) immédiatement après un |\item| de liste. +On remarquera que la présence d'un |\hline| initial n'empêche pas l'alignement sur la ligne de base de la première +rangée (avec |{tabular}| ou |{array}| de \pkg{array}, il faut utiliser |\firsthline|\footnote{On peut aussi utiliser |\firsthline| + dans les environnements de \pkg{nicematrix}.}). + +\smallskip +\begin{BVerbatim}[baseline=c,boxwidth=9cm] +\begin{enumerate} +\item un item +\smallskip +\item \renewcommand{\arraystretch}{1.2} +$\begin{NiceArray}[t]{LCCCCCC} +\hline +n & 0 & 1 & 2 & 3 & 4 & 5 \\ +u_n & 1 & 2 & 4 & 8 & 16 & 32 +\hline +\end{NiceArray}$ +\end{enumerate} +\end{BVerbatim} +% +\begin{minipage}{5cm} +\begin{enumerate} +\item un item +\smallskip +\item \renewcommand{\arraystretch}{1.2} +$\begin{NiceArray}[t]{LCCCCCC} +\hline +n & 0 & 1 & 2 & 3 & 4 & 5 \\ +u_n & 1 & 2 & 4 & 8 & 16 & 32 \\ +\hline +\end{NiceArray}$ +\end{enumerate} +\end{minipage} + + +\bigskip +Il est également possible d'utiliser les outils de \pkg{booktabs}: |\toprule|, +|\bottomrule|, |\midrule|, etc.\par\nobreak + +\smallskip +\begin{BVerbatim}[baseline=c,boxwidth=9cm] +\begin{enumerate} +\item an item +\smallskip +\item +$\begin{NiceArray}[t]{LCCCCCC} +~emphase#\toprule@ +n & 0 & 1 & 2 & 3 & 4 & 5 \\ +~emphase#\midrule@ +u_n & 1 & 2 & 4 & 8 & 16 & 32 +~emphase#\bottomrule@ +\end{NiceArray}$ +\end{enumerate} +\end{BVerbatim} +\begin{minipage}{5cm} +\begin{enumerate} +\item an item +\smallskip +\item +$\begin{NiceArray}[t]{LCCCCCC} +\toprule +n & 0 & 1 & 2 & 3 & 4 & 5 \\ +\midrule +u_n & 1 & 2 & 4 & 8 & 16 & 32 \\ +\bottomrule +\end{NiceArray}$ +\end{enumerate} +\end{minipage} + + + +\section{Les blocs} + +\label{Block} +Dans les environnements de \pkg{nicematrix}, on peut utiliser la commande |\Block| pour placer un élément au centre +d'un rectangle de cases fusionnées. La commande |\Block| ne crée pas d'espace par elle-même. + +La commande |\Block| doit être utilisée dans la case supérieure gauche du bloc avec deux arguments. Le premier +argument est la taille de ce bloc avec la syntaxe $i$-$j$ où $i$ est le nombre de rangées et $j$ le nombre de +colonnes du bloc. Le deuxième argument, est, sans surprise, le contenu du bloc. + +Dans |{NiceTabular}|, le contenu est composé en mode texte. Dans les autres environnements, il est composé en mode +mathématique. + \medskip -L'option |nullify-dots| «smashe» les instructions |\Ldots| (et ses variantes) horizontalement mais aussi -verticalement. +\begin{BVerbatim} +\begin{NiceTabular}{CCCC} +rose & tulipe & marguerite & dahlia \\ +violette & ~emphase#\Block{2-2}{\LARGE\color{blue} fleurs}@ & & souci \\ +pervenche & & & lys \\ +arum & iris & jacinthe & muguet +\end{NiceTabular} +\end{BVerbatim} + \medskip -{\bfseries Il doit n'y avoir aucun espace devant le crochet ouvrant (|[|) des options de l'environnement.} +\begin{center} +\begin{NiceTabular}{CCCC} +rose & tulipe & marguerite & dahlia \\ +violette & \Block{2-2}{\LARGE\color{blue} fleurs} & & souci \\ +pervenche & & & lys \\ +arum & iris & jacinthe & muguet +\end{NiceTabular} +\end{center} -\subsection{La commande \textbackslash Hdotsfor} -Certaines personnes utilisent habituellement la commande |\hdotsfor| de l'extension \pkg{amsmath} pour tracer des -lignes en pointillés horizontales dans une matrice. Dans les environnements de \pkg{nicematrix}, il convient -d'utiliser |\Hdotsfor| à la place pour avoir les lignes en pointillés similaires à toutes celles tracées par -l'extension \pkg{nicematrix}. -Comme avec les autres commandes de \pkg{nicematrix} (comme |\Cdots|, |\Ldots|, |\Vdots|, etc.), la ligne en -pointillés tracée par |\Hdotsfor| s'étend jusqu'au contenu des cases de part et d'autre. +\bigskip +On peut aussi utiliser la commande |\Block| dans des matrices mathématiques. \medskip -\begin{BVerbatim}[baseline=c,boxwidth=7cm] -$\begin{pNiceMatrix} -1 & 2 & 3 & 4 & 5 \\ -1 & ~emphase#\Hdotsfor{3}@ & 5 \\ -1 & 2 & 3 & 4 & 5 \\ -1 & 2 & 3 & 4 & 5 -\end{pNiceMatrix}$ +\begin{BVerbatim}[baseline=c,boxwidth=10.6cm] +$\begin{bNiceArray}{CCC|C}[margin] +~emphase#\Block{3-3}{A}@ & & & 0 \\ +& \hspace*{1cm} & & \Vdots \\ +& & & 0 \\ +\hline +0 & \Cdots& 0 & 0 +\end{bNiceArray}$ \end{BVerbatim} -$\begin{pNiceMatrix} -1 & 2 & 3 & 4 & 5 \\ -1 & \Hdotsfor{3} & 5 \\ -1 & 2 & 3 & 4 & 5 \\ -1 & 2 & 3 & 4 & 5 -\end{pNiceMatrix}$ +$\begin{bNiceArray}{CCC|C}[margin] +\Block{3-3}{A} & & & 0 \\ +& \hspace*{1cm} & & \Vdots \\ +& & & 0 \\ +\hline +0 & \Cdots& 0 & 0 +\end{bNiceArray}$ \bigskip -Néanmoins, si ces cases sont vides, la ligne en pointillés s'étend seulement dans les cases spécifiées par -l'argument de |\Hdotsfor| (par conception). +On peut souhaiter agrandir la taille du «$A$» placé dans le bloc de l'exemple précédent. Comme il est composé en +mode mathématique, on ne peut pas directement utiliser une commande comme |\large|, |\Large| ou |\LARGE|. C'est +pourquoi une option à mettre entre chevrons est proposée par |\Block| pour spécifier du code LaTeX qui sera inséré +\emph{avant} le début du mode mathématique. \medskip -\begin{BVerbatim}[baseline=c,boxwidth=7cm] -$\begin{pNiceMatrix} -1 & 2 & 3 & 4 & 5 \\ - & ~emphase#\Hdotsfor{3}@ \\ -1 & 2 & 3 & 4 & 5 \\ -1 & 2 & 3 & 4 & 5 -\end{pNiceMatrix}$ +\begin{BVerbatim}[baseline=c,boxwidth=10.6cm] +$\begin{bNiceArray}{CCC|C}[margin] +\Block{3-3}~emphase#<\LARGE>@{A} & & & 0 \\ +& \hspace*{1cm} & & \Vdots \\ +& & & 0 \\ +\hline +0 & \Cdots& 0 & 0 +\end{bNiceArray}$ \end{BVerbatim} -$\begin{pNiceMatrix} -1 & 2 & 3 & 4 & 5 \\ - & \Hdotsfor{3} \\ -1 & 2 & 3 & 4 & 5 \\ -1 & 2 & 3 & 4 & 5 -\end{pNiceMatrix}$ +$\begin{bNiceArray}{CCC|C}[margin] +\Block{3-3}<\LARGE>{A} & & & 0 \\ +& \hspace*{1cm} & & \Vdots \\ +& & & 0 \\ +\hline +0 & \Cdots& 0 & 0 +\end{bNiceArray}$ -\medskip -Remarque : Contrairement à la commande |\hdotsfor| de \pkg{amsmath}, la commande |\Hdotsfor| est utilisable lorsque -l'extension \pkg{colortbl} est chargée (mais vous risquez d'avoir des problèmes si vous utilisez |\rowcolor| sur la -même rangée que |\Hdotsfor|). -\subsection{Comment créer les lignes en pointillés de manière transparente} +\section{Les filets horizontaux et verticaux} -L'extension \pkg{nicematrix} fournit une option appelée |transparent| qui permet d'utiliser du code existant de -manière transparente dans les environnements de l'\pkg{amsmath} : |{matrix}|, |{pmatrix}|, etc. En fait, cette -option est un alias pour la conjonction de deux options : |renew-dots| et |renew-matrix|.\footnote{Comme toutes les - autres options, les options |renew-dots|, |renew-matrix| et |transparent| peuvent être fixées avec la commande - |\NiceMatrixOptions|, mais elles peuvent aussi être passées en option du |\usepackage| (ce sont les trois - seules).} +Les techniques habituelles pour tracer des filets peuvent être utilisées dans les environnements de +\pkg{nicematrix}, à l'exception de |\vline|. + +\subsection{L'épaisseur et la couleur des filets} + +Les environnements de \pkg{nicematrix} proposent une clé |rules/width| pour fixer la largeur (en fait l'épaisseur) +des filets dans l'environnement. En fait, cette clé ne fait que fixer la valeur de |\arrayrulewidth|. \smallskip +On sait que \pkg{colortbl} propose la commande |\arrayrulecolor| pour spécifier la couleur de ces filets. -\begin{itemize} -\item L'option |renew-dots|\par\nobreak +\smallskip +Avec \pkg{nicematrix}, il est possible de spécifier une couleur même si \pkg{colortbl} n'est pas chargé. Par souci +de compatibilité, la commande est nommée également |\arrayrulecolor|. Les environnements de \pkg{nicematrix} +proposent également une clé |rules/color| qui permet de fixer cette couleur pour l'environnement en question. -Avec cette option, les commandes |\ldots|, |\cdots|, |\vdots|, |\ddots|, |\iddots|\footnotemark[\thefniddots] et -|\hdotsfor| sont redéfinies dans les environnements de \pkg{nicematrix} et agissent alors comme |\Ldots|, |\Cdots|, -|\Vdots|, |\Ddots|, |\Iddots| et |\Hdotsfor| ; la commande |\dots| (points de suspension «automatiques» de -|amsmath|) est aussi redéfinie et se comporte comme |\Ldots|. +\medskip +\begin{scope} +\hfuzz=10cm +\begin{BVerbatim}[baseline=c,boxwidth=9.5cm] +\begin{NiceTabular}{|CCC|}[~emphase#rules/color=[gray]{0.9},rules/width=1pt@] +\hline +rose & tulipe & lys \\ +arum & iris & violette \\ +muguet & dahlia & souci \\ +\hline +\end{NiceTabular} +\end{BVerbatim} +\begin{NiceTabular}{|CCC|}[rules/color=[gray]{0.9},rules/width=1pt] +\hline +rose & tulipe & lys \\ +arum & iris & violette \\ +muguet & dahlia & souci \\ +\hline +\end{NiceTabular} +\end{scope} -\item L'option |renew-matrix|\par\nobreak +\medskip +Si on veut définir de nouveaux spécificateurs de colonnes pour des filets (par exemple plus épais ou bien d'une +couleur spécifique), on aura peut-être intérêt à utiliser la commande |\OnlyMainNiceMatrix| décrite p.~\pageref{OnlyMainNiceMatrix}. -Avec cette option, l'environnement |{matrix}| est redéfini et se comporte comme |{NiceMatrix}| et il en est de même -pour les cinq variantes. -\end{itemize} -\bigskip -Par conséquent, avec l'option |transparent|, un code classique donne directement le résultat fourni par -\pkg{nicematrix}.\par\nobreak \bigskip -\begin{scope} -\NiceMatrixOptions{transparent} +\subsection{Une remarque concernant \textbackslash cline} + +\label{remark-cline} + +Les traits verticaux et horizontaux que l'on insère avec |\hline| et le spécificateur de colonne «\verb+|+» de +\pkg{array} rendent le tableau plus large ou plus long d'une quantité égale à la largeur du trait. + +\smallskip +Pour des raisons historiques, il n'en est pas de même pour la commande |\cline|, comme on peut le voir avec +l'exemple suivant. + +\medskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] -~emphase#\NiceMatrixOptions{transparent}@ -\begin{pmatrix} -1 & \cdots & \cdots & 1 \\ -0 & \ddots & & \vdots \\ -\vdots & \ddots & \ddots & \vdots \\ -0 & \cdots & 0 & 1 -\end{pmatrix} +\setlength{\arrayrulewidth}{2pt} +\begin{tabular}{cccc} \hline +A&B&C&D \\ ~emphase#\cline{2-2}@ +A&B&C&D \\ \hline +\end{tabular} \end{BVerbatim} -$\begin{pmatrix} -1 & \cdots & \cdots & 1 \\ -0 & \ddots & & \vdots \\ -\vdots & \ddots & \ddots & \vdots \\ -0 & \cdots & 0 & 1 -\end{pmatrix}$ +% +\begin{scope} +\setlength{\arrayrulewidth}{2pt} +\begin{tabular}[c]{cccc} +\hline +A&B&C&D \\ +\cline{2-2} +A&B&C&D \\ +\hline +\end{tabular} \end{scope} +\medskip +Dans les environnements de \pkg{nicematrix}, cette situation est corrigée (il est néanmoins possible de revenir au +comportement par défaut de |\cline| avec la clé |standard-cline|). -\subsection{Les labels des lignes en pointillés} - -Les commandes |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| et |\Hdotsfor| (ainsi que la commande |\line| dans -le |code-after| décrite p.~\pageref{line-in-code-after}) peuvent en fait prendre deux arguments optionnels -spécifiés par les caractères |_| et |^| pour des labels situés au-dessous et au-dessus de la ligne. Les arguments -sont composés en mode mathématique avec |\scriptstyle|. - +\medskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] -$\begin{bNiceMatrix} -1 & \hspace*{1cm} & 0 \\[8mm] - & ~emphase#\Ddots^{n \text{ times}}@ & \\ -0 & & 1 -\end{bNiceMatrix}$ +\setlength{\arrayrulewidth}{2pt} +\begin{NiceTabular}{CCCC} \hline +A&B&C&D \\ ~emphase#\cline{2-2}@ +A&B&C&D \\ \hline +\end{NiceTabular} \end{BVerbatim} -$\begin{bNiceMatrix} -1 & \hspace*{1cm} & 0 \\[8mm] - & \Ddots^{n \text{ times}} & \\ -0 & & 1 -\end{bNiceMatrix}$ +% +\begin{scope} +\setlength{\arrayrulewidth}{2pt} +\begin{NiceTabular}[c]{CCCC} +\hline +A&B&C&D \\ +\cline{2-2} +A&B&C&D \\ +\hline +\end{NiceTabular} +\end{scope} -\subsection{Personnalisation des lignes en pointillés} +\bigskip +\subsection{Les clés hlines et vlines} -\label{customization} -Les lignes pointillées tracées par |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| et |\Hdotsfor| (ainsi que par la -commande |\line| dans le |code-after| décrite p.~\pageref{line-in-code-after}) peuvent être -paramétrées par trois options (que l'on met entre crochets après la commande) : -% -\begin{itemize} -\item |color| ; -\item |shorten| ; -\item |line-style|. -\end{itemize} - -Ces options peuvent aussi être fixées avec |\NiceMatrixOptions| ou bien au niveau d'un environnement mais elles -doivent alors être préfixées par |xdots|, ce qui fait que leurs noms deviennent : -% -\begin{itemize} -\item |xdots/color| ; -\item |xdots/shorten| ; -\item |xdots/line-style|. -\end{itemize} -% -Pour la clarté, dans la suite, on utilisera ces noms-là. +La clé |hlines| demande un tracé de tous les filets horizontaux et la clé |vlines| demande un tracé de tous les +filets verticaux. En fait, dans les environnements avec délimiteurs (comme |{pNiceMatrix}| ou |{bNiceArray}|), les +filets extérieurs ne sont pas tracés (ce qui est le comportement certainement attendu). -\bigskip -\textbf{L'option xdots/color}\par\nobreak -\smallskip -L'option |xdots/color| indique bien entendu la couleur de la ligne tracée. On remarquera néanmoins que les lignes -tracées dans les rangées et colonnes extérieures (décrites plus loin) bénificient d'un régime spécial : cf. -p.~\pageref{exterior}. +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=10.6cm] +$\begin{pNiceMatrix}[~emphase#vlines@,rules/width=0.2pt] +1 & 2 & 3 & 4 & 5 & 6 \\ +1 & 2 & 3 & 4 & 5 & 6 \\ +1 & 2 & 3 & 4 & 5 & 6 +\end{pNiceMatrix}$ +\end{BVerbatim} +$\begin{pNiceMatrix}[vlines,rules/width=0.2pt] +1 & 2 & 3 & 4 & 5 & 6 \\ +1 & 2 & 3 & 4 & 5 & 6 \\ +1 & 2 & 3 & 4 & 5 & 6 +\end{pNiceMatrix}$ \bigskip -\textbf{L'option xdots/shorten}\par\nobreak +Il y a néanmoins une différence entre l'utilisation de l'option |vlines| et du spécificateur «\verb+|+» dans le +préambule de l'environnement : les filets tracés par |vlines| traversent les double-filets horizontaux tracés par +|\hline\hline| (il n'y a pas besoin d'utiliser \pkg{hhline}). -\smallskip -L'option |xdots/shorten| indique la marge qui est laissée aux deux extrémités de la ligne. Le nom s'inspire des options -«|shorten >|» et «|shorten <|» de Tikz, mais il faut remarquer que \pkg{nicematrix} ne propose que |xdots/shorten|. -La valeur initiale de ce paramètre est de $0.3$~em (il est conseillé d'utiliser une unité de mesure dépendante de -la fonte courante). +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11.5cm] +$\begin{NiceMatrix}[~emphase#vlines@] \hline +a & b & c & d \\ \hline \hline +1 & 2 & 3 & 4 \\ +1 & 2 & 3 & 4 \\ \hline +\end{NiceMatrix}$ +\end{BVerbatim} +% +$\begin{NiceMatrix}[vlines] +\hline +a & b & c & d \\ +\hline \hline +1 & 2 & 3 & 4 \\ +1 & 2 & 3 & 4 \\ +\hline +\end{NiceMatrix}$ \bigskip -\textbf{L'option xdots/line-style}\par\nobreak +Si vous utilisez \pkg{booktabs} (qui fournit |\toprule|, |\midrule|, |\bottomrule|, etc.) et que vous tenez +absolument à mettre des filets verticaux (ce qui est contraire à l'esprit à \pkg{booktabs}), sachez que la clé +|vlines| est compatible avec \pkg{booktabs}. -\smallskip -Il faut savoir que, par défaut, les lignes de Tikz tracées avec le paramètre |dotted| sont composées de points -carrés et non pas ronds.\footnote{La raison de départ est que le format \textsc{pdf} comporte un système de description - de lignes en tiretés, qui, puisqu'il est incorporé dans le \textsc{pdf}, est affiché très rapidement par les - lecteurs de \textsc{pdf}. Il est facile à partir de ce type de ligne de créer des lignes de points carrés alors - qu'une ligne de points ronds doit être construite explicitement point par point.} - -\begin{BVerbatim}[baseline=c,boxwidth=9cm] -\tikz \draw [dotted] (0,0) -- (5,0) ; +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11.5cm] +$\begin{NiceMatrix}[~emphase#vlines@] \toprule +a & b & c & d \\ \midrule +1 & 2 & 3 & 4 \\ +1 & 2 & 3 & 4 \\ \bottomrule +\end{NiceMatrix}$ \end{BVerbatim} -\tikz \draw [dotted] (0,0) -- (5,0) ; +% +$\begin{NiceMatrix}[vlines] +\toprule +a & b & c & d \\ +\midrule +1 & 2 & 3 & 4 \\ +1 & 2 & 3 & 4 \\ +\bottomrule +\end{NiceMatrix}$ -\bigskip -Voulant proposer des lignes avec des points ronds dans le style de celui de |\ldots| (au moins celui des fontes -\emph{Computer Modern}), l'extension \pkg{nicematrix} contient en interne son propre système de ligne en pointillés -(qui, au passage, n'utilise que \pkg{pgf} et non \pkg{tikz}). Ce style est appelé le style |standard|. Cette valeur -est la valeur initiale du paramètre |xdots/line-style|. -\bigskip -Néanmoins (quand Tikz est chargé), on peut utiliser pour |xdots/line-style| n'importe quel style proposé par Tikz, -c'est-à-dire n'importe quelle suite d'options Tikz applicables à un chemin (à l'exception de «|color|», -«|shorten >|» et «|shorten <|»). +\subsection{La clé hvlines} +\label{hvlines} + +La clé |hvlines| demande le tracé de tous les filets horizontaux et verticaux \emph{sauf dans les + blocs}.\footnote{En fait, quand la clé |hvlines| est utilisée, les filets ne sont pas non plus tracés dans les blocs virtuels + délimités par des cases reliées par des lignes pointillées (cf. p. \pageref{dotted-and-hvlines}).} \medskip -Voici par exemple une matrice tridiagonale avec le style |loosely dotted| :\par\nobreak +\begin{Verbatim} +\begin{NiceTabular}{CCCC}[~emphase#hvlines@,rules/color=blue,rules/width=1pt] +rose & tulipe & marguerite & dahlia \\ +violette & \Block{2-2}{\LARGE\color{blue} fleurs} & & souci \\ +pervenche & & & lys \\ +arum & iris & jacinthe & muguet +\end{NiceTabular} +\end{Verbatim} +% +\begin{center} +\begin{NiceTabular}{CCCC}[hvlines,rules/color=blue,rules/width=1pt] +rose & tulipe & marguerite & dahlia \\ +violette & \Block{2-2}{\LARGE\color{blue} fleurs} & & souci \\ +pervenche & & & lys \\ +arum & iris & jacinthe & muguet +\end{NiceTabular} +\end{center} + + + +\subsection{La commande \textbackslash diagbox} + +La commande |\diagbox| (inspirée par l'extension \pkg{diagbox}) permet, quand elle est utilisée dans une case, de +couper cette case selon une diagonale descendante.\footnote{L'auteur de ce document considère que ce type de + construction est un piètre choix graphique.} \medskip -\begin{BVerbatim}[baseline=c] -$\begin{pNiceMatrix}[nullify-dots,~emphase#xdots/line-style=loosely dotted@] -a & b & 0 & & \Cdots & 0 \\ -b & a & b & \Ddots & & \Vdots \\ -0 & b & a & \Ddots & & \\ - & \Ddots & \Ddots & \Ddots & & 0 \\ -\Vdots & & & & & b \\ -0 & \Cdots & & 0 & b & a -\end{pNiceMatrix}$ +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\begin{NiceArray}{*{5}{C}}[hvlines] +~emphase#\diagbox{x}{y}@ & e & a & b & c \\ +e & e & a & b & c \\ +a & a & e & c & b \\ +b & b & c & e & a \\ +c & c & b & a & e +\end{NiceArray}$ \end{BVerbatim} +$\begin{NiceArray}{*{5}{C}}[hvlines] +\diagbox{x}{y} & e & a & b & c \\ +e & e & a & b & c \\ +a & a & e & c & b \\ +b & b & c & e & a \\ +c & c & b & a & e +\end{NiceArray}$ -\[\begin{pNiceMatrix}[nullify-dots,xdots/line-style=loosely dotted] -a & b & 0 & & \Cdots & 0 \\ -b & a & b & \Ddots & & \Vdots \\ -0 & b & a & \Ddots & & \\ - & \Ddots & \Ddots & \Ddots & & 0 \\ -\Vdots & & & & & b \\ -0 & \Cdots & & 0 & b & a -\end{pNiceMatrix}\] -\section{Les nœuds PGF-Tikz créés par l'extension nicematrix} -\label{name} +\subsection{Filets en pointillés} -L'extension \pkg{nicematrix} crée un nœud PGF-Tikz pour chaque case (non vide) du tableau considéré. Ces nœuds sont -utilisés pour tracer les lignes en pointillés entre les cases du tableau. Toutefois, l'utilisateur peut aussi -utiliser directement ces nœuds (s'il a chargé Tikz\footnote{On rappelle que depuis la version 3.13, - \pkg{nicematrix} ne charge plus Tikz par défaut, mais seulement \textsc{pgf} (Tikz est une surcouche de - \textsc{pgf}).}). On commence par donner un nom au tableau (avec l'option |name|). Cela étant fait, les nœuds -sont accessibles à travers les noms «\textsl{nom}-$i$-$j$» où \textsl{nom} est le nom donné au tableau et $i$ et -$j$ les numéros de rangée et de colonne de la case considérée. + +Dans les environnements de \pkg{nicematrix}, il est possible d'utiliser la commande |\hdottedline| (fournie +par \pkg{nicematrix}) qui est l'équivalent pour les pointillés des commandes |\hline| et |\hdashline| +(cette dernière étant une commande de \pkg{arydshln}). \medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] -$\begin{pNiceMatrix}[name=~emphase#ma-matrice@] -1 & 2 & 3 \\ -4 & 5 & 6 \\ -7 & 8 & 9 -\end{pNiceMatrix}$ -\tikz[remember picture,overlay] - \draw ~emphase#(ma-matrice-2-2)@ circle (2mm) ; +\begin{BVerbatim}[baseline=c,boxwidth=9.5cm] +\begin{pNiceMatrix} +1 & 2 & 3 & 4 & 5 \\ +~emphase#\hdottedline@ +6 & 7 & 8 & 9 & 10 \\ +11 & 12 & 13 & 14 & 15 +\end{pNiceMatrix} \end{BVerbatim} -$\begin{pNiceMatrix}[name=ma-matrice] -1 & 2 & 3 \\ -4 & 5 & 6 \\ -7 & 8 & 9 +$\begin{pNiceMatrix} +1 & 2 & 3 & 4 & 5 \\ +\hdottedline +6 & 7 & 8 & 9 & 10 \\ +11 & 12 & 13 & 14 & 15 \end{pNiceMatrix}$ -\tikz[remember picture,overlay] - \draw (ma-matrice-2-2) circle (2mm) ; + + +\bigskip +Dans les environnements avec un préambule explicite (comme |{NiceTabular}|, |{NiceArray}|, etc.), il est possible +de dessiner un trait vertical en pointillés avec le spécificateur «|:|». \medskip -Ne pas oublier les options |remember picture| et |overlay|. +\begin{BVerbatim}[baseline=c,boxwidth=9.5cm] +\begin{pNiceArray}{CCCC~emphase#:@C} +1 & 2 & 3 & 4 & 5 \\ +6 & 7 & 8 & 9 & 10 \\ +11 & 12 & 13 & 14 & 15 +\end{pNiceArray} +\end{BVerbatim} +$\begin{pNiceArray}{CCCC:C} +1 & 2 & 3 & 4 & 5 \\ +6 & 7 & 8 & 9 & 10 \\ +11 & 12 & 13 & 14 & 15 +\end{pNiceArray}$ \bigskip -Dans l'exemple suivant, nous avons surligné toutes les cases de la matrice. -\[\begin{pNiceMatrix} -a & a + b & a + b + c \\ -a & a & a + b \\ -a & a & a -\CodeAfter -\begin{tikzpicture}[ - every node/.style = - { - blend mode = multiply, - inner sep = 0 pt , - fill = red!15 - } - ] -\node [fit = (1-1)] {} ; -\node [fit = (1-3)] {} ; -\node [fit = (2-2)] {} ; -\node [fit = (3-1)] {} ; -\node [fit = (3-3)] {} ; -\node [fit = (1-2)] {} ; -\node [fit = (2-1)] {} ; -\node [fit = (2-3)] {} ; -\node [fit = (3-2)] {} ; -\end{tikzpicture} -\end{pNiceMatrix}\] +Il est possible de changer dans \pkg{nicematrix} la lettre utilisée pour indiquer dans le préambule un trait +vertical en pointillés avec l'option |letter-for-dotted-lines| disponible dans |\NiceMatrixOptions|. \bigskip -En fait, l'extension \pkg{nicematrix} peut créer deux séries de nœuds supplémentaires (\emph{extra nodes} en -anglais) : les «nœuds moyens» (\emph{medium nodes} en anglais) et les «nœuds larges» (\emph{large nodes} en -anglais). Les premiers sont créés avec l'option |create-medium-nodes| et les seconds avec l'option -|create-large-nodes|.\footnote{Il existe aussi l'option |create-extra-nodes| qui est un alias pour la conjonction -de |create-medium-nodes| et |create-large-nodes|.} +\emph{Remarque} : Quand l'extension \pkg{array} (sur laquelle s'appuie \pkg{nicematrix}) est chargée, les traits +verticaux et horizontaux que l'on insère rendent le tableau plus large ou plus long d'une quantité égale à la +largeur du trait\footnote{En fait, cela est vrai pour |\hline| et «\verb+|+» mais pas pour |\cline|.}. Avec +\pkg{nicematrix}, les lignes en pointillés tracées par |\hdottedline| et «|:|» ont le même effet. -\medskip -Les noms des «nœuds moyens» s'obtiennent en ajoutant le suffixe «|-medium|» au nom des nœuds normaux. Dans -l'exemple suivant, on a surligné tous les «nœuds moyens». Nous considérons que cet exemple se suffit à lui-même -comme définition de ces nœuds. -\[\begin{pNiceMatrix}[ - create-medium-nodes, - code-after = {\begin{tikzpicture} - [every node/.style = {fill = red!15, - blend mode = multiply, - inner sep = 0 pt}, - name suffix = -medium] - \node [fit = (1-1)] {} ; - \node [fit = (1-2)] {} ; - \node [fit = (1-3)] {} ; - \node [fit = (2-1)] {} ; - \node [fit = (2-2)] {} ; - \node [fit = (2-3)] {} ; - \node [fit = (3-1)] {} ; - \node [fit = (3-2)] {} ; - \node [fit = (3-3)] {} ; - \end{tikzpicture}}] -a & a + b & a + b + c \\ -a & a & a + b \\ -a & a & a -\end{pNiceMatrix}\] -\medskip -Les noms des «nœuds larges» s'obtiennent en ajoutant le suffixe «|-large|» au nom des nœuds normaux. Dans l'exemple -suivant, on a surligné tous les «nœuds larges». Nous considérons que cet exemple se suffit à lui-même comme -définition de ces nœuds.\footnote{Il n'y a pas de «nœuds larges» créés dans les rangées et colonnes extérieures - (pour ces rangées et colonnes, voir p.~\pageref{exterior}).} -\[\begin{pNiceMatrix}[ - create-large-nodes, - code-after = {\begin{tikzpicture} - [every node/.style = {blend mode = multiply, - inner sep = 0 pt}, - name suffix = -large] - \node [fit = (1-1),fill = red!15] {} ; - \node [fit = (1-3),fill = red!15] {} ; - \node [fit = (2-2),fill = red!15] {} ; - \node [fit = (3-1),fill = red!15] {} ; - \node [fit = (3-3),fill = red!15] {} ; - \node [fit = (1-2),fill = blue!15] {} ; - \node [fit = (2-1),fill = blue!15] {} ; - \node [fit = (2-3),fill = blue!15] {} ; - \node [fit = (3-2),fill = blue!15] {} ; - \end{tikzpicture}}] -a & a + b & a + b + c \\ -a & a & a + b \\ -a & a & a -\end{pNiceMatrix}\] +\section{Les couleurs des rangées et des colonnes} +L'extension \pkg{colortbl} permet de colorier des cases, des rangées ou des colonnes d'un tableau. Néanmoins, +l'affichage du \textsc{pdf} résultant n'est pas toujours parfait, en particulier quand on utilise également des +filets. Dans certains lecteurs de \textsc{pdf}, des filets verticaux semblent disparaître. De fines lignes blanches +peuvent également apparaître. \medskip -Les «nœuds larges» de la première colonne et de la dernière colonne peuvent apparaître trop petits pour certains -usages. C'est pourquoi il est possible d'utiliser les options |left-margin| et |right-margin| pour ajouter de -l'espace des deux côtés du tableau et aussi de l'espace dans les «nœuds larges» de la première colonne et de la -dernière colonne. Dans l'exemple suivant, nous avons utilisé les options |left-margin| et -|right-margin|.\footnote{Les options |left-margin| et |right-margin| prennent des dimensions comme valeurs mais, si - aucune valeur n'est donnée, c'est la valeur par défaut qui est utilisée et elle est égale à |\arraycolsep| (par - défaut, 5~pt).Il existe aussi une option |margin| pour fixer à la fois |left-margin| et |right-margin|.} -\[\begin{pNiceMatrix}[ - create-large-nodes,left-margin,right-margin, - code-after = {\begin{tikzpicture} - [every node/.style = {blend mode = multiply, - inner sep = 0 pt}, - name suffix = -large] - \node [fit = (1-1),fill = red!15] {} ; - \node [fit = (1-3),fill = red!15] {} ; - \node [fit = (2-2),fill = red!15] {} ; - \node [fit = (3-1),fill = red!15] {} ; - \node [fit = (3-3),fill = red!15] {} ; - \node [fit = (1-2),fill = blue!15] {} ; - \node [fit = (2-1),fill = blue!15] {} ; - \node [fit = (2-3),fill = blue!15] {} ; - \node [fit = (3-2),fill = blue!15] {} ; - \end{tikzpicture}}] -a & a + b & a + b + c \\ -a & a & a + b \\ -a & a & a -\end{pNiceMatrix}\] +L'extension \pkg{nicematrix} propose des outils similaires qui ne présentent pas ces inconvénients. Elle propose +une clé |code-before|\footnote{Il existe aussi une clé |code-after| : cf. p.~\pageref{code-after}.} pour du code +qui sera exécuté \emph{avant} le tracé du tableau. Dans ce |code-before|, de nouvelles commandes sont disponibles : +|\cellcolor|, |\rectanglecolor|, |\rowcolor|, |\columncolor|, |\rowcolors| et |\chessboardcolors|. +\label{code-before} \medskip -Il est aussi possible d'ajouter de l'espace sur les côtés du tableau avec les options |extra-left-margin| et -|extra-right-margin|. Ces marges ne sont pas incorporées dans les «nœuds larges». Dans l'exemple suivant, nous -avons utilisé |extra-left-margin| et |extra-right-margin| avec la valeur $3$~pt. -\[\begin{pNiceMatrix}[ - create-large-nodes,left-margin,right-margin,extra-right-margin=3pt,extra-left-margin=3pt, - code-after = {\begin{tikzpicture} - [every node/.style = {blend mode = multiply, - inner sep = 0 pt}, - name suffix = -large] - \node [fit = (1-1),fill = red!15] {} ; - \node [fit = (1-3),fill = red!15] {} ; - \node [fit = (2-2),fill = red!15] {} ; - \node [fit = (3-1),fill = red!15] {} ; - \node [fit = (3-3),fill = red!15] {} ; - \node [fit = (1-2),fill = blue!15] {} ; - \node [fit = (2-1),fill = blue!15] {} ; - \node [fit = (2-3),fill = blue!15] {} ; - \node [fit = (3-2),fill = blue!15] {} ; - \end{tikzpicture}}] -a & a + b & a + b + c \\ -a & a & a + b \\ -a & a & a -\end{pNiceMatrix}\] +Ces outils sont indépendants de \pkg{colortbl}.\footnote{On peut donc colorier les filets, les cellules, les + rangées, les colonnes, etc. sans charger \pkg{colortbl}. Le présent document ne charge pas \pkg{colortbl}.} \medskip -Dans le cas présent, si on veut un contrôle sur la hauteur des rangées, on peut ajouter un |\strut| dans chaque -rangée du tableau. -\[\begin{pNiceMatrix}[ - create-large-nodes,left-margin,right-margin,extra-right-margin=3pt,extra-left-margin=3pt, - code-after = {\begin{tikzpicture} - [every node/.style = {blend mode = multiply, - inner sep = 0 pt}, - name suffix = -large] - \node [fit = (1-1),fill = red!15] {} ; - \node [fit = (1-3),fill = red!15] {} ; - \node [fit = (2-2),fill = red!15] {} ; - \node [fit = (3-1),fill = red!15] {} ; - \node [fit = (3-3),fill = red!15] {} ; - \node [fit = (1-2),fill = blue!15] {} ; - \node [fit = (2-1),fill = blue!15] {} ; - \node [fit = (2-3),fill = blue!15] {} ; - \node [fit = (3-2),fill = blue!15] {} ; - \end{tikzpicture}}] -\strut a & a + b & a + b + c \\ -\strut a & a & a + b \\ -\strut a & a & a -\end{pNiceMatrix}\] +Toutes ces commandes acceptent un argument optionnel (entre crochets et en première position) qui est le modèle +colorimétrique pour la spécification des couleurs. -\bigskip -On explique plus loin comment surligner les nœuds créés par Tikz (cf. p. \pageref{highlight}). - -\section{Le code-after} - -\label{code-after} +\medskip +\begin{itemize} +\item La commande |\cellcolor| tient son nom de la commande |\cellcolor| de \pkg{colortbl}. -L'option |code-after| peut être utilisée pour indiquer du code qui sera exécuté après la construction de la matrice, -et donc, en particulier, après la construction de tous les nœuds. +Elle prend en arguments obligatoires une couleur et une liste de cases sous le format $i$-$j$ où $i$ est le +numéro de ligne et $j$ le numéro de colonne. -\textbf{Si on a chargé Tikz}\footnote{On rappelle que depuis la version 3.13, \pkg{nicematrix} ne charge plus Tikz - par défaut, mais seulement \textsc{pgf} (Tikz est une surcouche de \textsc{pgf}).}, on peut accéder à ces nœuds -avec des instructions Tikz classiques. Les nœuds devront être désignés sous la forme $i$-$j$ (sans le préfixe -correspondant au nom de l'environnement). +\medskip +\begin{scope} +\hfuzz=10cm +\begin{BVerbatim}[boxwidth=10cm,baseline=c] +\begin{NiceTabular}{|C|C|C|}[code-before = ~emphase#\cellcolor{red!15}{3-1,2-2,1-3}@] +\hline +a & b & c \\ \hline +e & f & g \\ \hline +h & i & j \\ \hline +\end{NiceTabular} +\end{BVerbatim} +\begin{NiceTabular}{|C|C|C|}[code-before = \cellcolor{red!15}{3-1,2-2,1-3}] +\hline +a & b & c \\ \hline +e & f & g \\ \hline +h & i & j \\ \hline +\end{NiceTabular} +\end{scope} -De plus, une commande spéciale, nommée |\line| est disponible pour tracer directement des lignes en pointillés -entre les nœuds). Elle peut par exemple être utilisée pour tracer une ligne entre deux cases adjacentes comme dans -l'exemple suivant. -\label{line-in-code-after} +\bigskip +\item La commande |\rectanglecolor| prend trois arguments obligatoires. Le premier est la couleur, les deux +suivants fournissent la case en haut à gauche et la case en bas à droite du rectangle. \medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] -\NiceMatrixOptions{xdots/shorten = 0.6 em} -\begin{pNiceMatrix}[~emphase#code-after=\line{2-2}{3-3}@] -I & 0 & \Cdots &0 \\ -0 & I & \Ddots &\Vdots\\ -\Vdots &\Ddots & I &0 \\ -0 &\Cdots & 0 &I -\end{pNiceMatrix} -\end{BVerbatim} \begin{scope} -\NiceMatrixOptions{xdots/shorten = 0.6 em} -$\begin{pNiceMatrix}[code-after=\line{2-2}{3-3}] -I & 0 & \Cdots &0 \\ -0 & I & \Ddots &\Vdots\\ -\Vdots &\Ddots & I &0 \\ -0 &\Cdots & 0 &I -\end{pNiceMatrix}$ +\hfuzz=10cm +\begin{BVerbatim}[boxwidth=10cm,baseline=c] +\begin{NiceTabular}{|C|C|C|}[code-before = ~emphase#\rectanglecolor{blue!15}{2-2}{3-3}@] +\hline +a & b & c \\ \hline +e & f & g \\ \hline +h & i & j \\ \hline +\end{NiceTabular} +\end{BVerbatim} +\begin{NiceTabular}{|C|C|C|}[code-before = \rectanglecolor{blue!15}{2-2}{3-3}] +\hline +a & b & c \\ \hline +e & f & g \\ \hline +h & i & j \\ \hline +\end{NiceTabular} \end{scope} + + +\bigskip +\item La commande |\rowcolor| doit son nom à la commande |\rowcolor| de \pkg{colortbl}. Son premier argument +obligatoire est la couleur et le deuxième est une liste de numéros de rangées ou bien d'intervalles de rangées sous +la forme $a$-$b$ (un intervalle de la forme $a$- représente toutes les rangées à partir de la rangée~$a$). + \medskip -Pour améliorer la lisibilité du code, une syntaxe alternative est proposée : on peut spécifier les instructions du -|code-after| à la fin de l'environnement, après le mot-clé |\CodeAfter|. Pour un exemple, voir page -\pageref{exemple-CodeAfter}. -\section{Les environnements \{NiceArray\} et \{NiceTabular\}} -\label{NiceArray} +\begin{scope} +\hfuzz=10cm +\begin{BVerbatim}[boxwidth=9cm,baseline=c] +$\begin{NiceArray}{LLL}[hvlines, ~emphase#code-before = \rowcolor{red!15}{1,3-5,8-}@] +a_1 & b_1 & c_1 \\ +a_2 & b_2 & c_2 \\ +a_3 & b_3 & c_3 \\ +a_4 & b_4 & c_4 \\ +a_5 & b_5 & c_5 \\ +a_6 & b_6 & c_6 \\ +a_7 & b_7 & c_7 \\ +a_8 & b_8 & c_8 \\ +a_9 & b_9 & c_9 \\ +a_{10} & b_{10} & c_{10} \\ +\end{NiceArray}$ +\end{BVerbatim} +% +$\begin{NiceArray}{LLL}% +[baseline=4,hvlines, code-before = \rowcolor{red!15}{1,3-5,8-}] +a_1 & b_1 & c_1 \\ +a_2 & b_2 & c_2 \\ +a_3 & b_3 & c_3 \\ +a_4 & b_4 & c_4 \\ +a_5 & b_5 & c_5 \\ +a_6 & b_6 & c_6 \\ +a_7 & b_7 & c_7 \\ +a_8 & b_8 & c_8 \\ +a_9 & b_9 & c_9 \\ +a_{10} & b_{10} & c_{10} \\ +\end{NiceArray}$ +\end{scope} -Les environnements |{NiceArray}| et |{NiceTabular}| sont similaires aux environnements |{array}| et |{tabular}|. -L'argument obligatoire est le préambule du tableau. Néanmoins, pour des raisons techniques, l'utilisateur doit -utiliser les lettres |L|, |C| et |R|\footnote{Les types de colonnes |L|, |C| et |R| sont définis localement à - l'intérieur de |{NiceArray}| avec la commande |\newcolumntype| de \pkg{array}. Cette définition masque une - éventuelle définition précédente.} au lieu de |l|, |c| et |r|. Dans une commande |\multicolumn|, on doit -également utiliser les lettres |L|, |C| et |R|. -Il est possible d'utiliser les constructions |p{...}|, |m{...}|, |b{...}|, |w{...}{...}|, |W{...}{...}|, \verb+|+, -|>{...}|, |<{...}|, |@{...}|, |!{...}| et |*{n}{...}|. Néanmoins, dans l'environnement |{NiceArray}| (et ses -variantes), le contenu des colonnes de type |w| ou |W| est composé en mode mathématique (dans |{array}| de -\pkg{array}, elles sont composées en mode texte). +\bigskip +\item La commande |\columncolor| doit son nom à la commande |\columncolor| de \pkg{colortbl}. Sa syntaxe est +similaire à celle de |\rowcolor|. \bigskip -Sans surprise, l'extension \pkg{nicematrix} fournit également les variantes |{pNiceArray}|, |{vNiceArray}|, -|{VNiceArray}|, |{bNiceArray}| et |{BNiceArray}|. +\item La commande |\rowcolors| (avec un \emph{s}) doit son nom à la commande |\rowcolors| de +\pkg{xcolor}\footnote{La commande |\rowcolors| de \pkg{xcolor} est disponible quand \pkg{xcolor} est chargé avec + l'option |table|.}. Le \emph{s} rappelle qu'il y a deux couleurs. Elle colorie alternativement les rangées avec +les deux couleurs à partir de la rangée dont le numéro est donné en premier argument (obligatoire). + +\medskip +\begin{scope} +\hfuzz=10cm +\begin{BVerbatim}[baseline=c,boxwidth=9cm] +\begin{NiceTabular}{LR}[hlines,code-before = ~emphase#\rowcolors{1}{blue!10}{}@] +Pierre & 12 \\ +Jacques & 8 \\ +Stéphanie & 18 \\ +Amélie & 20 \\ +Henri & 14 \\ +Estelle & 15 +\end{NiceTabular} +\end{BVerbatim} +\begin{NiceTabular}{LR}[hlines,code-before = \rowcolors{1}{blue!10}{},baseline=3] +Pierre & 12 \\ +Jacques & 8 \\ +Stéphanie & 18 \\ +Amélie & 20 \\ +Henri & 14 \\ +Estelle & 15 +\end{NiceTabular} +\end{scope} + -\interitem -L'un des intérêts de |{pNiceArray}| par rapport à |{pNiceMatrix}| est la possibilité de tracer des filets verticaux -: \bigskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -$\left[\begin{NiceArray}{CCCC|C} -a_1 & ? & \Cdots & ? & ? \\ -0 & & \Ddots & \Vdots & \Vdots\\ -\Vdots & \Ddots & \Ddots & ? \\ -0 & \Cdots & 0 & a_n & ? -\end{NiceArray}\right]$ -\end{BVerbatim} -$\left[\begin{NiceArray}{CCCC|C} -a_1 & ? & \Cdots & ? & ? \\ -0 & & \Ddots & \Vdots & \Vdots\\ -\Vdots & \Ddots & \Ddots & ? \\ -0 & \Cdots & 0 & a_n & ? -\end{NiceArray}\right]$ +\item La commande |\chessboardcolors| prend en arguments obligatoires deux couleurs et colorie les cases en +quinconces avec les deux couleurs. -\interitem -Un autre intérêt est la possibilité d'utiliser plusieurs types d'alignement de colonnes. +\medskip +\begin{scope} +\hfuzz=10cm +\begin{BVerbatim}[baseline=c,boxwidth=9cm] +$\begin{pNiceMatrix}[R,margin, ~emphase#code-before=\chessboardcolors{red!15}{blue!15}@] +1 & -1 & 1 \\ +-1 & 1 & -1 \\ +1 & -1 & 1 +\end{pNiceMatrix}$ +\end{BVerbatim} +$\begin{pNiceMatrix}% +[baseline=1, R, margin, code-before = \chessboardcolors{red!15}{blue!15}] +1 & -1 & 1 \\ +-1 & 1 & -1 \\ +1 & -1 & 1 +\end{pNiceMatrix}$ +\end{scope} + +\medskip +On a utilisé la clé |R| qui impose que toutes les colonnes soient alignées à droite (cf. p.~\pageref{key-R}). +\end{itemize} \bigskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -$\begin{pNiceArray}{LCR} -a_{11} & \Cdots & a_{1n} \\ -a_{21} & & a_{2n} \\ -\Vdots & & \Vdots \\ -a_{n-1,1} & \Cdots & a_{n-1,n} -\end{pNiceArray}$ +On remarquera que ces commandes sont compatibles avec les commandes de \pkg{booktabs} (|\toprule|, |\midrule|, +|\bottomrule|, etc). + +\medskip +\begin{scope} +\hfuzz=10cm +\begin{BVerbatim}[baseline=c,boxwidth=8.5cm] +\begin{NiceTabular}{LSSSS}% +[code-before = \rowcolor{red!15}{1-2} \rowcolors{3}{blue!15}{}] +~emphase#\toprule@ +\Block{2-1}{Produit} \\ +\Block{1-3}{dimensions (cm)} & & & +\Block{2-1}{\rotate Prix} \\ +~emphase#\cmidrule(rl){2-4}@ + & L & l & h \\ +~emphase#\midrule@ +petit & 3 & 5.5 & 1 & 30 \\ +moyen & 5.5 & 8 & 1.5 & 50.5 \\ +premium & 8.5 & 10.5 & 2 & 80 \\ +extra & 8.5 & 10 & 1.5 & 85.5 \\ +spécial & 12 & 12 & 0.5 & 70 \\ +~emphase#\bottomrule@ +\end{NiceTabular} \end{BVerbatim} -$\begin{pNiceArray}{LCR} -a_{11} & \Cdots & a_{1n} \\ -a_{21} & & a_{2n} \\ -\Vdots & & \Vdots \\ -a_{n-1,1} & \Cdots & a_{n-1,n} -\end{pNiceArray}$ +\begin{NiceTabular}[c]{LSSSS}% +[code-before = \rowcolor{red!15}{1-2} \rowcolors{3}{blue!15}{}] +\toprule +\Block{2-1}{Produit} & +\Block{1-3}{dimensions (cm)} & & & +\Block{2-1}{\rotate Prix} \\ +\cmidrule(rl){2-4} + & L & l & h \\ +\midrule +petit & 3 & 5.5 & 1 & 30 \\ +moyen & 5.5 & 8 & 1.5 & 50.5 \\ +premium & 8.5 & 10.5 & 2 & 80 \\ +extra & 8.5 & 10 & 1.5 & 85.5 \\ +spécial & 12 & 12 & 0.5 & 70 \\ +\bottomrule +\end{NiceTabular} +\end{scope} + +\medskip +On a utilisé le type de colonne |S| de \pkg{siunitx}. +\section{La largeur des colonnes} +\label{width} -\interitem -En fait, l'environnement |{pNiceArray}| et ses variantes sont fondés sur un environnement plus général, appelé -|{NiceArrayWithDelims}|. Les deux premiers arguments obligatoires de cet environnement sont les délimiteurs gauche -et droit qui seront utilisés dans la construction de la matrice. Il est possible d'utiliser |{NiceArrayWithDelims}| -si on a besoin de délimiteurs atypiques ou asymétriques. +Dans les environnements avec un préambule explicite (comme |{NiceTabular}|, |{NiceArray}|, etc.), il est possible +de fixer la largeur d'une colonne avec les lettres classiques |w| et |W| de l'extension \pkg{array}. Dans +|{NiceTabular}|, les cases des colonnes de ce type sont composées en mode texte mais, dans |{NiceArray}|, +|{pNiceArray}|, etc., elles sont composées en mode mathématique (alors que dans |{array}| de \pkg{array}, elles +sont composées en mode texte). \medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] -$\begin{~emphase#NiceArrayWithDelims@} - {\downarrow}{\uparrow}{CCC}[margin] -1 & 2 & 3 \\ -4 & 5 & 6 \\ -7 & 8 & 9 -\end{~emphase#NiceArrayWithDelims@}$ +\begin{BVerbatim}[baseline=c,boxwidth=9cm] +\begin{NiceTabular}{~emphase#Wc{2cm}@CC}[hvlines] +Paris & New York & Madrid \\ +Berlin & London & Roma \\ +Rio & Tokyo & Oslo +\end{NiceTabular} \end{BVerbatim} -$\begin{NiceArrayWithDelims} - {\downarrow}{\uparrow}{CCC}[margin] -1 & 2 & 3 \\ -4 & 5 & 6 \\ -7 & 8 & 9 -\end{NiceArrayWithDelims}$ +\begin{NiceTabular}{Wc{2cm}CC}[hvlines] +Paris & New York & Madrid \\ +Berlin & London & Roma \\ +Rio & Tokyo & Oslo +\end{NiceTabular} -\bigskip -\subsection{Le positionnement vertical des matrices} -L'extension \pkg{nicematrix} propose aussi une option |baseline| pour la position verticale des matrices. Cette -option |baseline| prend comme valeur un entier qui indique le numéro de rangée dont la ligne de base servira de -ligne de base pour le tableau. +\bigskip +Dans les environnements de \pkg{nicematrix}, il est aussi possible de fixer la largeur \emph{minimale} de toutes +les colonnes de la matrice directement avec l'option |columns-width|. \medskip -\begin{BVerbatim}[baseline=c,boxwidth=9cm] -$A = \begin{pNiceMatrix}[~emphase#baseline=2@] -\frac{1}{\sqrt{1+p^2}} & p & 1-p \\ -1 & 1 & 1 \\ -1 & p & 1+p +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\begin{pNiceMatrix}[~emphase#columns-width = 1cm@] +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 \end{pNiceMatrix}$ \end{BVerbatim} -$A = \begin{pNiceMatrix}[baseline=2] -\frac{1}{\sqrt{1+p^2}} & p & 1-p \\ -1 & 1 & 1 \\ -1 & p & 1+p +$\begin{pNiceMatrix}[columns-width = 1cm] +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 \end{pNiceMatrix}$ +\medskip +Notez que l'espace inséré entre deux colonnes (égal à 2 |\tabcolsep| dans |{NiceTabular}| et à 2 |\arraycolsep| +dans les autres environnements) n'est pas supprimé (il est évidemment possible de le supprimer en mettant +|\tabcolsep| ou |\arraycolsep| à~$0$ avant). -\interitem -L'option |baseline| peut aussi prendre les trois valeurs spéciales |t|, |c| et |b|. Ces trois lettres peuvent aussi -être utilisées de manière absolue comme pour l'option de l'environnement |{array}| de \pkg{array}. La valeur -initiale de |baseline| est~|c|. +\bigskip +Il est possible de donner la valeur spéciale |auto| à l'option |columns-width|: toutes les colonnes du tableau +auront alors une largeur égale à la largeur de la case la plus large du tableau.\footnote{Le résultat est atteint + dès la première compilation (mais Tikz écrivant des informations dans le fichier |.aux|, un message demandant une + deuxième compilation apparaîtra).}\par\nobreak +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\begin{pNiceMatrix}[~emphase#columns-width = auto@] +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 +\end{pNiceMatrix}$ +\end{BVerbatim} +$\begin{pNiceMatrix}[columns-width = auto] +1 & 12 & -123 \\ +12 & 0 & 0 \\ +4 & 1 & 2 +\end{pNiceMatrix}$ \bigskip -Dans l'exemple suivant, on utilise l'option |t| (synonyme de |baseline=t|) immédiatement après un |\item| de liste. -On remarquera que la présence d'un |\hline| initial n'empêche pas l'alignement sur la ligne de base de la première -rangée (avec |{array}| de {array}, il faut utiliser |\firsthline|\footnote{On peut aussi utiliser |\firsthline| - avec |{NiceArray}|.}). +Sans surprise, il est possible de fixer la largeur minimale de toutes les colonnes de toutes les matrices dans une +certaine portion de document avec la commande |\NiceMatrixOptions|.\par\nobreak -\smallskip -\begin{BVerbatim}[baseline=c,boxwidth=9cm] -\begin{enumerate} -\item un item -\smallskip -\item \renewcommand{\arraystretch}{1.2} -$\begin{NiceArray}[t]{LCCCCCC} -\hline -n & 0 & 1 & 2 & 3 & 4 & 5 \\ -u_n & 1 & 2 & 4 & 8 & 16 & 32 -\hline -\end{NiceArray}$ -\end{enumerate} +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=8.5cm] +~emphase#\NiceMatrixOptions{columns-width=10mm}@ +$\begin{pNiceMatrix} +a & b \\ c & d +\end{pNiceMatrix} += +\begin{pNiceMatrix} +1 & 1245 \\ 345 & 2 +\end{pNiceMatrix}$ \end{BVerbatim} -% -\begin{minipage}{5cm} -\begin{enumerate} -\item un item -\smallskip -\item \renewcommand{\arraystretch}{1.2} -$\begin{NiceArray}[t]{LCCCCCC} -\hline -n & 0 & 1 & 2 & 3 & 4 & 5 \\ -u_n & 1 & 2 & 4 & 8 & 16 & 32 \\ -\hline -\end{NiceArray}$ -\end{enumerate} -\end{minipage} +\begin{scope} +\NiceMatrixOptions{columns-width=10mm} +$\begin{pNiceMatrix} +a & b \\ +c & d +\end{pNiceMatrix} += +\begin{pNiceMatrix} +1 & 1245 \\ +345 & 2 +\end{pNiceMatrix}$ +\end{scope} \bigskip -Il est également possible d'utiliser les outils de \pkg{booktabs}: |\toprule|, -|\bottomrule| et |\midrule|.\par\nobreak +Mais il est aussi possible de fixer une zone dans laquelle toutes les matrices auront leurs colonnes de la même +largeur, égale à la largeur de la case la plus large de toutes les matrices de la zone. Cette construction utilise +l'environnement |{NiceMatrixBlock}| avec l'option |auto-columns-width|\footnote{Pour le moment, c'est le seul + usage de l'environnement |{NiceMatrixBlock}| mais il pourrait y en avoir davantage dans le futur.}. +L'environnement |{NiceMatrixBlock}| n'a pas de rapport direct avec la commande |\Block| présentée précédemment dans +ce document (cf.~p.~\pageref{Block}). -\smallskip -\begin{BVerbatim}[baseline=c,boxwidth=9cm] -\begin{enumerate} -\item an item -\smallskip -\item -$\begin{NiceArray}[t]{LCCCCCC} -~emphase#\toprule@ -n & 0 & 1 & 2 & 3 & 4 & 5 \\ -~emphase#\midrule@ -u_n & 1 & 2 & 4 & 8 & 16 & 32 -~emphase#\bottomrule@ -\end{NiceArray}$ -\end{enumerate} +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=8.5cm] +~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@ +$\begin{array}{c} +\begin{bNiceMatrix} + 9 & 17 \\ -2 & 5 + \end{bNiceMatrix} \\ \\ +\begin{bNiceMatrix} + 1 & 1245345 \\ 345 & 2 +\end{bNiceMatrix} +\end{array}$ +~emphase#\end{NiceMatrixBlock}@ \end{BVerbatim} -\begin{minipage}{5cm} -\begin{enumerate} -\item an item -\smallskip -\item -$\begin{NiceArray}[t]{LCCCCCC} -\toprule -n & 0 & 1 & 2 & 3 & 4 & 5 \\ -\midrule -u_n & 1 & 2 & 4 & 8 & 16 & 32 \\ -\bottomrule -\end{NiceArray}$ -\end{enumerate} -\end{minipage} - +\begin{NiceMatrixBlock}[auto-columns-width] +$\begin{array}{c} +\begin{bNiceMatrix} + 9 & 17 \\ -2 & 5 + \end{bNiceMatrix} \\ \\ +\begin{bNiceMatrix} + 1 & 1245345 \\ 345 & 2 +\end{bNiceMatrix} +\end{array}$ +\end{NiceMatrixBlock} +\medskip +\textbf{Plusieurs compilations peuvent être nécessaires pour obtenir le résultat désiré.} @@ -1073,7 +1071,7 @@ Les environnements de \pkg{nicematrix} permettent de composer des rangées et de \label{exterior} Si elle est présente, la «première rangée» (extérieure) est numérotée par $0$ (et non $1$). Il en est de même pour -la «première rangée». +la «première colonne». \begin{Verbatim} $\begin{pNiceMatrix}[~emphase#first-row,last-row,first-col,last-col@,nullify-dots] @@ -1095,6 +1093,10 @@ L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ & C_1 & \Cdots & & C_4 & \end{pNiceMatrix}\] +\medskip +Les lignes pointillées ont été tracées avec les outils présentés p.~\pageref{Cdots}. + + \bigskip Il y a plusieurs remarques à formuler. % @@ -1171,16 +1173,11 @@ L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4 \\ \emph{Remarques} \begin{itemize}[beginpenalty=10000] -\item Comme on peut le voir dans l'exemple précédent, un filet horizontal (tracé avec |\hline|) ne s'étend pas -dans les colonnes extérieures et un filet vertical (spécifié par un caractère «\verb+|+» dans le préambule du -tableau) ne s'étend pas dans les rangées extérieures.\footnote{Ce dernier point n'est pas valable si on a chargé, - en plus de \pkg{nicematrix}, l'extension \pkg{arydshln}. Les extensions \pkg{nicematrix} et \pkg{arydshln} ne - sont pas parfaitement compatibles car \pkg{arydshln} redéfinit beaucoup de structures internes à \pkg{array}. Par -ailleurs, si on veut vraiment un filet qui s'étende dans la première et la dernière rangée, on peut utiliser -|!{\vline}| dans le préambule à la place de \verb+|+.} - -Si on veut définir de nouveaux spécificateurs de colonnes pour des filets (par exemple plus épais), on aura -peut-être intérêt à utiliser la commande |\OnlyMainNiceMatrix| décrite p.~\pageref{OnlyMainNiceMatrix}. +\item Comme on peut le voir dans l'exemple précédent, les filets horizontaux et verticaux ne s'étendent pas dans +les rangées et colonnes extérieures. + +Néanmoins, si on veut définir de nouveaux spécificateurs de colonnes pour des filets (par exemple plus épais), on +aura sans doute intérêt à utiliser la commande |\OnlyMainNiceMatrix| décrite p.~\pageref{OnlyMainNiceMatrix}. \item Une spécification de couleur présente dans |code-for-first-row| s'applique à une ligne pointillée tracée dans cette «première rangée» (sauf si une valeur a été donnée à |xdots/color|). Idem pour les autres. \item Sans surprise, une éventuelle option |columns-width| (décrite p.~\pageref{width}) ne s'applique pas à la @@ -1192,476 +1189,540 @@ dans cette «première rangée» (sauf si une valeur a été donnée à |xdots/c +\section{Les lignes en pointillés continues} -\section[Les lignes en pointillés pour séparer les rangées et les colonnes]{Les lignes en pointillés pour séparer les rangées\\ et les colonnes} +\label{Cdots} +À l'intérieur des environnements de l'extension \pkg{nicematrix}, de nouvelles commandes sont définies : |\Ldots|, +|\Cdots|, |\Vdots|, |\Ddots|, et |\Iddots|. Ces commandes sont conçues pour être utilisées à la place de |\dots|, +|\cdots|, |\vdots|, |\ddots| et |\iddots|.\footnote{La commande |\iddots|, définie dans \pkg{nicematrix}, est une + variante de |\ddots| avec les points allant vers le haut. Si \pkg{mathdots} est chargée, la + version de \pkg{mathdots} est utilisée. Elle correspond à la commande |\adots| de \pkg{unicode-math}.} +\newcounter{fniddots} +\setcounter{fniddots}{\thefootnote} -Dans les environnements de \pkg{nicematrix}, il est possible d'utiliser la commande |\hdottedline| (fournie -par \pkg{nicematrix}) qui est l'équivalent pour les pointillés des commandes |\hline| et |\hdashline| -(cette dernière étant une commande de \pkg{arydshln}). +\smallskip +Chacune de ces commandes doit être utilisée seule dans la case du tableau et elle trace une ligne en pointillés +entre les premières cases non vides\footnote{La définition précise de ce qui est considéré comme une «case vide» + est donnée plus loin (cf. p.~\pageref{empty-cells}).} situées de part et d'autre de la case courante. Bien +entendu, pour |\Ldots| et |\Cdots|, c'est une ligne horizontale ; pour |\Vdots|, c'est une ligne verticale et pour +|\Ddots| et |\Iddots|, ce sont des lignes diagonales. On peut changer la couleur d'une ligne avec +l'option~|color|.\footnote{Il est aussi possible de changer la couleur de toutes ces lignes pointillées avec + l'option |xdots/color| (\textsl{xdots} pour rappeler que cela s'applique à |\Cdots|, |\Ldots|, |Vdots|, etc.) : + cf. p.~\pageref{customization}). +}\par\nobreak -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=9.5cm] -\begin{pNiceMatrix} -1 & 2 & 3 & 4 & 5 \\ -~emphase#\hdottedline@ -6 & 7 & 8 & 9 & 10 \\ -11 & 12 & 13 & 14 & 15 -\end{pNiceMatrix} +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +a_1 & \Cdots & & & a_1 \\ +\Vdots & a_2 & \Cdots & & a_2 \\ + & \Vdots & \Ddots[color=red] \\ +\\ +a_1 & a_2 & & & a_n +\end{bNiceMatrix} +\end{BVerbatim} +$\begin{bNiceMatrix} +a_1 & \Cdots & & & a_1 \\ +\Vdots & a_2 & \Cdots & & a_2 \\ + & \Vdots & \Ddots[color=red] \\ +\\ +a_1 & a_2 & & & a_n +\end{bNiceMatrix}$ + + + + +\interitem +Pour représenter la matrice nulle, on peut choisir d'utiliser le codage suivant :\par\nobreak + +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +0 & \Cdots & 0 \\ +\Vdots & & \Vdots \\ +0 & \Cdots & 0 +\end{bNiceMatrix} +\end{BVerbatim} +$\begin{bNiceMatrix} +0 & \Cdots & 0 \\ +\Vdots & & \Vdots \\ +0 & \Cdots & 0 +\end{bNiceMatrix}$ + +\bigskip +On peut néanmoins souhaiter une matrice plus grande. Habituellement, dans un tel cas, les utilisateurs de LaTeX +ajoutent une nouvelle ligne et une nouvelle colonne. Il est possible d'utiliser la même méthode avec +\pkg{nicematrix} :\par\nobreak + +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +0 & \Cdots & \Cdots & 0 \\ +\Vdots & & & \Vdots \\ +\Vdots & & & \Vdots \\ +0 & \Cdots & \Cdots & 0 +\end{bNiceMatrix} \end{BVerbatim} -$\begin{pNiceMatrix} -1 & 2 & 3 & 4 & 5 \\ -\hdottedline -6 & 7 & 8 & 9 & 10 \\ -11 & 12 & 13 & 14 & 15 -\end{pNiceMatrix}$ +$\begin{bNiceMatrix} +0 & \Cdots & \Cdots & 0 \\ +\Vdots & & & \Vdots \\ +\Vdots & & & \Vdots \\ +0 & \Cdots & \Cdots & 0 +\end{bNiceMatrix}$ +\bigskip +Dans la première colonne de cet exemple, il y a deux instructions |\Vdots| mais une seule ligne en pointillés sera +tracée (il n'y a pas d'objets qui se superposent dans le fichier \textsc{pdf} résultant\footnote{Et il n'est pas + possible de tracer une ligne |\Ldots| et une ligne |\Cdots| entre les mêmes cases.}). \bigskip -Dans les environnements avec un préambule explicite (comme |{NiceArray}|, |{pNiceArray}|, etc.), il est possible de -dessiner un trait vertical en pointillés avec le spécificateur «|:|». +En fait, dans cet exemple, il aurait été possible de tracer la même matrice plus rapidement avec le codage suivant +:\par\nobreak -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=9.5cm] -\begin{pNiceArray}{CCCC~emphase#:@C} -1 & 2 & 3 & 4 & 5 \\ -6 & 7 & 8 & 9 & 10 \\ -11 & 12 & 13 & 14 & 15 -\end{pNiceArray} +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +0 & \Cdots & & 0 \\ +\Vdots & & & \\ + & & & \Vdots \\ +0 & & \Cdots & 0 +\end{bNiceMatrix} \end{BVerbatim} -$\begin{pNiceArray}{CCCC:C} -1 & 2 & 3 & 4 & 5 \\ -6 & 7 & 8 & 9 & 10 \\ -11 & 12 & 13 & 14 & 15 -\end{pNiceArray}$ +$\begin{bNiceMatrix} +0 & \Cdots & & 0 \\ +\Vdots & & & \\ + & & & \Vdots \\ +0 & & \Cdots & 0 +\end{bNiceMatrix}$ + +\bigskip +Il y a aussi d'autres moyens de changer la taille d'une matrice. On pourrait vouloir utiliser l'argument optionnel +de la commande~|\\| pour l'espacement vertical et la commande~|\hspace*| dans une case pour l'espacement +horizontal.\footnote{Dans \pkg{nicematrix}, il faut utiliser |\hspace*| et non |\hspace| car \pkg{nicematrix} + utilise \pkg{array}. Remarquons aussi que l'on peut également régler la largeur des colonnes en utilisant l'environnement |{NiceArray}| (ou + une de ses variantes) avec une colonne de type~|w| ou |W|: cf. p.~\pageref{width}} +Toutefois, une commande~|\hspace*| pourrait interférer dans la construction des lignes en pointillés. C'est +pourquoi l'extension \pkg{nicematrix} fournit une commande~|\Hspace| qui est une variante de |\hspace| transparente +pour la construction des lignes en pointillés de \pkg{nicematrix}.\par\nobreak \bigskip -Ces lignes en pointillés ne s'étendent pas dans les rangées et colonnes extérieures.\par\nobreak +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +\begin{bNiceMatrix} +0 & \Cdots & ~emphase#\Hspace*{1cm}@ & 0 \\ +\Vdots & & & \Vdots \\~emphase#[1cm]@ +0 & \Cdots & & 0 +\end{bNiceMatrix} +\end{BVerbatim} +$\begin{bNiceMatrix} +0 & \Cdots & \Hspace*{1cm} & 0 \\ +\Vdots & & & \Vdots \\[1cm] +0 & \Cdots & & 0 +\end{bNiceMatrix}$ + +\subsection{L'option nullify-dots} +Considérons la matrice suivante qui a été composée classiquement avec l'environnement |{pmatrix}| de +\pkg{amsmath}.\par\nobreak \medskip -\begin{BVerbatim}[baseline=c,boxwidth=9.5cm] -$\begin{pNiceArray}{CCC:C}% - [first-row,last-col, - code-for-first-row = \color{blue}\scriptstyle, - code-for-last-col = \color{blue}\scriptstyle ] -C_1 & C_2 & C_3 & C_4 \\ -1 & 2 & 3 & 4 & L_1 \\ -5 & 6 & 7 & 8 & L_2 \\ -9 & 10 & 11 & 12 & L_3 \\ -\hdottedline -13 & 14 & 15 & 16 & L_4 -\end{pNiceArray}$ +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$A = \begin{pmatrix} +h & i & j & k & l & m \\ +x & & & & & x +\end{pmatrix}$ \end{BVerbatim} -$\begin{pNiceArray}{CCC:C}% - [first-row,last-col, - code-for-first-row = \color{blue}\scriptstyle, - code-for-last-col = \color{blue}\scriptstyle ] -C_1 & C_2 & C_3 & C_4 \\ -1 & 2 & 3 & 4 & L_1 \\ -5 & 6 & 7 & 8 & L_2 \\ -9 & 10 & 11 & 12 & L_3 \\ -\hdottedline -13 & 14 & 15 & 16 & L_4 -\end{pNiceArray}$ - -\bigskip -Il est possible de changer dans \pkg{nicematrix} la lettre utilisée pour indiquer dans le préambule un trait -vertical en pointillés avec l'option |letter-for-dotted-lines| disponible dans |\NiceMatrixOptions|. +$A = \begin{pmatrix} +h & i & j & k & l & m \\ +x & & & & & x +\end{pmatrix}$ \bigskip -\emph{Remarque} : Quand l'extension \pkg{array} (sur laquelle s'appuie \pkg{nicematrix}) est chargée, les traits -verticaux et horizontaux que l'on insère rendent le tableau plus large ou plus long d'une quantité égale à la -largeur du trait\footnote{En fait, cela est vrai pour |\hline| et «\verb+|+» mais pas pour |\cline|.}. Avec -\pkg{nicematrix}, les lignes en pointillés tracées par |\hdottedline| et «|:|» ont le même effet. +Si nous ajoutons des instructions |\ldots| dans la seconde rangée, la géométrie de la matrice est +modifiée.\par\nobreak -\section{La largeur des colonnes} -\label{width} +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$B = \begin{pmatrix} +h & i & j & k & l & m \\ +x & \ldots & \ldots & \ldots & \ldots & x +\end{pmatrix}$ +\end{BVerbatim} +$B = \begin{pmatrix} +h & i & j & k & l & m \\ +x & \ldots & \ldots & \ldots & \ldots & x +\end{pmatrix}$ -Dans les environnements avec un préambule explicite (comme |{NiceArray}|, |{pNiceArray}|, etc.), il est possible de -fixer la largeur d'une colonne avec les lettres classiques |w| et |W| de l'extension \pkg{array}. Dans les -environnements de \pkg{nicematrix}, les cases des colonnes de ce type sont composées en mode mathématique (alors -que dans |{array}| de \pkg{array}, elles sont composées en mode texte). +\bigskip +Par défaut, avec \pkg{nicematrix}, si nous remplaçons |{pmatrix}| par |{pNiceMatrix}| et |\ldots| par |\Ldots|, la +géométrie de la matrice n'est pas changée.\par\nobreak \medskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] -$\begin{pNiceArray}{~emphase#Wc{1cm}@CC} -1 & 12 & -123 \\ -12 & 0 & 0 \\ -4 & 1 & 2 -\end{pNiceArray}$ +$C = \begin{pNiceMatrix} +h & i & j & k & l & m \\ +x & \Ldots & \Ldots & \Ldots & \Ldots & x +\end{pNiceMatrix}$ \end{BVerbatim} -$\begin{pNiceArray}{Wc{1cm}CC} -1 & 12 & -123 \\ -12 & 0 & 0 \\ -4 & 1 & 2 -\end{pNiceArray}$ - +$C = \begin{pNiceMatrix} +h & i & j & k & l & m \\ +x & \Ldots & \Ldots & \Ldots & \Ldots & x +\end{pNiceMatrix}$ \bigskip -Dans les environnements de \pkg{nicematrix}, il est aussi possible de fixer la largeur \emph{minimale} de toutes -les colonnes de la matrice directement avec l'option |columns-width|. +On pourrait toutefois préférer la géométrie de la première matrice $A$ et vouloir avoir la même géométrie avec une +ligne en pointillés continue dans la seconde rangée. C'est possible en utilisant l'option |nullify-dots| (et une +seule instruction |\Ldots| suffit).\par\nobreak \medskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] -$\begin{pNiceMatrix}[~emphase#columns-width = 1cm@] -1 & 12 & -123 \\ -12 & 0 & 0 \\ -4 & 1 & 2 +$D = \begin{pNiceMatrix}[~emphase#nullify-dots@] +h & i & j & k & l & m \\ +x & \Ldots & & & & x \end{pNiceMatrix}$ \end{BVerbatim} -$\begin{pNiceMatrix}[columns-width = 1cm] -1 & 12 & -123 \\ -12 & 0 & 0 \\ -4 & 1 & 2 +$D = \begin{pNiceMatrix}[nullify-dots] +h & i & j & k & l & m \\ +x & \Ldots & & & & x \end{pNiceMatrix}$ \medskip -Noter que l'espace inséré entre deux colonnes (égal à 2 |\arraycolsep|) n'est pas supprimé (il est évidemment -possible de le supprimer en mettant |\arraycolsep| à~$0$ avant). +L'option |nullify-dots| «smashe» les instructions |\Ldots| (et ses variantes) horizontalement mais aussi +verticalement. -\bigskip -Il est possible de donner la valeur spéciale |auto| à l'option |columns-width|: toutes les colonnes du tableau -auront alors une largeur égale à la largeur de la case la plus large du tableau.\footnote{Le résultat est atteint - dès la première compilation (mais Tikz écrivant des informations dans le fichier |.aux|, un message demandant une - deuxième compilation apparaîtra).}\par\nobreak + +\subsection{La commande \textbackslash Hdotsfor} + +Certaines personnes utilisent habituellement la commande |\hdotsfor| de l'extension \pkg{amsmath} pour tracer des +lignes en pointillés horizontales dans une matrice. Dans les environnements de \pkg{nicematrix}, il convient +d'utiliser |\Hdotsfor| à la place pour avoir les lignes en pointillés similaires à toutes celles tracées par +l'extension \pkg{nicematrix}. + +Comme avec les autres commandes de \pkg{nicematrix} (comme |\Cdots|, |\Ldots|, |\Vdots|, etc.), la ligne en +pointillés tracée par |\Hdotsfor| s'étend jusqu'au contenu des cases de part et d'autre. \medskip -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -$\begin{pNiceMatrix}[~emphase#columns-width = auto@] -1 & 12 & -123 \\ -12 & 0 & 0 \\ -4 & 1 & 2 +\begin{BVerbatim}[baseline=c,boxwidth=7cm] +$\begin{pNiceMatrix} +1 & 2 & 3 & 4 & 5 \\ +1 & ~emphase#\Hdotsfor{3}@ & 5 \\ +1 & 2 & 3 & 4 & 5 \\ +1 & 2 & 3 & 4 & 5 \end{pNiceMatrix}$ \end{BVerbatim} -$\begin{pNiceMatrix}[columns-width = auto] -1 & 12 & -123 \\ -12 & 0 & 0 \\ -4 & 1 & 2 +$\begin{pNiceMatrix} +1 & 2 & 3 & 4 & 5 \\ +1 & \Hdotsfor{3} & 5 \\ +1 & 2 & 3 & 4 & 5 \\ +1 & 2 & 3 & 4 & 5 \end{pNiceMatrix}$ \bigskip -Sans surprise, il est possible de fixer la largeur minimale de toutes les colonnes de toutes les matrices dans une -certaine portion de document avec la commande |\NiceMatrixOptions|.\par\nobreak +Néanmoins, si ces cases sont vides, la ligne en pointillés s'étend seulement dans les cases spécifiées par +l'argument de |\Hdotsfor| (par conception). \medskip -\begin{BVerbatim}[baseline=c,boxwidth=8.5cm] -~emphase#\NiceMatrixOptions{columns-width=10mm}@ +\begin{BVerbatim}[baseline=c,boxwidth=7cm] $\begin{pNiceMatrix} -a & b \\ c & d -\end{pNiceMatrix} -= -\begin{pNiceMatrix} -1 & 1245 \\ 345 & 2 +1 & 2 & 3 & 4 & 5 \\ + & ~emphase#\Hdotsfor{3}@ \\ +1 & 2 & 3 & 4 & 5 \\ +1 & 2 & 3 & 4 & 5 \end{pNiceMatrix}$ \end{BVerbatim} -\begin{scope} -\NiceMatrixOptions{columns-width=10mm} $\begin{pNiceMatrix} -a & b \\ -c & d -\end{pNiceMatrix} -= -\begin{pNiceMatrix} -1 & 1245 \\ -345 & 2 +1 & 2 & 3 & 4 & 5 \\ + & \Hdotsfor{3} \\ +1 & 2 & 3 & 4 & 5 \\ +1 & 2 & 3 & 4 & 5 \end{pNiceMatrix}$ + +\medskip +Remarque : Contrairement à la commande |\hdotsfor| de \pkg{amsmath}, la commande |\Hdotsfor| est utilisable lorsque +l'extension \pkg{colortbl} est chargée (mais vous risquez d'avoir des problèmes si vous utilisez |\rowcolor| sur la +même rangée que |\Hdotsfor|). + +\subsection{Comment créer les lignes en pointillés de manière transparente} + +L'extension \pkg{nicematrix} fournit une option appelée |transparent| qui permet d'utiliser du code existant de +manière transparente dans les environnements de l'\pkg{amsmath} : |{matrix}|, |{pmatrix}|, etc. En fait, cette +option est un alias pour la conjonction de deux options : |renew-dots| et |renew-matrix|.\footnote{Comme toutes les + autres options, les options |renew-dots|, |renew-matrix| et |transparent| peuvent être fixées avec la commande + |\NiceMatrixOptions|, mais elles peuvent aussi être passées en option du |\usepackage| (ce sont les trois + seules).} + +\smallskip + +\begin{itemize} +\item L'option |renew-dots|\par\nobreak + +Avec cette option, les commandes |\ldots|, |\cdots|, |\vdots|, |\ddots|, |\iddots|\footnotemark[\thefniddots] et +|\hdotsfor| sont redéfinies dans les environnements de \pkg{nicematrix} et agissent alors comme |\Ldots|, |\Cdots|, +|\Vdots|, |\Ddots|, |\Iddots| et |\Hdotsfor| ; la commande |\dots| (points de suspension «automatiques» de +|amsmath|) est aussi redéfinie et se comporte comme |\Ldots|. + +\item L'option |renew-matrix|\par\nobreak + +Avec cette option, l'environnement |{matrix}| est redéfini et se comporte comme |{NiceMatrix}| et il en est de même +pour les cinq variantes. +\end{itemize} + +\bigskip +Par conséquent, avec l'option |transparent|, un code classique donne directement le résultat fourni par +\pkg{nicematrix}.\par\nobreak + +\bigskip +\begin{scope} +\NiceMatrixOptions{transparent} +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +~emphase#\NiceMatrixOptions{transparent}@ +\begin{pmatrix} +1 & \cdots & \cdots & 1 \\ +0 & \ddots & & \vdots \\ +\vdots & \ddots & \ddots & \vdots \\ +0 & \cdots & 0 & 1 +\end{pmatrix} +\end{BVerbatim} +$\begin{pmatrix} +1 & \cdots & \cdots & 1 \\ +0 & \ddots & & \vdots \\ +\vdots & \ddots & \ddots & \vdots \\ +0 & \cdots & 0 & 1 +\end{pmatrix}$ \end{scope} -\bigskip -Mais il est aussi possible de fixer une zone dans laquelle toutes les matrices auront leurs colonnes de la même -largeur, égale à la largeur de la case la plus large de toutes les matrices de la zone. Cette construction utilise -l'environnement |{NiceMatrixBlock}| avec l'option |auto-columns-width|\footnote{Pour le moment, c'est le seul - usage de l'environnement |{NiceMatrixBlock}| mais il pourrait y en avoir davantage dans le futur.}. -L'environnement |{NiceMatrixBlock}| n'a pas de rapport direct avec la commande |\Block| présentée juste ci-dessous -(cf.~p.~\pageref{Block}). +\subsection{Les labels des lignes en pointillés} -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=8.5cm] -~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@ -$\begin{pNiceMatrix} -a & b \\ c & d -\end{pNiceMatrix} -= -\begin{pNiceMatrix} -1 & 1245 \\ 345 & 2 -\end{pNiceMatrix}$ -~emphase#\end{NiceMatrixBlock}@ +Les commandes |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| et |\Hdotsfor| (ainsi que la commande |\line| dans +le |code-after| décrite p.~\pageref{line-in-code-after}) peuvent en fait prendre deux arguments optionnels +spécifiés par les caractères |_| et |^| pour des labels situés au-dessous et au-dessus de la ligne. Les arguments +sont composés en mode mathématique avec |\scriptstyle|. + +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\begin{bNiceMatrix} +1 & \hspace*{1cm} & 0 \\[8mm] + & ~emphase#\Ddots^{n \text{ times}}@ & \\ +0 & & 1 +\end{bNiceMatrix}$ \end{BVerbatim} -\begin{NiceMatrixBlock}[auto-columns-width] -$\begin{pNiceMatrix} - a & b \\ c & d - \end{pNiceMatrix} -= - \begin{pNiceMatrix} - 1 & 1245 \\ 345 & 2 -\end{pNiceMatrix}$ -\end{NiceMatrixBlock} +$\begin{bNiceMatrix} +1 & \hspace*{1cm} & 0 \\[8mm] + & \Ddots^{n \text{ times}} & \\ +0 & & 1 +\end{bNiceMatrix}$ -\medskip -\textbf{Plusieurs compilations peuvent être nécessaires pour obtenir le résultat désiré.} +\subsection{Personnalisation des lignes en pointillés} -\section{Les matrices par blocs} -\label{Block} +\label{customization} +Les lignes pointillées tracées par |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| et |\Hdotsfor| (ainsi que par la +commande |\line| dans le |code-after| décrite p.~\pageref{line-in-code-after}) peuvent être +paramétrées par trois options (que l'on met entre crochets après la commande) : +% +\begin{itemize} +\item |color| ; +\item |shorten| ; +\item |line-style|. +\end{itemize} + +Ces options peuvent aussi être fixées avec |\NiceMatrixOptions| ou bien au niveau d'un environnement mais elles +doivent alors être préfixées par |xdots|, ce qui fait que leurs noms deviennent : +% +\begin{itemize} +\item |xdots/color| ; +\item |xdots/shorten| ; +\item |xdots/line-style|. +\end{itemize} +% +Pour la clarté, dans la suite, on utilisera ces noms-là. -Cette partie, qui introduit une commande |\Block|, n'a pas de rapport direct avec l'environnement -|{NiceMatrixBlock}| présenté dans la section précédente. +\bigskip +\textbf{L'option xdots/color}\par\nobreak \smallskip -Dans les environnements de \pkg{nicematrix}, on peut utiliser la commande |\Block| pour placer un élément au centre -d'un rectangle de cases fusionnées. +L'option |xdots/color| indique bien entendu la couleur de la ligne tracée. On remarquera néanmoins que les lignes +tracées dans les rangées et colonnes extérieures (décrites plus loin) bénificient d'un régime spécial : cf. +p.~\pageref{exterior}. -La commande |\Block| doit être utilisée dans la case supérieure gauche du bloc avec deux arguments. Le premier -argument est la taille de ce bloc avec la syntaxe $i$-$j$ où $i$ est le nombre de rangées et $j$ le nombre de -colonnes du bloc. Le deuxième argument, est, sans surprise, le contenu du bloc (en mode mathématique). Un nœud Tikz -correspondant à l'ensemble des cases fusionnées est créé sous le nom «$i$-$j$-block» où \textsl{nom} est le -nom donné au tableau. Si on a demandé la création des nœuds |medium|, alors un nœud de ce type est aussi créé pour -ce bloc avec un nom suffixé par |-medium|. -\medskip -Dans les exemples qui suivent, on utilise la commande |\arrayrulecolor| de \pkg{colortbl}. +\bigskip +\textbf{L'option xdots/shorten}\par\nobreak + +\smallskip +L'option |xdots/shorten| indique la marge qui est laissée aux deux extrémités de la ligne. Le nom s'inspire des options +«|shorten >|» et «|shorten <|» de Tikz, mais il faut remarquer que \pkg{nicematrix} ne propose que |xdots/shorten|. +La valeur initiale de ce paramètre est de $0.3$~em (il est conseillé d'utiliser une unité de mesure dépendante de +la fonte courante). -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=10.6cm] -\arrayrulecolor{blue} -$\begin{bNiceArray}{CCC|C}[margin] -~emphase#\Block{3-3}{A}@ & & & 0 \\ -& \hspace*{1cm} & & \Vdots \\ -& & & 0 \\ -\hline -0 & \Cdots& 0 & 0 -\end{bNiceArray}$ -\arrayrulecolor{black} -\end{BVerbatim} -\begin{scope} -\arrayrulecolor{blue} -$\begin{bNiceArray}{CCC|C}[margin] -\Block{3-3}{A} & & & 0 \\ -& \hspace*{1cm} & & \Vdots \\ -& & & 0 \\ -\hline -0 & \Cdots& 0 & 0 -\end{bNiceArray}$ -\arrayrulecolor{black} -\end{scope} \bigskip -On peut souhaiter agrandir la taille du «$A$» placé dans le bloc de l'exemple précédent. Comme il est composé en -mode mathématique, on ne peut pas directement utiliser une commande comme |\large|, |\Large| ou |\LARGE|. C'est -pourquoi une option à mettre entre chevrons est proposée par |\Block| pour spécifier du code LaTeX qui sera inséré -\emph{avant} le début du mode mathématique. +\textbf{L'option xdots/line-style}\par\nobreak -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=10.6cm] -\arrayrulecolor{blue} -$\begin{bNiceArray}{CCC|C}[margin] -\Block{3-3}~emphase#<\Large>@{A} & & & 0 \\ -& \hspace*{1cm} & & \Vdots \\ -& & & 0 \\ -\hline -0 & \Cdots& 0 & 0 -\end{bNiceArray}$ -\arrayrulecolor{black} +\smallskip +Il faut savoir que, par défaut, les lignes de Tikz tracées avec le paramètre |dotted| sont composées de points +carrés et non pas ronds.\footnote{La raison de départ est que le format \textsc{pdf} comporte un système de description + de lignes en tiretés, qui, puisqu'il est incorporé dans le \textsc{pdf}, est affiché très rapidement par les + lecteurs de \textsc{pdf}. Il est facile à partir de ce type de ligne de créer des lignes de points carrés alors + qu'une ligne de points ronds doit être construite explicitement point par point.} + +\begin{BVerbatim}[baseline=c,boxwidth=9cm] +\tikz \draw [dotted] (0,0) -- (5,0) ; \end{BVerbatim} -\begin{scope} -\arrayrulecolor{blue} -$\begin{bNiceArray}{CCC|C}[margin] -\Block{3-3}<\Large>{A} & & & 0 \\ -& \hspace*{1cm} & & \Vdots \\ -& & & 0 \\ -\hline -0 & \Cdots& 0 & 0 -\end{bNiceArray}$ -\arrayrulecolor{black} -\end{scope} +\tikz \draw [dotted] (0,0) -- (5,0) ; + +\bigskip +Voulant proposer des lignes avec des points ronds dans le style de celui de |\ldots| (au moins celui des fontes +\emph{Computer Modern}), l'extension \pkg{nicematrix} contient en interne son propre système de ligne en pointillés +(qui, au passage, n'utilise que \pkg{pgf} et non \pkg{tikz}). Ce style est appelé le style |standard|. Cette valeur +est la valeur initiale du paramètre |xdots/line-style|. + +\bigskip +Néanmoins (quand Tikz est chargé), on peut utiliser pour |xdots/line-style| n'importe quel style proposé par Tikz, +c'est-à-dire n'importe quelle suite d'options Tikz applicables à un chemin (à l'exception de «|color|», +«|shorten >|» et «|shorten <|»). +\medskip +Voici par exemple une matrice tridiagonale avec le style |loosely dotted| :\par\nobreak \medskip -Pour des raisons techniques, il n'est pas possible d'écrire |\Block{|$i$|-|$j$|}{<}| -(mais on peut écrire |\Block{|$i$|-|$j$|}<>{<}| avec le résultat attendu). +\begin{BVerbatim}[baseline=c] +$\begin{pNiceMatrix}[nullify-dots,~emphase#xdots/line-style=loosely dotted@] +a & b & 0 & & \Cdots & 0 \\ +b & a & b & \Ddots & & \Vdots \\ +0 & b & a & \Ddots & & \\ + & \Ddots & \Ddots & \Ddots & & 0 \\ +\Vdots & & & & & b \\ +0 & \Cdots & & 0 & b & a +\end{pNiceMatrix}$ +\end{BVerbatim} -\section{Les couleurs des rangées et des colonnes} +\[\begin{pNiceMatrix}[nullify-dots,xdots/line-style=loosely dotted] +a & b & 0 & & \Cdots & 0 \\ +b & a & b & \Ddots & & \Vdots \\ +0 & b & a & \Ddots & & \\ + & \Ddots & \Ddots & \Ddots & & 0 \\ +\Vdots & & & & & b \\ +0 & \Cdots & & 0 & b & a +\end{pNiceMatrix}\] -L'extension \pkg{colortbl} permet de colorier des cellules, des rangées ou des colonnes d'un tableau. Néanmoins, -l'affichage du \textsc{pdf} résultant n'est pas toujours parfait, en particulier quand on utilise également des -filets. Dans certains lecteurs de \textsc{pdf}, des filets verticaux semblent disparaître. De fines lignes -blanches peuvent également apparaître. -\medskip -La version 4.0 de \pkg{nicematrix} propose des outils similaires qui ne présentent pas ces inconvénients. Elle -propose une option |code-before| pour du code qui sera exécuté \emph{avant} le tracé du tableau. Dans ce -|code-before|, de nouvelles commandes sont disponibles : |\cellcolor|, |\rectanglecolor|, |\rowcolor|, -|\columncolor|, |\rowcolors| et |\chessboardcolors|. +\subsection{Les lignes pointillées et la clé hvlines} -\medskip -\begin{itemize} -\item La commande |\cellcolor| tient son nom de la commande |\cellcolor| de \pkg{colortbl}. +\label{dotted-and-hvlines} -Elle prend en arguments une couleur et une liste de cellules sous le format $i$-$j$ où $i$ est le numéro de ligne -et $j$ le numéro de colonne. +On a dit (cf. p. \pageref{hvlines}) que la clé |hvlines| trace tous les filets horizontaux et verticaux, exceptés +dans les blocs. En fait, avec cette clé, les filets ne sont pas non plus tracés dans les blocs virtuels délimités +par des cases reliées par des lignes pointillées. \medskip -\begin{scope} -\hfuzz=10cm -\begin{BVerbatim}[boxwidth=10cm,baseline=c] -\begin{NiceTabular}{|C|C|C|}[code-before = ~emphase#\cellcolor{red!15}{3-1,2-2,1-3}@] -\hline -a & b & c \\ \hline -e & f & g \\ \hline -h & i & j \\ \hline -\end{NiceTabular} +\begin{BVerbatim}[baseline=c,boxwidth=11cm] +\NiceMatrixOptions{nullify-dots} +$\begin{pNiceMatrix}[rules/color=gray,~emphase#hvlines@,margin] +0 & \Cdots & & & & 0 \\ +1 & \Cdots & & & 1 & 2 \\ +0 & \Ddots & & & \Vdots & \Vdots \\ +\Vdots & \Ddots & & & & \\ + & & & & & \\ +0 & \Cdots & & 0 & 1 & 2 \\ +\end{pNiceMatrix}$ \end{BVerbatim} -\begin{NiceTabular}{|C|C|C|}[code-before = \cellcolor{red!15}{3-1,2-2,1-3}] -\hline -a & b & c \\ \hline -e & f & g \\ \hline -h & i & j \\ \hline -\end{NiceTabular} +\begin{scope} +\NiceMatrixOptions{nullify-dots} +$\begin{pNiceMatrix}[rules/color=gray,hvlines,margin] +0 & \Cdots & & & & 0 \\ +1 & \Cdots & & & 1 & 2 \\ +0 & \Ddots & & & \Vdots & \Vdots \\ +\Vdots & \Ddots & & & & \\ + & & & & & \\ +0 & \Cdots & & 0 & 1 & 2 \\ +\end{pNiceMatrix}$ \end{scope} -\bigskip -\item La commande |\rectanglecolor| prend trois arguments. Le premier est la couleur, les deux suivants fournissent -la case en haut à gauche et la case en bas à droite du rectangle. -\medskip -\begin{scope} -\hfuzz=10cm -\begin{BVerbatim}[boxwidth=10cm,baseline=c] -\begin{NiceTabular}{|C|C|C|}[code-before = ~emphase#\rectanglecolor{red!15}{2-2}{3-3}@] -\hline -a & b & c \\ \hline -e & f & g \\ \hline -h & i & j \\ \hline -\end{NiceTabular} -\end{BVerbatim} -\begin{NiceTabular}{|C|C|C|}[code-before = \rectanglecolor{red!15}{2-2}{3-3}] -\hline -a & b & c \\ \hline -e & f & g \\ \hline -h & i & j \\ \hline -\end{NiceTabular} -\end{scope} +\section{Le code-after} +\label{code-after} -\bigskip -\item La commande |\rowcolor| doit son nom à la commande |\rowcolor| de \pkg{colortbl}. Son premier argument est la -couleur et le deuxième est une liste de numéros de rangées ou bien d'intervalles de rangées sous la forme -$a$-$b$ (un intervalle de la forme $a$- représente toutes les rangées à partir de la rangée~$a$). +L'option |code-after| peut être utilisée pour indiquer du code qui sera exécuté après la construction de la +matrice.\footnote{Il existe aussi une clé |code-before| décrite p.~\pageref{code-before}.} -\medskip +Une commande spéciale, nommée |\line| est disponible pour tracer directement des lignes en pointillés entre les +cases. Elle prend deux arguments correspondant aux deux cases à relier, chacun de la forme $i$-$j$ où $i$ est le +numéro de ligne et $j$ est le numéro de colonne. Elle peut par exemple être utilisée pour tracer une ligne entre +deux cases adjacentes comme dans l'exemple suivant. +\label{line-in-code-after} -\begin{scope} -\hfuzz=10cm -\begin{BVerbatim}[boxwidth=9cm,baseline=c] -$\begin{NiceArray}{LLL}[hvlines, ~emphase#code-before = \rowcolor{red!15}{1,3-5,8-}@] -a_1 & b_1 & c_1 \\ -a_2 & b_2 & c_2 \\ -a_3 & b_3 & c_3 \\ -a_4 & b_4 & c_4 \\ -a_5 & b_5 & c_5 \\ -a_6 & b_6 & c_6 \\ -a_7 & b_7 & c_7 \\ -a_8 & b_8 & c_8 \\ -a_9 & b_9 & c_9 \\ -a_{10} & b_{10} & c_{10} \\ -\end{NiceArray}$ -\end{BVerbatim} -% -$\begin{NiceArray}{LLL}% -[baseline=4,hvlines, code-before = \rowcolor{red!15}{1,3-5,8-}] -a_1 & b_1 & c_1 \\ -a_2 & b_2 & c_2 \\ -a_3 & b_3 & c_3 \\ -a_4 & b_4 & c_4 \\ -a_5 & b_5 & c_5 \\ -a_6 & b_6 & c_6 \\ -a_7 & b_7 & c_7 \\ -a_8 & b_8 & c_8 \\ -a_9 & b_9 & c_9 \\ -a_{10} & b_{10} & c_{10} \\ -\end{NiceArray}$ +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] +\NiceMatrixOptions{xdots/shorten = 0.6 em} +\begin{pNiceMatrix}[~emphase#code-after=\line{2-2}{3-3}@] +I & 0 & \Cdots &0 \\ +0 & I & \Ddots &\Vdots\\ +\Vdots &\Ddots & I &0 \\ +0 &\Cdots & 0 &I +\end{pNiceMatrix} +\end{BVerbatim} +\begin{scope} +\NiceMatrixOptions{xdots/shorten = 0.6 em} +$\begin{pNiceMatrix}[code-after=\line{2-2}{3-3}] +I & 0 & \Cdots &0 \\ +0 & I & \Ddots &\Vdots\\ +\Vdots &\Ddots & I &0 \\ +0 &\Cdots & 0 &I +\end{pNiceMatrix}$ \end{scope} +\medskip +Pour améliorer la lisibilité du code, une syntaxe alternative est proposée : on peut spécifier les instructions du +|code-after| à la fin de l'environnement, après le mot-clé |\CodeAfter|. Pour un exemple, voir page +\pageref{exemple-CodeAfter}. -\bigskip -\item La commande |\columncolor| doit son nom à la commande |\columncolor| de \pkg{colortbl}. Sa syntaxe est -similaire à celle de |\rowcolor|. -\bigskip -\item La commande |\rowcolors| (avec un \emph{s}) doit son nom à la commande |\rowcolors| de \pkg{xcolor}. Le -\emph{s} rappelle qu'il y a deux couleurs. Elle colorie alternativement les rangées avec les deux couleurs à partir -de la rangée dont le numéro est donné en premier argument. -\medskip +\section{Autres fonctionnalités} -\begin{scope} -\hfuzz=10cm -\begin{BVerbatim}[baseline=c,boxwidth=9cm] -\begin{NiceTabular}{LR}% -[~emphase#code-before = \rowcolor{red!15}{1} \rowcolors{3}{blue!10}{}@] -\toprule -Ville & habitants \\ -\midrule -Pau & 80000 \\ -Paris & 2000000 \\ -Toulouse & 700000 \\ -Reims & 40000 \\ -\bottomrule -\end{NiceTabular} -\end{BVerbatim} -\begin{NiceTabular}{LR}[code-before =\rowcolor{red!15}{1} \rowcolors{3}{blue!10}{}] -\toprule -Ville & habitants \\ -\midrule -Pau & 80000 \\ -Paris & 2000000 \\ -Toulouse & 700000 \\ -Reims & 40000 \\ -\bottomrule -\end{NiceTabular} -\end{scope} -\bigskip -\item La commande |\chessboardcolors| prend en arguments deux couleurs et colorie les cellules en quinconces avec -les deux couleurs. +\subsection{Utilisation du type de colonne S de siunitx} + +Si l'extension \pkg{siunitx} est chargée (avant ou après \pkg{nicematrix}), il est possible d'utiliser les colonnes +de type |S| de \pkg{siunitx} dans les environnements de \pkg{nicematrix}. L'implémentation n'utilise explicitement +aucune macro privée de \pkg{siunitx}. \medskip -\begin{scope} -\hfuzz=10cm -\begin{BVerbatim}[baseline=c,boxwidth=9cm] -$\begin{pNiceMatrix}[R,margin, ~emphase#code-before=\chessboardcolors{red!15}{blue!15}@] -1 & -1 & 1 \\ --1 & 1 & -1 \\ -1 & -1 & 1 -\end{pNiceMatrix}$ +\begin{BVerbatim}[baseline = c, boxwidth = 10.5cm] +$\begin{pNiceArray}{~emphase#S@CWc{1cm}C}[nullify-dots,first-row] +{C_1} & \Cdots & & C_n \\ +2.3 & 0 & \Cdots & 0 \\ +12.4 & \Vdots & & \Vdots \\ +1.45 \\ +7.2 & 0 & \Cdots & 0 +\end{pNiceArray}$ \end{BVerbatim} -$\begin{pNiceMatrix}% -[baseline=1, R, margin, code-before = \chessboardcolors{red!15}{blue!15}] -1 & -1 & 1 \\ --1 & 1 & -1 \\ -1 & -1 & 1 -\end{pNiceMatrix}$ -\end{scope} +$\begin{pNiceArray}{SCWc{1cm}C}[nullify-dots,first-row] +{C_1} & \Cdots & & C_n \\ +2.3 & 0 & \Cdots & 0 \\ +12.4 & \Vdots & & \Vdots \\ +1.45 \\ +7.2 & 0 & \Cdots & 0 +\end{pNiceArray}$ -\end{itemize} +\medskip +En revanche, les colonnes |d| de l'extension \pkg{dcolumn} ne sont pas prises en charge par \pkg{nicematrix}. -\section{Fonctionnalités avancées} +\subsection{Option d'alignement dans \{NiceMatrix\}} -\subsection{Option d'alignement dans NiceMatrix} +\label{key-R} Les environnements sans préambule (|{NiceMatrix}|, |{pNiceMatrix}|, |{bNiceMatrix}|, etc.) proposent les options -|l| et |r| (possédant |L| et |R| comme alias) qui imposent des colonnes alignées à gauche ou à -droite.\footnote{Cela reprend une partie des fonctionnalités proposées par les environnements |{pmatrix*}|, - |{bmatrix*}|, etc. de \pkg{mathtools}.} +|l| et |r| (possédant |L| et |R| comme alias) qui imposent des colonnes alignées à gauche ou à droite. \medskip \begin{BVerbatim}[baseline=c,boxwidth=10cm] @@ -1675,7 +1736,10 @@ $\begin{bNiceMatrix}[R] \sin x & \cos x \end{bNiceMatrix}$ - +\medskip +Il existe aussi l'option |S| qui impose que toutes les colonnes soient des colonnes |S| de \pkg{siunitx} (si cette +extension est chargée).\footnote{Cela reprend une partie des fonctionnalités proposées par les environnements |{pmatrix*}|, + |{bmatrix*}|, etc. de \pkg{mathtools}.} \subsection{La commande \textbackslash rotate} @@ -1790,8 +1854,9 @@ numéro de la rangée courante et le numéro de la colonne courante\footnote{On Bien entendu, l'utilisateur ne doit pas modifier les valeurs de ces compteurs qui sont utilisés en interne par \pkg{nicematrix}. -Dans le |code-after| (cf. p. \pageref{code-after}), |iRow| représente le nombre total de rangées (hors éventuelles -rangées extérieures) et |jCol| le nombre total de colonnes (hors potentielles colonnes extérieures). +Dans le |code-before| (cf. p. \pageref{code-before}) et dans le |code-after| (cf. p. \pageref{code-after}), |iRow| +représente le nombre total de rangées (hors éventuelles rangées extérieures) et |jCol| le nombre total de colonnes +(hors potentielles colonnes extérieures). \medskip \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] @@ -1818,8 +1883,8 @@ $\begin{pNiceMatrix}[first-row, \medskip Si des compteurs LaTeX nommés |iRow| ou |jCol| sont créés dans le document par d'autres extensions que -\pkg{nicematrix} (ou tout simplement par l'utilisateur), ces compteurs sont masqués dans les environnements de -\pkg{nicematrix}. +\pkg{nicematrix} (ou tout simplement par l'utilisateur final), ces compteurs sont masqués dans les environnements +de \pkg{nicematrix}. \bigskip @@ -1838,164 +1903,458 @@ $C = ~emphase#\pAutoNiceMatrix@{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$ \end{Verbatim} -$C = \pAutoNiceMatrix{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$ +\[C = \pAutoNiceMatrix{3-3}{C_{\arabic{iRow},\arabic{jCol}}}\] + + + +\subsection{L'option light-syntax} + +\label{light-syntax} + +L'option |light-syntax| (inspirée de l'extension \pkg{spalign}) permet d'alléger la saisie des matrices, ainsi que +leur lisibilité dans le source TeX. Lorsque cette option est activée, on doit utiliser le point-virgule comme +marqueur de fin de rangée et séparer les colonnes par des espaces ou des tabulations. On remarquera toutefois que, +comme souvent dans le monde TeX, les espaces après les séquences de contrôle ne sont pas comptées et que les +éléments entre accolades sont considérés comme un tout. + + +\medskip +\begin{scope} +\begin{BVerbatim}[baseline=c,boxwidth=10cm] +$\begin{bNiceMatrix}[~emphase#light-syntax@,first-row,first-col] +{} a b ; +a 2\cos a {\cos a + \cos b} ; +b \cos a+\cos b { 2 \cos b } +\end{bNiceMatrix}$ +\end{BVerbatim} +\end{scope} +% +$\begin{bNiceMatrix}[light-syntax,first-row,first-col] +{} a b ; +a 2\cos a {\cos a + \cos b} ; +b \cos a+\cos b { 2 \cos b } +\end{bNiceMatrix}$ + +\medskip +On peut changer le caractère utilisé pour indiquer les fins de rangées avec l'option |end-of-row|. Comme dit +précédemment, la valeur initiale de ce paramètre est un point-virgule. + +\medskip +Lorsque l'option |light-syntax| est utilisée, il n'est pas possible de mettre d'éléments en verbatim (avec par +exemple la commande |\verb|) dans les cases du tableau.\footnote{La raison en est que lorsque l'option + |light-syntax| est utilisée, le contenu complet de l'environnement est chargé comme un argument de commande TeX. + L'environnement ne se comporte plus comme un «vrai» environnement de LaTeX qui se contente d'insérer des + commandes avant et après.} + +\subsection{L'environnement \{NiceArrayWithDelims\}} + +En fait, l'environnement |{pNiceArray}| et ses variantes sont fondés sur un environnement plus général, appelé +|{NiceArrayWithDelims}|. Les deux premiers arguments obligatoires de cet environnement sont les délimiteurs gauche +et droit qui seront utilisés dans la construction de la matrice. Il est possible d'utiliser |{NiceArrayWithDelims}| +si on a besoin de délimiteurs atypiques ou asymétriques. + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] +$\begin{~emphase#NiceArrayWithDelims@} + {\downarrow}{\uparrow}{CCC}[margin] +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 +\end{~emphase#NiceArrayWithDelims@}$ +\end{BVerbatim} +% +$\begin{NiceArrayWithDelims} + {\downarrow}{\uparrow}{CCC}[margin] +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 +\end{NiceArrayWithDelims}$ + + + + +\section{Utilisation de Tikz avec nicematrix} + +\label{name} + +\subsection{Les nœuds correspondant aux contenus des cases} + +L'extension \pkg{nicematrix} crée un nœud PGF-Tikz pour chaque case (non vide) du tableau considéré. Ces nœuds sont +utilisés, entre autres, pour tracer les lignes en pointillés entre les cases du tableau. + +\smallskip +Tous les nœuds du document doivent avoir des noms deux à deux distincts et le nom de ces nœuds doit donc faire +intervenir le numéro de l'environnement courant. Les environnements créés par \pkg{nicematrix} sont en effet +numérotés par un compteur global interne. + +\smallskip +Si l'environnement concerné a le numéro $n$, alors le nœud de la rangée~$i$ et de la colonne~$j$ a pour nom +|nm-|$n$|-|$i$|-|$j$. + +\smallskip +La commande |\NiceMatrixLastEnv| donne le numéro du dernier de ces environnements (pour LaTeX, il s'agit d'une +commande — complètement développable — et non d'un compteur). + +\smallskip +Il est néanmoins recommandé de passer plutôt par la clé |name|. Celle-ci permet de donner un nom à l'environnement. +Une fois l'environnement nommé, les nœuds sont accessibles à travers les noms «\textsl{nom}-$i$-$j$» où +\textsl{nom} est le nom donné au tableau et $i$ et $j$ les numéros de rangée et de colonne de la case considérée. +On peut les utiliser avec \textsc{pgf} mais l'utilisateur final préférera sans doute utiliser Tikz (qui est une +sur-couche de \textsc{pgf}). Il faut néanmoins se souvenir que \pkg{nicematrix} ne charge pas Tikz par défault. + +\bigskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] +$\begin{pNiceMatrix}[name=~emphase#ma-matrice@] +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 +\end{pNiceMatrix}$ +\tikz[remember picture,overlay] + \draw ~emphase#(ma-matrice-2-2)@ circle (2mm) ; +\end{BVerbatim} +$\begin{pNiceMatrix}[name=ma-matrice] +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 +\end{pNiceMatrix}$ +\tikz[remember picture,overlay] + \draw (ma-matrice-2-2) circle (2mm) ; + +\medskip +Ne pas oublier les options |remember picture| et |overlay|. + + +\bigskip +Dans le |code-after|, et si Tikz est chargé, les choses sont plus simples. On peut (et on doit) désigner les nœuds +sous la forme $i$-$j$ : il n'y a pas besoin de préciser l'environnement qui est évidemment l'environnement courant. + + +\medskip +\begin{BVerbatim}[baseline=c,boxwidth=11cm] +$\begin{pNiceMatrix} +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 +\CodeAfter +\tikz \draw ~emphase#(2-2)@ circle (2mm) ; +\end{pNiceMatrix}$ +\end{BVerbatim} +$\begin{pNiceMatrix} +1 & 2 & 3 \\ +4 & 5 & 6 \\ +7 & 8 & 9 +\CodeAfter +\tikz \draw (2-2) circle (2mm) ; +\end{pNiceMatrix}$ + + + +\bigskip +Dans l'exemple suivant, nous avons surligné tous nœuds de la matrice (on explique plus loin la technique utilisée : +cf. p. \pageref{highlight}). + +\[\begin{pNiceMatrix} +a & a + b & a + b + c \\ +a & a & a + b \\ +a & a & a +\CodeAfter +\begin{tikzpicture}[ + every node/.style = + { + blend mode = multiply, + inner sep = 0 pt , + fill = red!15 + } + ] +\node [fit = (1-1)] {} ; +\node [fit = (1-3)] {} ; +\node [fit = (2-2)] {} ; +\node [fit = (3-1)] {} ; +\node [fit = (3-3)] {} ; +\node [fit = (1-2)] {} ; +\node [fit = (2-1)] {} ; +\node [fit = (2-3)] {} ; +\node [fit = (3-2)] {} ; +\end{tikzpicture} +\end{pNiceMatrix}\] + + +\subsection{Les «nœuds moyens» et les «nœuds larges»} + + +En fait, l'extension \pkg{nicematrix} peut créer deux séries de nœuds supplémentaires (\emph{extra nodes} en +anglais) : les «nœuds moyens» (\emph{medium nodes} en anglais) et les «nœuds larges» (\emph{large nodes} en +anglais). Les premiers sont créés avec l'option |create-medium-nodes| et les seconds avec l'option +|create-large-nodes|.\footnote{Il existe aussi l'option |create-extra-nodes| qui est un alias pour la conjonction +de |create-medium-nodes| et |create-large-nodes|.} + +\medskip +Ces nœuds ne sont pas utilisés par défault par \pkg{nicematrix}. + +\medskip +Les noms des «nœuds moyens» s'obtiennent en ajoutant le suffixe «|-medium|» au nom des nœuds normaux. Dans +l'exemple suivant, on a surligné tous les «nœuds moyens». Nous considérons que cet exemple se suffit à lui-même +comme définition de ces nœuds. +\[\begin{pNiceMatrix}[ + create-medium-nodes, + code-after = {\begin{tikzpicture} + [every node/.style = {fill = red!15, + blend mode = multiply, + inner sep = 0 pt}, + name suffix = -medium] + \node [fit = (1-1)] {} ; + \node [fit = (1-2)] {} ; + \node [fit = (1-3)] {} ; + \node [fit = (2-1)] {} ; + \node [fit = (2-2)] {} ; + \node [fit = (2-3)] {} ; + \node [fit = (3-1)] {} ; + \node [fit = (3-2)] {} ; + \node [fit = (3-3)] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c \\ +a & a & a + b \\ +a & a & a +\end{pNiceMatrix}\] + -\subsection{Les options hlines, vlines et hvlines} +\medskip +Les noms des «nœuds larges» s'obtiennent en ajoutant le suffixe «|-large|» au nom des nœuds normaux. Dans l'exemple +suivant, on a surligné tous les «nœuds larges». Nous considérons que cet exemple se suffit à lui-même comme +définition de ces nœuds.\footnote{Il n'y a pas de «nœuds larges» créés dans les rangées et colonnes extérieures + (pour ces rangées et colonnes, voir p.~\pageref{exterior}).} -\label{hvlines} +\[\begin{pNiceMatrix}[ + create-large-nodes, + code-after = {\begin{tikzpicture} + [every node/.style = {blend mode = multiply, + inner sep = 0 pt}, + name suffix = -large] + \node [fit = (1-1),fill = red!15] {} ; + \node [fit = (1-3),fill = red!15] {} ; + \node [fit = (2-2),fill = red!15] {} ; + \node [fit = (3-1),fill = red!15] {} ; + \node [fit = (3-3),fill = red!15] {} ; + \node [fit = (1-2),fill = blue!15] {} ; + \node [fit = (2-1),fill = blue!15] {} ; + \node [fit = (2-3),fill = blue!15] {} ; + \node [fit = (3-2),fill = blue!15] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c \\ +a & a & a + b \\ +a & a & a +\end{pNiceMatrix}\] -Dans les environnements de \pkg{nicematrix}, on peut bien entendu ajouter des filets horizontaux entre les rangées -avec la commande~|\hline| et des filets verticaux avec le spécificateur ``\verb+|+'' dans le préambule de -l'environnement. Par souci de commodité, l'extension \pkg{nicematrix} fournit aussi l'option |hlines| (resp. -|vlines|) qui impose directement que tous les filets horizontaux (resp. verticaux) soient tracés (à l'exception, -très naturelle, des filets extérieurs aux rangées et colonnes extérieures). L'option |hvlines| est la conjonction -des options |hlines| et |vlines|. \medskip -Dans l'exemple suivant, on utilise la commande |\arrayrulecolor| de \pkg{colortbl}. - - +Les «nœuds larges» de la première colonne et de la dernière colonne peuvent apparaître trop petits pour certains +usages. C'est pourquoi il est possible d'utiliser les options |left-margin| et |right-margin| pour ajouter de +l'espace des deux côtés du tableau et aussi de l'espace dans les «nœuds larges» de la première colonne et de la +dernière colonne. Dans l'exemple suivant, nous avons utilisé les options |left-margin| et +|right-margin|.\footnote{Les options |left-margin| et |right-margin| prennent des dimensions comme valeurs mais, si + aucune valeur n'est donnée, c'est la valeur par défaut qui est utilisée et elle est égale à |\arraycolsep| (par + défaut, 5~pt). Il existe aussi une option |margin| pour fixer à la fois |left-margin| et |right-margin|.} +\[\begin{pNiceMatrix}[ + create-large-nodes,left-margin,right-margin, + code-after = {\begin{tikzpicture} + [every node/.style = {blend mode = multiply, + inner sep = 0 pt}, + name suffix = -large] + \node [fit = (1-1),fill = red!15] {} ; + \node [fit = (1-3),fill = red!15] {} ; + \node [fit = (2-2),fill = red!15] {} ; + \node [fit = (3-1),fill = red!15] {} ; + \node [fit = (3-3),fill = red!15] {} ; + \node [fit = (1-2),fill = blue!15] {} ; + \node [fit = (2-1),fill = blue!15] {} ; + \node [fit = (2-3),fill = blue!15] {} ; + \node [fit = (3-2),fill = blue!15] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c \\ +a & a & a + b \\ +a & a & a +\end{pNiceMatrix}\] \medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] -\arrayrulecolor{blue} -$\begin{NiceArray}{CCCC}[~emphase#hvlines@,first-row,first-col] - & e & a & b & c \\ -e & e & a & b & c \\ -a & a & e & c & b \\ -b & b & c & e & a \\ -c & c & b & a & e -\end{NiceArray}$ -\arrayrulecolor{black} -\end{BVerbatim} -% -\arrayrulecolor{blue} -$\begin{NiceArray}{CCCC}[hvlines,first-row,first-col] - & e & a & b & c \\ -e & e & a & b & c \\ -a & a & e & c & b \\ -b & b & c & e & a \\ -c & c & b & a & e -\end{NiceArray}$ -\arrayrulecolor{black} +Il est aussi possible d'ajouter de l'espace sur les côtés du tableau avec les options |extra-left-margin| et +|extra-right-margin|. Ces marges ne sont pas incorporées dans les «nœuds larges». Dans l'exemple suivant, nous +avons utilisé |extra-left-margin| et |extra-right-margin| avec la valeur $3$~pt. +\[\begin{pNiceMatrix}[ + create-large-nodes,left-margin,right-margin,extra-right-margin=3pt,extra-left-margin=3pt, + code-after = {\begin{tikzpicture} + [every node/.style = {blend mode = multiply, + inner sep = 0 pt}, + name suffix = -large] + \node [fit = (1-1),fill = red!15] {} ; + \node [fit = (1-3),fill = red!15] {} ; + \node [fit = (2-2),fill = red!15] {} ; + \node [fit = (3-1),fill = red!15] {} ; + \node [fit = (3-3),fill = red!15] {} ; + \node [fit = (1-2),fill = blue!15] {} ; + \node [fit = (2-1),fill = blue!15] {} ; + \node [fit = (2-3),fill = blue!15] {} ; + \node [fit = (3-2),fill = blue!15] {} ; + \end{tikzpicture}}] +a & a + b & a + b + c \\ +a & a & a + b \\ +a & a & a +\end{pNiceMatrix}\] +\bigskip +\textbf{Attention} : Ces nœuds sont reconstruits à partir des contenus des cases et ne correspondent donc pas +nécessairement aux cases délimitées par des filets. \bigskip -Il y a néanmoins une différence entre l'utilisation de l'option |vlines| et du spécificateur «\verb+|+» dans le -préambule de l'environnement : les filets tracés par |vlines| traversent les double-filets horizontaux tracés par -|\hline\hline|. +\begin{minipage}[c]{7.5cm} +Voici un tableau qui a été composé de la manière suivante : \medskip -\begin{BVerbatim}[baseline=c,boxwidth=11.5cm] -$\begin{NiceArray}{CCCC}[vlines] \hline -a & b & c & d \\ \hline \hline -1 & 2 & 3 & 4 \\ -1 & 2 & 3 & 4 \\ \hline -\end{NiceArray}$ +\begin{BVerbatim} +\large +\begin{NiceTabular}{wl{2cm}LL}[hvlines] +fraise & amande & abricot \\ +prune & pêche & poire \\[1ex] +noix & noisette & brugnon +\end{NiceTabular} \end{BVerbatim} -% -$\begin{NiceArray}{CCCC}[vlines] -\hline -a & b & c & d \\ -\hline \hline -1 & 2 & 3 & 4 \\ -1 & 2 & 3 & 4 \\ -\hline -\end{NiceArray}$ +\end{minipage} +\hspace{1cm} +\begin{scope} +\large +\begin{NiceTabular}[c]{wl{2cm}LL}[hvlines] +fraise & amande & abricot \\ +prune & pêche & poire \\[1ex] +noix & noisette & brugnon +\end{NiceTabular} +\end{scope} -\bigskip -Dans le cas d'un environnement avec délimiteurs (par exemple |{pNiceArray}| ou |{pNiceMatrix}|), l'option |vlines| ne -trace pas de filets verticaux au niveau des deux délimiteurs (bien entendu). +\vspace{1cm} +\begin{minipage}[c]{7cm} +Ci-contre, on a colorié toutes les cases de ce tableau avec |\chessboardcolors|. +\end{minipage} +\hspace{1.5cm} +\begin{scope} +\large +\begin{NiceTabular}[c]{wl{2cm}LL}[hvlines,code-before = \chessboardcolors{red!15}{blue!15}] +fraise & amande & abricot \\ +prune & pêche & poire \\[1ex] +noix & noisette & brugnon +\end{NiceTabular} +\end{scope} -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=10.6cm] -\setlength{\arrayrulewidth}{0.2pt} -$\begin{pNiceMatrix}[vlines] -1 & 2 & 3 & 4 & 5 & 6 \\ -1 & 2 & 3 & 4 & 5 & 6 \\ -1 & 2 & 3 & 4 & 5 & 6 \\ -\end{pNiceMatrix}$ -\end{BVerbatim} -% + +\vspace{1cm} +\begin{minipage}[c]{7cm} +Voici maintenant tous les «nœuds larges» de ce tableau (sans utilisation de |margin| ni de |extra-margin|). +\end{minipage} +\hspace{1.5cm} \begin{scope} -\setlength{\arrayrulewidth}{0.2pt} -$\begin{pNiceMatrix}[vlines] -1 & 2 & 3 & 4 & 5 & 6 \\ -1 & 2 & 3 & 4 & 5 & 6 \\ -1 & 2 & 3 & 4 & 5 & 6 \\ -\end{pNiceMatrix}$ +\large +\begin{NiceTabular}[c]{wl{2cm}LL}[hvlines, + create-large-nodes, + code-after = {\begin{tikzpicture} + [every node/.style = {blend mode = multiply, + inner sep = 0 pt}, + name suffix = -large] + \node [fit = (1-1),fill = red!15] {} ; + \node [fit = (1-3),fill = red!15] {} ; + \node [fit = (2-2),fill = red!15] {} ; + \node [fit = (3-1),fill = red!15] {} ; + \node [fit = (3-3),fill = red!15] {} ; + \node [fit = (1-2),fill = blue!15] {} ; + \node [fit = (2-1),fill = blue!15] {} ; + \node [fit = (2-3),fill = blue!15] {} ; + \node [fit = (3-2),fill = blue!15] {} ; + \end{tikzpicture}}] +fraise & amande & abricot \\ +prune & pêche & poire \\[1ex] +noix & noisette & brugnon +\end{NiceTabular} \end{scope} -\subsection{L'option light-syntax} -\label{light-syntax} -L'option |light-syntax|\footnote{Cette option est inspirée de l'extension \pkg{spalign} de Joseph Rabinoff.} permet -d'alléger la saisie des matrices, ainsi que leur lisibilité dans le source TeX. Lorsque cette option est activée, -on doit utiliser le point-virgule comme marqueur de fin de rangée et séparer les colonnes par des espaces ou des -tabulations. On remarquera toutefois que, comme souvent dans le monde TeX, les espaces après les séquences de -contrôle ne sont pas comptées et que les éléments entre accolades sont considérés comme un tout. -\medskip -\begin{scope} -\begin{BVerbatim}[baseline=c,boxwidth=10cm] -$\begin{bNiceMatrix}[~emphase#light-syntax@,first-row,first-col] -{} a b ; -a 2\cos a {\cos a + \cos b} ; -b \cos a+\cos b { 2 \cos b } -\end{bNiceMatrix}$ -\end{BVerbatim} -\end{scope} -% -$\begin{bNiceMatrix}[light-syntax,first-row,first-col] -{} a b ; -a 2\cos a {\cos a + \cos b} ; -b \cos a+\cos b { 2 \cos b } -\end{bNiceMatrix}$ -\medskip -On peut changer le caractère utilisé pour indiquer les fins de rangées avec l'option |end-of-row|. Comme dit -précédemment, la valeur initiale de ce paramètre est un point-virgule. +\subsection{Les nœuds «row» et «col»} -\medskip -Lorsque l'option |light-syntax| est utilisée, il n'est pas possible de mettre d'éléments en verbatim (avec par -exemple la commande |\verb|) dans les cases du tableau.\footnote{La raison en est que lorsque l'option - |light-syntax| est utilisée, le contenu complet de l'environnement est chargé comme un argument de commande TeX. - L'environnement ne se comporte plus comme un «vrai» environnement de LaTeX qui se contente d'insérer des - commandes avant et après.} +L'extension \pkg{nicematrix} crée un nœud PGF-Tikz indiquant la position potentielle de chaque filet horizontal +(avec les noms |row-|$i$) et de chaque filet vertical (avec les noms |col-|$j$), comme décrit sur la figure +ci-dessous. Ces nœuds sont accessibles dans le |code-before| et dans le |code-after|. +\begin{center} +\begin{NiceTabular}{CCC}[hvlines,rules/width=1pt,rules/color=gray] +rose & tulipe & lys \\ +arum & iris & violette \\ +muguet & dahlia & souci +\CodeAfter +\tiny +\begin{tikzpicture} +\foreach \i in {1,2,3,4} + { + \fill [red] (row-\i) circle (0.5mm) ; + \node [red,anchor=east] at (row-\i) {row-\i} ; + } +\foreach \j in {1,2,3,4} + { + \fill [blue] (col-\j) circle (0.5mm) ; + \node [blue,anchor=north] at (col-\j) {col-\j} ; + } +\end{tikzpicture} +\end{NiceTabular} +\end{center} -\subsection{Utilisation du type de colonne S de siunitx} -Si l'extension \pkg{siunitx} est chargée (avant ou après \pkg{nicematrix}), il est possible d'utiliser les colonnes -de type |S| de \pkg{siunitx} dans les environnements de \pkg{nicematrix}. L'implémentation n'utilise explicitement -aucune macro privée de \pkg{siunitx}. +\bigskip +Si on utilise Tikz (on rappelle que \pkg{nicematrix} ne charge pas Tikz par défaut), on peut donc accéder (dans le +|code-before| et le |code-after|) à l'intersection du filet horizontal~$i$ et du filet vertical~$j$ avec la syntaxe +|(row-|$i$\verb+-|col-+$j$|)|. -\medskip -\begin{BVerbatim}[baseline = c, boxwidth = 10.5cm] -$\begin{pNiceArray}{~emphase#S@CWc{1cm}C}[nullify-dots,first-row] -{C_1} & \Cdots & & C_n \\ -2.3 & 0 & \Cdots & 0 \\ -12.4 & \Vdots & & \Vdots \\ -1.45 \\ -7.2 & 0 & \Cdots & 0 -\end{pNiceArray}$ -\end{BVerbatim} -$\begin{pNiceArray}{SCWc{1cm}C}[nullify-dots,first-row] -{C_1} & \Cdots & & C_n \\ -2.3 & 0 & \Cdots & 0 \\ -12.4 & \Vdots & & \Vdots \\ -1.45 \\ -7.2 & 0 & \Cdots & 0 -\end{pNiceArray}$ \medskip -En revanche, les colonnes |d| de l'extension \pkg{dcolumn} ne sont pas prises en charge par \pkg{nicematrix}. - +\begin{Verbatim} +\[\begin{NiceMatrix}[ + code-before = + { +~emphase# \tikz \draw [fill = red!15] @ +~emphase# (row-7-|col-4) -- (row-8-|col-4) -- (row-8-|col-5) -- @ +~emphase# (row-9-|col-5) -- (row-9-|col-6) |- cycle ; @ + } +] +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}\] +\end{Verbatim} +% +\[\begin{NiceMatrix}[ + code-before = + { + \tikz \draw [fill = red!15] + (row-7-|col-4) -- (row-8-|col-4) -- (row-8-|col-5) -- + (row-9-|col-5) -- (row-9-|col-6) |- cycle ; + } +] +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}\] \section{Remarques techniques} @@ -2040,26 +2399,13 @@ C_1 & C_2 & C_3 & C_4 \end{scope} \medskip -Le spécificateur |?| ainsi créé est aussi utilisable dans les environnements |{array}| (de \pkg{array}) et, dans ce -cas, |\OnlyMainNiceMatrix| est sans effet. +Le spécificateur |?| ainsi créé est aussi utilisable dans les environnements |{tabular}| et |{array}| (de +\pkg{array}) et, dans ce cas, |\OnlyMainNiceMatrix| est sans effet. -\subsection{Le nom des nœuds PGF créés par nicematrix} - -Les nœuds PGF-Tikz créés par \pkg{nicematrix} peuvent être utilisés hors des environnements de \pkg{nicematrix} -après avoir nommé l'environnement concerné avec l'option |name| (cf. p.~\pageref{name}). Il s'agit là de la méthode -conseillée mais on décrit néanmoins maintenant le nom Tikz interne de ces nœuds. - -Les environnements créés par \pkg{nicematrix} sont numérotés par un compteur global interne. La commande -|\NiceMatrixLastEnv| donne le numéro du dernier de ces environnements (pour LaTeX, il s'agit d'une commande — -complètement développable — et non d'un compteur). - -Si l'environnement concerné a le numéro $n$, alors le nœud de la rangée~$i$ et de la colonne~$j$ a pour nom -|nm-|$n$|-|$i$|-|$j$. Les noms des nœuds |medium| et |large| correspondants s'obtiennent en suffixant par |-medium| -et |-large|. \subsection{Lignes diagonales} @@ -2185,91 +2531,14 @@ Avec cette option, des espaces extérieurs de longueur |\arraycolsep| seront ins -\subsection{Un problème technique avec l'argument de \textbackslash\textbackslash} - - -Pour des raisons techniques, si vous utilisez l'argument optionnel de la commande |\\|, l'espace vertical sera -aussi ajouté au nœud («normal») correspondant à la case précédente. - - -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] - \begin{pNiceMatrix} - a & \frac AB \\~emphase#[2mm]@ - b & c - \end{pNiceMatrix} -\end{BVerbatim} -$\begin{pNiceMatrix}[ - code-after = {\tikz \node [inner sep = 0pt, - fill = red!15, - blend mode = multiply, - fit = (1-2) ] {} ; } ] -a & \frac AB \\[2mm] -b & c -\end{pNiceMatrix}$ - -\bigskip -Il y a deux solutions pour résoudre ce problème. La première solution est d'utiliser une commande TeX pour insérer -l'espace entre les deux rangées. - -\medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] - \begin{pNiceMatrix} - a & \frac AB \\ - ~emphase#\noalign{\kern2mm}@ - b & c - \end{pNiceMatrix} -\end{BVerbatim} -$\begin{pNiceMatrix}[ - code-after = {\tikz \node [inner sep = 0pt, - fill = red!15, - blend mode = multiply, - fit = (1-2) ] {} ; } ] -a & \frac AB \\ -\noalign{\kern2mm} -b & c -\end{pNiceMatrix}$ +\subsection{Incompatibilités} -\bigskip -L'autre solution est d'utiliser la commande |\multicolumn| dans la case précédente : +L'extension \pkg{nicematrix} n'est pas compatible with \pkg{threeparttable}. \medskip -\begin{BVerbatim}[baseline=c,boxwidth=11cm] - \begin{pNiceMatrix} - a & ~emphase#\multicolumn1C{\frac AB}@ \\[2mm] - b & c - \end{pNiceMatrix} -\end{BVerbatim} -$\begin{pNiceMatrix}[ - code-after = {\tikz \node [inner sep = 0pt, - fill = red!15, - blend mode = multiply, - fit = (1-2) ] {} ; } ] -a & \multicolumn1C{\frac AB} \\[2mm] -b & c -\end{pNiceMatrix}$ - -\subsection{Environnements obsolètes} - -La version 3.0 de \pkg{nicematrix} a introduit l'environnement |{pNiceArray}| (et ses variantes) avec les options -|first-row|, |last-row|, |first-col| et |last-col|. - -Par conséquent, les environnements suivants, présents dans les versions précédentes de \pkg{nicematrix} ont été -supprimés. -% -\begin{itemize} -\item |{NiceArrayCwithDelims}| ; -\item |{pNiceArrayC}|, |{bNiceArrayC}|, |{BNiceArrayC}|, |{vNiceArrayC}|, -|{VNiceArrayC}| ; -\item |{NiceArrayRCwithDelims}| ; -\item |{pNiceArrayRC}|, |{bNiceArrayRC}|, |{BNiceArrayRC}|, |{vNiceArrayRC}|, -|{VNiceArrayRC}|. -\end{itemize} - -Le code correspondant est toutefois encore présent à la fin du fichier |nicematrix.sty|, après une -commande |\file_input_stop:|. - +L'extension \pkg{nicematrix} n'est pas parfaitement compatible avec l'extension \pkg{arydshln} (parce que cette +extension redéfinit de nombreuses commandes internes de \pkg{array}). \section{Exemples} @@ -2402,11 +2671,9 @@ a_p & &&a_0 & & &b_1 \\ \end{scope} \vspace{2cm} -Un exemple avec un système linéaire (le trait vertical a été tracé en bleu avec les outils de -\pkg{colortbl}):\par\nobreak +Un exemple avec un système linéaire:\par\nobreak \begin{Verbatim} -\arrayrulecolor{blue} $\begin{pNiceArray}{*6C|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 \\ @@ -2415,10 +2682,9 @@ $\begin{pNiceArray}{*6C|C}[nullify-dots,last-col,code-for-last-col=\scriptstyle] \Vdots & & &\Ddots & & 0 & \\ 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 \end{pNiceArray}$ -\arrayrulecolor{black} \end{Verbatim} -\arrayrulecolor{blue} + \[\begin{pNiceArray}{*6C|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 \\ @@ -2427,7 +2693,7 @@ $\begin{pNiceArray}{*6C|C}[nullify-dots,last-col,code-for-last-col=\scriptstyle] \Vdots & & &\Ddots & & 0 & \\ 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 \end{pNiceArray}\] -\arrayrulecolor{black} + \subsection{Des lignes pointillées qui ne sont plus pointillées} @@ -2617,19 +2883,16 @@ a_{41} & a_{42} & a_{43} & a_{44} On remarquera que les traits que l'on vient de tracer sont dessinés \emph{après} la matrice sans modifier la position des composantes de celle-ci. En revanche, les traits tracés par |\hline|, le spécificateur «\verb+|+» ou -les options |hlines| et |vlines| «écartent» les composantes de la matrice (quand l'extension \pkg{array} est -chargée, ce qui est toujours le cas avec \pkg{nicematrix}).\footnote{En revanche les traits tracés par |\ncline| - n'écartent pas les lignes de la matrice.} +les options |hlines|, |vlines| et |hvlines| «écartent» les composantes de la matrice.\footnote{Pour la commande + |\cline|, voir la remarque p.~\pageref{remark-cline}.} \vspace{1cm} - -L'extension \pkg{nicematrix} est construite au-dessus de l'environnement |{array}| et, par conséquent, il est -possible d'utiliser l'extension \pkg{colortbl} dans les environnements de \pkg{nicematrix}. Les possibilités de -réglage de \pkg{colortbl} sont néanmoins assez limitées. C'est pourquoi nous proposons une autre méthode pour -surligner une rangée de la matrice. Nous créons un nœud Tikz rectangulaire qui englobe les nœuds de la deuxième -rangée en utilisant les outils de la bibliothèque Tikz \pkg{fit}. Ce nœud est rempli après la construction de la -matrice. Pour que l'on puisse voir le texte \emph{sous} le nœud, nous devons utiliser la transparence avec le -|blend mode| égal à |multiply|. +Il est possible de colorier une rangée avec |\rowcolor| dans le |code-before| (ou avec |\rowcolor| de +\pkg{colortbl} dans la première case de la rangée ). Les possibilités de réglages sont néanmoins limitées. C'est +pourquoi nous présentons ici une autre méthode pour surligner une rangée de la matrice. Nous créons un nœud Tikz +rectangulaire qui englobe les nœuds de la deuxième rangée en utilisant les outils de la bibliothèque Tikz +\pkg{fit}. Ce nœud est rempli après la construction de la matrice. Pour que l'on puisse voir le texte \emph{sous} +le nœud, nous devons utiliser la transparence avec le |blend mode| égal à |multiply|. \tikzset{highlight/.style={rectangle, @@ -2941,3 +3204,8 @@ documentation ici présente, ainsi que le code source commenté et un historique \end{document} + + + + + diff --git a/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf b/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf index 8f7fb6b647e..0004ec61cd3 100644 Binary files a/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf and b/Master/texmf-dist/doc/latex/nicematrix/nicematrix.pdf differ diff --git a/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx b/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx index a78a94ee50c..7e220667699 100644 --- a/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx +++ b/Master/texmf-dist/source/latex/nicematrix/nicematrix.dtx @@ -15,8 +15,8 @@ % % \fi % \iffalse -\def\myfileversion{4.0} -\def\myfiledate{2020/05/08} +\def\myfileversion{4.1} +\def\myfiledate{2020/05/27} % % %<*batchfile> @@ -123,38 +123,12 @@ version 2005/12/01 or later. % % \begin{abstract} % The LaTeX package \pkg{nicematrix} provides new environments similar to the -% classical environments |{tabular}|, |{array}| and |{matrix}| but with some -% additional features. Among these features are the possibilities to fix the -% width of the columns and to draw continuous ellipsis dots between the cells of -% the array. +% classical environments |{tabular}|, |{array}| and |{matrix}| of \pkg{array} +% and \pkg{amsmath} but with extended features. % \end{abstract} % % \vspace{1cm} -% \section{Presentation} -% -% -% This package can be used with |xelatex|, |lualatex|, |pdflatex| but also by -% the classical workflow |latex|-|dvips|-|ps2pdf| (or Adobe Distiller). Two or -% three compilations may be necessary. This package requires and \textbf{loads} -% the packages \pkg{l3keys2e}, \pkg{xparse}, \pkg{array}, \pkg{amsmath}, -% \pkg{pgfcore} and the module \pkg{shapes} of \textsc{pgf} (\pkg{tikz} is -% \emph{not} loaded). The final user only has to load the package with -% |\usepackage{nicematrix}|. -% -% -% \medskip -% \begin{savenotes} -% \begin{minipage}{0.6\linewidth} -% This package provides some new tools to draw mathematical matrices. The main -% features are the following: -% \begin{itemize}\setlength{\itemsep}{0pt} -% \item continuous dotted lines; -% \item exterior rows and columns for labels; -% \item a control of the width of the columns. -% \end{itemize} -% \end{minipage} -% \end{savenotes} -% \hspace{1.4cm} +% \hspace{1cm} % $\begin{bNiceArray}{CCCC}[first-row,first-col, % code-for-first-col=\color{blue}\scriptstyle, % code-for-first-row=\color{blue}\scriptstyle, @@ -164,58 +138,59 @@ version 2005/12/01 or later. % L_2 & a_{21} & a_{22} & \Cdots & a_{2n} \\ % \Vdots & \Vdots & \Vdots & \Ddots & \Vdots\\ % L_n & a_{n1} & a_{n2} & \Cdots & a_{nn} -% \end{bNiceArray}$ -% -% \medskip -% A command |\NiceMatrixOptions| is provided to fix the options (the -% scope of the options fixed by this command is the current TeX group). +% \end{bNiceArray}$\hspace{2cm} +% \begin{NiceTabular}{LSSSS}[code-before = \rowcolor{red!15}{1-2} \rowcolors{3}{blue!15}{}] +% \toprule +% \Block{2-1}{Product} & \multicolumn{3}{C}{dimensions (cm)} & \Block{2-1}{\rotate Price} \\ +% \cmidrule(rl){2-4} +% & L & l & h \\ +% \midrule +% small & 3 & 5.5 & 1 & 30 \\ +% standard & 5.5 & 8 & 1.5 & 50.5 \\ +% premium & 8.5 & 10.5 & 2 & 80 \\ +% extra & 8.5 & 10 & 1.5 & 85.5 \\ +% special & 12 & 12 & 0.5 & 70 \\ +% \bottomrule +% \end{NiceTabular} % -% -% \bigskip -% \textbf{An example for the continuous dotted lines} +% \vspace{1cm} +% The package \pkg{nicematrix} is entirely contained in the file +% |nicematrix.sty|. This file may be put in the current directory or in a +% |texmf| tree. However, the best is to install \pkg{nicematrix} with a TeX +% distribution as MiKTeX or TeXlive. % -% \medskip -% \begin{minipage}{10cm} -% For example, consider the following code which uses an environment |{pmatrix}| -% of \pkg{amsmath}. +% \bigskip +% This package can be used with |xelatex|, |lualatex|, |pdflatex| but also by +% the classical workflow |latex|-|dvips|-|ps2pdf| (or Adobe Distiller). % -% \smallskip -% \begin{BVerbatim} -% $A = \begin{pmatrix} -% 1 & \cdots & \cdots & 1 \\ -% 0 & \ddots & & \vdots \\ -% \vdots & \ddots & \ddots & \vdots \\ -% 0 & \cdots & 0 & 1 -% \end{pmatrix}$ -% \end{BVerbatim} +% \bigskip +% This package requires and \textbf{loads} the packages \pkg{l3keys2e}, +% \pkg{xparse}, \pkg{array}, \pkg{amsmath}, \pkg{pgfcore} and the module +% \pkg{shapes} of \textsc{pgf} (\pkg{tikz}, which is a layer over \textsc{pgf} +% is \emph{not} loaded). The final user only has to load the package with +% |\usepackage{nicematrix}|. % -% \smallskip -% This code composes the matrix $A$ on the right. -% \end{minipage}\hspace{1cm} -% $A = \begin{pmatrix} -% 1 &\cdots &\cdots &1 \\ -% 0 &\ddots & &\vdots \\ -% \vdots &\ddots &\ddots &\vdots \\ -% 0 &\cdots &0 &1 -% \end{pmatrix}$ % +% \bigskip +% The idea of \pkg{nicematrix} is to create \textsc{pgf} nodes under the cells +% and the positions of the rules of the tabular created by \pkg{array} and to +% use these nodes to develop new features. As usual with \textsc{pgf}, the +% coordinates of these nodes are written in the |.aux| to be used on the next +% compilation and that's why \pkg{nicematrix} may need \textbf{several +% compilations}. % % \bigskip -% \begin{scope} -% \NiceMatrixOptions{transparent} -% \begin{minipage}{10cm} -% Now, if we use the package \pkg{nicematrix} with the option \\ -% |transparent|, the same code will give the result on the right. -% \end{minipage}\hspace{1cm} -% $A = \begin{pmatrix} -% 1 & \cdots & \cdots & 1 \\ -% 0 & \ddots & & \vdots \\ -% \vdots & \ddots & \ddots & \vdots \\ -% 0 & \cdots & 0 & 1 -% \end{pmatrix}$ -% \end{scope} +% Most features of \pkg{nicematrix} may be used without explicit use of +% \textsc{pgf} or Tikz (which, in fact, is not loaded by default). +% +% \bigskip +% 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). % % +% \newpage +% % \section{The environments of this package} % % The package \pkg{nicematrix} defines the following new environments. @@ -224,918 +199,958 @@ version 2005/12/01 or later. % \begin{ttfamily} % \setlength{\tabcolsep}{3mm} % \begin{tabular}{llll} -% \{NiceMatrix\} & \{NiceArray\} & \{NiceTabular\} \\ -% \{pNiceMatrix\} & \{pNiceArray\} \\ -% \{bNiceMatrix\} & \{bNiceArray\} \\ -% \{BNiceMatrix\} & \{BNiceArray\} \\ -% \{vNiceMatrix\} & \{vNiceArray\} \\ -% \{VNiceMatrix\} & \{VNiceArray\} \\ -% & \{NiceArrayWithDelims\} +% \{NiceTabular\} & \{NiceArray\} & \{NiceMatrix\} \\ +% & \{pNiceArray\} & \{pNiceMatrix\} \\ +% & \{bNiceArray\} & \{bNiceMatrix\} \\ +% & \{BNiceArray\} & \{BNiceMatrix\} \\ +% & \{vNiceArray\} & \{vNiceMatrix\} \\ +% & \{VNiceArray\} & \{VNiceMatrix\} % \end{tabular} % \end{ttfamily} % % -% \medskip -% By default, the environments |{NiceMatrix}|, |{pNiceMatrix}|, |{bNiceMatrix}|, -% |{BNiceMatrix}|, |{vNiceMatrix}| and |{VNiceMatrix}| behave almost exactly as -% the corresponding environments of \pkg{amsmath}: |{matrix}|, |{pmatrix}|, -% |{bmatrix}|, |{Bmatrix}|, |{vmatrix}| and |{Vmatrix}|. % % % \medskip % The environments |{NiceArray}| and |{NiceTabular}| are similar to the -% environments |{array}| and |{tabular}| of the -% package |{array}|. However, for technical reasons, in the preamble of these -% environments, the user must use the letters |L|, |C| and~|R| -% instead of |l|, |c| and |r|. It's possible to use the constructions -% |w{...}{...}|, |W{...}{...}|, "|", |>{...}|, |<{...}|, |@{...}|, |!{...}| and -% |*{n}{...}| but the letters |p|, |m| and |b| should not be used. +% environments |{array}| and |{tabular}| of the package \pkg{array} (which is +% loaded by \pkg{nicematrix} ). % -% See p.~\pageref{NiceArray} the section relating to |{NiceArray}| and |{NiceTabular}|. -% +% \medskip +% However, there are some small differences: +% \begin{itemize} +% \item For technical reasons, in the preamble of these environments, the user +% must use the letters |L|, |C| and~|R|\footnote{The column types |L|, |C| and +% |R| are defined locally inside |{NiceTabular}| or |{NiceArray}| with +% |\newcolumntype| of \pkg{array}. This definition overrides an eventual +% previous definition.} instead of |l|, |c| and |r|, included in the commands +% |\multicolumn| and in the types of columns defined by |\newcolumntype|. +% +% * In |{NiceArray}| (and its variants), the columns of type |w| (ex. : +% |wc{1cm}|) are composed in math mode whereas, in |{array}| of \pkg{array}, +% they are composed in text mode. +% \end{itemize} +% +% \medskip +% The environments |{pNiceArray}|, |{bNiceArray}|, etc. have no equivalent in +% \pkg{array}. % -% \section{The continuous dotted lines} +% \medskip +% The environments |{NiceMatrix}|, |{pNiceMatrix}|, etc. are similar to the +% corresponding environments of \pkg{amsmath} (which is loaded by +% \pkg{nicematrix}): |{matrix}|, |{pmatrix}|, etc. % -% Inside the environments of the package \pkg{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|.\footnote{The command |\iddots|, defined in \pkg{nicematrix}, is a -% variant of |\ddots| with dots going forward. If |mathdots| is loaded, the -% version of |mathdots| is used. It corresponds to the command |\adots| of -% \pkg{unicode-math}.} -% \newcounter{fniddots} -% \setcounter{fniddots}{\thefootnote} +% \medskip +% All the environments of the package \pkg{nicematrix} accept, between square +% brackets, an optional list of \textsl{key=value} pairs. \textbf{There must be +% no space before the opening bracket (|[|) of this list of options.} % -% \smallskip -% Each of them must be used alone in the cell of the array and it draws a dotted -% line between the first non-empty cells\footnote{The precise definition of a -% ``non-empty cell'' is given below (cf. p.~\pageref{empty-cells}).} 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|.\footnote{It's also possible to change the color of -% all theses dotted lines with the option |xdots/color| (\textsl{xdots} to -% remind that it works for |\Cdots|, |\Ldots|, |\Vdots|, etc.): cf. p. \pageref{customization}.}\par\nobreak +% \section{The vertical space between the rows} % -% \bigskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% \begin{bNiceMatrix} -% a_1 & \Cdots & & & a_1 \\ -% \Vdots & a_2 & \Cdots & & a_2 \\ -% & \Vdots & \Ddots[color=red] \\ -% \\ -% a_1 & a_2 & & & a_n -% \end{bNiceMatrix} +% It's well known that some rows of the arrays created by default with LaTeX +% are, by default, too close to each other. Here is a classical example. +% +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=9cm] +% $\begin{pmatrix} +% \frac12 & -\frac12 \\ +% \frac13 & \frac14 \\ +% \end{pmatrix}$ % \end{BVerbatim} -% $\begin{bNiceMatrix} -% a_1 & \Cdots & & & a_1 \\ -% \Vdots & a_2 & \Cdots & & a_2 \\ -% & \Vdots & \Ddots[color=red] \\ -% \\ -% a_1 & a_2 & & & a_n -% \end{bNiceMatrix}$ +% $\begin{pmatrix} +% \frac12 & -\frac12 \\ +% \frac13 & \frac14 \\ +% \end{pmatrix}$ % -% \interitem -% In order to represent the null matrix, one can use the following -% codage:\par\nobreak -% % \bigskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% \begin{bNiceMatrix} -% 0 & \Cdots & 0 \\ -% \Vdots & & \Vdots \\ -% 0 & \Cdots & 0 -% \end{bNiceMatrix} -% \end{BVerbatim} -% $\begin{bNiceMatrix} -% 0 & \Cdots & 0 \\ -% \Vdots & & \Vdots \\ -% 0 & \Cdots & 0 -% \end{bNiceMatrix}$ +% Inspired by the package \pkg{cellspace} which deals with that problem, the +% package \pkg{nicematrix} provides two keys |cell-space-top-limit| and +% |cell-space-bottom-limit| similar to the parameters |\cellspacetoplimit| and +% |\cellspacebottomlimit| of \pkg{cellspace}. The initial value of these +% parameters is $0$~pt in order to have for the environments of \pkg{nicematrix} +% the same behaviour as those of \pkg{array} and \pkg{amsmath}. However, a value +% of $1$~pt would probably be a good choice and we suggest to set them with +% |\NiceMatrixOptions|. % -% \bigskip -% 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 \pkg{nicematrix}:\par\nobreak +% \medskip +% \begin{Verbatim} +% \NiceMatrixOptions{~emphase#cell-space-top-limit = 1pt,cell-space-bottom-limit = 1pt@} +% \end{Verbatim} % -% \bigskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% \begin{bNiceMatrix} -% 0 & \Cdots & \Cdots & 0 \\ -% \Vdots & & & \Vdots \\ -% \Vdots & & & \Vdots \\ -% 0 & \Cdots & \Cdots & 0 -% \end{bNiceMatrix} +% \begin{BVerbatim}[baseline=c,boxwidth=9cm] +% $\begin{pNiceMatrix} +% \frac12 & -\frac12 \\ +% \frac13 & \frac14 \\ +% \end{pNiceMatrix}$ % \end{BVerbatim} -% $\begin{bNiceMatrix} -% 0 & \Cdots & \Cdots & 0 \\ -% \Vdots & & & \Vdots \\ -% \Vdots & & & \Vdots \\ -% 0 & \Cdots & \Cdots & 0 -% \end{bNiceMatrix}$ +% \begin{scope} +% \NiceMatrixOptions{ +% cell-space-top-limit = 1pt , +% cell-space-bottom-limit = 1pt , +% } +% $\begin{pNiceMatrix} +% \frac12 & -\frac12 \\ +% \frac13 & \frac14 \\ +% \end{pNiceMatrix}$ +% \end{scope} +% +% % -% \bigskip -% In the first column of this exemple, there are two instructions |\Vdots| but -% only one dotted line is drawn (there is no overlapping graphic objects in the -% resulting \textsc{pdf}\footnote{And it's not possible to draw a |\Ldots| and a -% |\Cdots| line between the same cells.}). % -% \bigskip -% In fact, in this example, it would be possible to draw the same matrix more -% easily with the following code:\par\nobreak % % \bigskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% \begin{bNiceMatrix} -% 0 & \Cdots & & 0 \\ -% \Vdots & & & \\ -% & & & \Vdots \\ -% 0 & & \Cdots & 0 -% \end{bNiceMatrix} -% \end{BVerbatim} -% $\begin{bNiceMatrix} -% 0 & \Cdots & & 0 \\ -% \Vdots & & & \\ -% & & & \Vdots \\ -% 0 & & \Cdots & 0 -% \end{bNiceMatrix}$ +% \section{The vertical position of the arrays} % -% \bigskip -% 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.\footnote{In \pkg{nicematrix}, one should use |\hspace*| and not -% |\hspace| for such an usage because \pkg{nicematrix} loads \pkg{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.~\pageref{width}} -% -% However, a command~|\hspace*| might interfer with the construction of the -% dotted lines. That's why the package \pkg{nicematrix} provides a -% command~|\Hspace| which is a variant of |\hspace| transparent for the dotted -% lines of \pkg{nicematrix}.\par\nobreak +% The package \pkg{nicematrix} provides a option |baseline| for the vertical +% position of the arrays. This option takes as value an integer which is the +% number of the row on which the array will be aligned. % -% \bigskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% \begin{bNiceMatrix} -% 0 & \Cdots & ~emphase#\Hspace*{1cm}@ & 0 \\ -% \Vdots & & & \Vdots \\~emphase#[1cm]@ -% 0 & \Cdots & & 0 -% \end{bNiceMatrix} +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=9cm] +% $A = \begin{pNiceMatrix}[~emphase#baseline=2@] +% \frac{1}{\sqrt{1+p^2}} & p & 1-p \\ +% 1 & 1 & 1 \\ +% 1 & p & 1+p +% \end{pNiceMatrix}$ % \end{BVerbatim} -% $\begin{bNiceMatrix} -% 0 & \Cdots & \Hspace*{1cm} & 0 \\ -% \Vdots & & & \Vdots \\[1cm] -% 0 & \Cdots & & 0 -% \end{bNiceMatrix}$ +% $A = \begin{pNiceMatrix}[baseline=2] +% \frac{1}{\sqrt{1+p^2}} & p & 1-p \\ +% 1 & 1 & 1 \\ +% 1 & p & 1+p +% \end{pNiceMatrix}$ % -% \subsection{The option nullify-dots} % -% -% Consider the following matrix composed classicaly with the environment -% \verb|{pmatrix}| of \pkg{amsmath}.\par\nobreak -% % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $A = \begin{pmatrix} -% h & i & j & k & l & m \\ -% x & & & & & x -% \end{pmatrix}$ -% \end{BVerbatim} -% $A = \begin{pmatrix} -% h & i & j & k & l & m \\ -% x & & & & & x -% \end{pmatrix}$ -% +% It's also possible to use the option |baseline| with one of the special values +% |t|, |c| or |b|. These letters may also be used absolutely like the option of +% the environments |{tabular}| and |{array}| of \pkg{array}. The initial value +% of |baseline| is~|c|. % -% \bigskip -% If we add \verb|\ldots| instructions in the second row, the geometry of the -% matrix is modified.\par\nobreak % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $B = \begin{pmatrix} -% h & i & j & k & l & m \\ -% x & \ldots & \ldots & \ldots & \ldots & x -% \end{pmatrix}$ -% \end{BVerbatim} -% $B = \begin{pmatrix} -% h & i & j & k & l & m \\ -% x & \ldots & \ldots & \ldots & \ldots & x -% \end{pmatrix}$ -% -% \bigskip -% By default, with \pkg{nicematrix}, if we replace \verb|{pmatrix}| by -% \verb|{pNiceMatrix}| and \verb|\ldots| by \verb|\Ldots|, the geometry of the matrix is not -% changed.\par\nobreak +% In the following example, we use the option |t| (equivalent to |baseline=t|) +% immediately after an |\item| of list. One should remark that the presence of a +% |\hline| at the beginning of the array doesn't prevent the alignment of the +% baseline with the baseline of the first row (with |{tabular}| or |{array}| of +% \pkg{array}, one must use |\firsthline|\footnote{It's also possible to use +% |\firsthline| in the environments of \pkg{nicematrix}.}). % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $C = \begin{pNiceMatrix} -% h & i & j & k & l & m \\ -% x & \Ldots & \Ldots & \Ldots & \Ldots & x -% \end{pNiceMatrix}$ -% \end{BVerbatim} -% $C = \begin{pNiceMatrix} -% h & i & j & k & l & m \\ -% x & \Ldots & \Ldots & \Ldots & \Ldots & x -% \end{pNiceMatrix}$ +% \begin{BVerbatim}[baseline=c,boxwidth=9cm] +% \begin{enumerate} +% \item an item +% \smallskip +% \item \renewcommand{\arraystretch}{1.2} +% $\begin{NiceArray}~emphase#[t]@{LCCCCCC} +% \hline +% n & 0 & 1 & 2 & 3 & 4 & 5 \\ +% u_n & 1 & 2 & 4 & 8 & 16 & 32 +% \hline +% \end{NiceArray}$ +% \end{enumerate} +% \end{BVerbatim} +% \begin{minipage}{5cm} +% \begin{enumerate} +% \item an item +% \smallskip +% \item \renewcommand{\arraystretch}{1.2} +% $\begin{NiceArray}[t]{LCCCCCC} +% \hline +% n & 0 & 1 & 2 & 3 & 4 & 5 \\ +% u_n & 1 & 2 & 4 & 8 & 16 & 32 \\ +% \hline +% \end{NiceArray}$ +% \end{enumerate} +% \end{minipage} +% +% \medskip +% However, it's also possible to use the tools of \pkg{booktabs}: |\toprule|, +% |\bottomrule|, |\midrule|, etc.\par\nobreak % -% \bigskip -% 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 \verb|nullify-dots| (and only one instruction \verb|\Ldots| is -% necessary).\par\nobreak +% \smallskip +% \begin{BVerbatim}[baseline=c,boxwidth=9cm] +% \begin{enumerate} +% \item an item +% \smallskip +% \item +% $\begin{NiceArray}[t]{LCCCCCC} +% ~emphase#\toprule@ +% n & 0 & 1 & 2 & 3 & 4 & 5 \\ +% ~emphase#\midrule@ +% u_n & 1 & 2 & 4 & 8 & 16 & 32 +% ~emphase#\bottomrule@ +% \end{NiceArray}$ +% \end{enumerate} +% \end{BVerbatim} +% \begin{minipage}{5cm} +% \begin{enumerate} +% \item an item +% \smallskip +% \item +% $\begin{NiceArray}[t]{LCCCCCC} +% \toprule +% n & 0 & 1 & 2 & 3 & 4 & 5 \\ +% \midrule +% u_n & 1 & 2 & 4 & 8 & 16 & 32 \\ +% \bottomrule +% \end{NiceArray}$ +% \end{enumerate} +% \end{minipage} +% +% +% \section{The blocks} +% \label{Block} +% +% In the environments of \pkg{nicematrix}, it's possible to use the command +% |\Block| in order to place an element in the center of a rectangle of merged +% cells of the array. The command |\Block| don't create space by itself. +% +% The command |\Block| must be used in the upper leftmost cell of the array with +% two arguments. The first argument is the size of the block with the syntax +% $i$\verb|-|$j$ where $i$ is the number of rows of the block and $j$ its number +% of columns. The second argument is the content of the block. +% +% In |{NiceTabular}| the content of the block is composed in text mode. In the +% other environments, it is composed in math mode. % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $D = \begin{pNiceMatrix}[~emphase#nullify-dots@] -% h & i & j & k & l & m \\ -% x & \Ldots & & & & x -% \end{pNiceMatrix}$ +% \begin{BVerbatim} +% \begin{NiceTabular}{CCCC} +% rose & tulipe & marguerite & dahlia \\ +% violette & ~emphase#\Block{2-2}{\LARGE\color{blue} fleurs}@ & & souci \\ +% pervenche & & & lys \\ +% arum & iris & jacinthe & muguet +% \end{NiceTabular} % \end{BVerbatim} -% $D = \begin{pNiceMatrix}[nullify-dots] -% h & i & j & k & l & m \\ -% x & \Ldots & & & & x -% \end{pNiceMatrix}$ % -% \medskip -% The option |nullify-dots| smashes the instructions |\Ldots| (and the variants) -% horizontally but also vertically. % % \medskip -% \textbf{There must be no space before the opening bracket (|[|) of the options -% of the environment.} -% +% \begin{center} +% \begin{NiceTabular}{CCCC} +% rose & tulipe & marguerite & dahlia \\ +% violette & \Block{2-2}{\LARGE\color{blue} fleurs} & & souci \\ +% pervenche & & & lys \\ +% arum & iris & jacinthe & muguet +% \end{NiceTabular} +% \end{center} % -% \subsection{The command \textbackslash Hdotsfor} % -% Some people commonly use the command |\hdotsfor| of \pkg{amsmath} in order to -% draw horizontal dotted lines in a matrix. In the environments of -% \pkg{nicematrix}, one should use instead |\Hdotsfor| in order to draw dotted -% lines similar to the other dotted lines drawn by the package \pkg{nicematrix}. % -% As with the other commands of \pkg{nicematrix} (like |\Cdots|, |\Ldots|, -% |\Vdots|, etc.), the dotted line drawn with |\Hdotsfor| extends until the -% contents of the cells on both sides. +% \medskip +% It's also possible to use the command |\Block| in mathematical matrices. % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=7cm] -% $\begin{pNiceMatrix} -% 1 & 2 & 3 & 4 & 5 \\ -% 1 & ~emphase#\Hdotsfor{3}@ & 5 \\ -% 1 & 2 & 3 & 4 & 5 \\ -% 1 & 2 & 3 & 4 & 5 -% \end{pNiceMatrix}$ +% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] +% $\begin{bNiceArray}{CCC|C}[margin] +% ~emphase#\Block{3-3}{A}@ & & & 0 \\ +% & \hspace*{1cm} & & \Vdots \\ +% & & & 0 \\ +% \hline +% 0 & \Cdots& 0 & 0 +% \end{bNiceArray}$ % \end{BVerbatim} -% $\begin{pNiceMatrix} -% 1 & 2 & 3 & 4 & 5 \\ -% 1 & \Hdotsfor{3} & 5 \\ -% 1 & 2 & 3 & 4 & 5 \\ -% 1 & 2 & 3 & 4 & 5 -% \end{pNiceMatrix}$ +% $\begin{bNiceArray}{CCC|C}[margin] +% \Block{3-3}{A} & & & 0 \\ +% & \hspace*{1cm} & & \Vdots \\ +% & & & 0 \\ +% \hline +% 0 & \Cdots& 0 & 0 +% \end{bNiceArray}$ % % \bigskip -% However, if these cells are empty, the dotted line extends only in the cells -% specified by the argument of |\Hdotsfor| (by design). +% 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. % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=7cm] -% $\begin{pNiceMatrix} -% 1 & 2 & 3 & 4 & 5 \\ -% & ~emphase#\Hdotsfor{3}@ \\ -% 1 & 2 & 3 & 4 & 5 \\ -% 1 & 2 & 3 & 4 & 5 -% \end{pNiceMatrix}$ +% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] +% $\begin{bNiceArray}{CCC|C}[margin] +% \Block{3-3}~emphase#<\Large>@{A} & & & 0 \\ +% & \hspace*{1cm} & & \Vdots \\ +% & & & 0 \\ +% \hline +% 0 & \Cdots& 0 & 0 +% \end{bNiceArray}$ % \end{BVerbatim} -% $\begin{pNiceMatrix} -% 1 & 2 & 3 & 4 & 5 \\ -% & \Hdotsfor{3} \\ -% 1 & 2 & 3 & 4 & 5 \\ -% 1 & 2 & 3 & 4 & 5 -% \end{pNiceMatrix}$ -% +% \begin{scope} +% $\begin{bNiceArray}{CCC|C}[margin] +% \Block{3-3}<\Large>{A} & & & 0 \\ +% & \hspace*{1cm} & & \Vdots \\ +% & & & 0 \\ +% \hline +% 0 & \Cdots& 0 & 0 +% \end{bNiceArray}$ +% \end{scope} % -% Remark: Unlike the command |\hdotsfor| of \pkg{amsmath}, the command -% |\Hdotsfor| may be used when the package \pkg{colortbl} is loaded (but you -% might have problem if you use |\rowcolor| on the same row as |\Hdotsfor|). +% \section{The rules} % -% \subsection{How to generate the continuous dotted lines transparently} +% The usual techniques for the rules may be used in the environments of +% \pkg{nicematrix} (excepted |\vline|). % -% The package \pkg{nicematrix} provides an option called |transparent| for using -% existing code transparently in the environments of the \pkg{amsmath} : -% |{matrix}|, |{pmatrix}|, |{bmatrix}|, etc. In fact, this -% option is an alias for the conjonction of two options: -% |renew-dots| and |renew-matrix|.\footnote{The options |renew-dots|, -% |renew-matrix| and |transparent| can be fixed with the command -% |\NiceMatrixOptions| like the other options. However, they can also be fixed -% as options of the command |\usepackage| (it's an exception for these three -% specific options.)} +% +% \subsection{The thickness and the color of the rules} +% +% The environments of \pkg{nicematrix} provide a key |rules/width| to set the +% width (in fact the thickness) of the rules in the current environment. In +% fact, this key merely sets the value of the length |\arrayrulewidth|. +% +% \smallskip +% It's well known that \pkg{colortbl} provides the command |\arrayrulecolor| in +% order to specify the color of the rules. % % \smallskip +% With \pkg{nicematrix}, it's possible to specify the color of the rules even +% when \pkg{colortbl} is not loaded. For sake of compatibility, the command is +% also named |\arrayrulecolor|. The environments of \pkg{nicematrix} also +% provide a key |rules/color| to fix the color of the rules in the current +% environment. +% +% \medskip +% \begin{scope} +% \hfuzz=10cm +% \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] +% \begin{NiceTabular}{|CCC|}[~emphase#rules/color=[gray]{0.9},rules/width=1pt@] +% \hline +% rose & tulipe & lys \\ +% arum & iris & violette \\ +% muguet & dahlia & souci \\ +% \hline +% \end{NiceTabular} +% \end{BVerbatim} +% \begin{NiceTabular}{|CCC|}[rules/color=[gray]{0.9},rules/width=1pt] +% \hline +% rose & tulipe & lys \\ +% arum & iris & violette \\ +% muguet & dahlia & souci \\ +% \hline +% \end{NiceTabular} +% \end{scope} % -% \begin{itemize} -% \item The option |renew-dots|\par\nobreak +% \medskip +% If one wishes to define new specifiers for columns in order to draw vertical +% rules (for example with a specific color or thicker than the standard rules), +% he should consider the command |\OnlyMainNiceMatrix| described on +% page~\pageref{OnlyMainNiceMatrix}. % -% With this option, the commands |\ldots|, |\cdots|, |\vdots|, |\ddots|, -% |\iddots|\footnotemark[\thefniddots] and |\hdotsfor| are redefined within the -% environments provided by \pkg{nicematrix} and behave like |\Ldots|, |\Cdots|, -% |\Vdots|, |\Ddots|, |\Iddots| and |\Hdotsfor|; the command |\dots| -% (``automatic dots'' of |amsmath|) is also redefined to behave like |\Ldots|. +% +% \bigskip +% \subsection{A remark about \textbackslash cline} % -% \item The option |renew-matrix|\par\nobreak +%\label{remark-cline} % -% With this option, the environment |{matrix}| is redefined and behave like -% |{NiceMatrix}|, and so on for the five variants. -% \end{itemize} +% The horizontal and vertical rules drawn by |\hline| and the specifier +% ``\verb+|+'' make the array larger or wider by a quantity equal to the width of the rule. % -% \bigskip -% Therefore, with the option |transparent|, a classical code gives directly the -% ouput of \pkg{nicematrix}.\par\nobreak +% \smallskip +% For historical reasons, this is not the case with the command |\cline|, as +% shown by the following example. % -% \bigskip +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% \setlength{\arrayrulewidth}{2pt} +% \begin{tabular}{cccc} \hline +% A&B&C&D \\ ~emphase#\cline{2-2}@ +% A&B&C&D \\ \hline +% \end{tabular} +% \end{BVerbatim} % \begin{scope} -% \NiceMatrixOptions{transparent} +% \setlength{\arrayrulewidth}{2pt} +% \begin{tabular}[c]{cccc} +% \hline +% A&B&C&D \\ +% \cline{2-2} +% A&B&C&D \\ +% \hline +% \end{tabular} +% \end{scope} +% +% \medskip +% In the environments of \pkg{nicematrix}, this situation is corrected (it's +% still possible to go to the standard behaviour of |\cline| with the key |standard-cline|). +% +% \medskip % \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% ~emphase#\NiceMatrixOptions{transparent}@ -% \begin{pmatrix} -% 1 & \cdots & \cdots & 1 \\ -% 0 & \ddots & & \vdots \\ -% \vdots & \ddots & \ddots & \vdots \\ -% 0 & \cdots & 0 & 1 -% \end{pmatrix} +% \setlength{\arrayrulewidth}{2pt} +% \begin{NiceTabular}{CCCC} \hline +% A&B&C&D \\ ~emphase#\cline{2-2}@ +% A&B&C&D \\ \hline +% \end{NiceTabular} % \end{BVerbatim} -% $\begin{pmatrix} -% 1 & \cdots & \cdots & 1 \\ -% 0 & \ddots & & \vdots \\ -% \vdots & \ddots & \ddots & \vdots \\ -% 0 & \cdots & 0 & 1 -% \end{pmatrix}$ +% \begin{scope} +% \setlength{\arrayrulewidth}{2pt} +% \begin{NiceTabular}[c]{CCCC} +% \hline +% A&B&C&D \\ +% \cline{2-2} +% A&B&C&D \\ +% \hline +% \end{NiceTabular} % \end{scope} +% +% \subsection{The keys hlines and vlines} % -% \subsection{The labels of the dotted lines} +% The key |hlines| draws all the horizontal rules and the key |vlines| draws all +% the vertical rules. In fact, in the environments with delimiters (as +% |{pNiceMatrix}| or |{bNiceArray}|) the exteriors rules are not drawn (as +% expected). % -% The commands |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| and |\Hdotsfor| -% (and the command |\line| in the |code-after| which is described -% p.~\pageref{line-in-code-after}) accept two optional arguments specified -% by the tokens |_| and |^| for labels positionned below and above the line. The -% arguments are composed in math mode with |\scriptstyle|. -% -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $\begin{bNiceMatrix} -% 1 & \hspace*{1cm} & 0 \\[8mm] -% & ~emphase#\Ddots^{n \text{ times}}@ & \\ -% 0 & & 1 -% \end{bNiceMatrix}$ +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] +% $\begin{pNiceMatrix}[~emphase#vlines@,rules/width=0.2pt] +% 1 & 2 & 3 & 4 & 5 & 6 \\ +% 1 & 2 & 3 & 4 & 5 & 6 \\ +% 1 & 2 & 3 & 4 & 5 & 6 +% \end{pNiceMatrix}$ % \end{BVerbatim} -% $\begin{bNiceMatrix} -% 1 & \hspace*{1cm} & 0 \\[8mm] -% & \Ddots^{n \text{ times}} & \\ -% 0 & & 1 -% \end{bNiceMatrix}$ -% -% \subsection{Customization of the dotted lines} -% -% \label{customization} -% The dotted lines drawn by |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| -% and |\Hdotsfor| (and by the command |\line| in the |code-after| which is described -% p.~\pageref{line-in-code-after}) may be customized by three options (specified -% between square brackets after the command): -% \begin{itemize} -% \item |color|; -% \item |shorten|; -% \item |line-style|. -% \end{itemize} +% $\begin{pNiceMatrix}[vlines,rules/width=0.2pt] +% 1 & 2 & 3 & 4 & 5 & 6 \\ +% 1 & 2 & 3 & 4 & 5 & 6 \\ +% 1 & 2 & 3 & 4 & 5 & 6 +% \end{pNiceMatrix}$ % -% These options may also be fixed with |\NiceMatrixOptions| or at the level of a -% given environment but, in those cases, they must be prefixed by |xdots|, and, -% thus have for names: -% \begin{itemize} -% \item |xdots/color|; -% \item |xdots/shorten|; -% \item |xdots/line-style|. -% \end{itemize} +% \bigskip +% However, there is a difference between the key |vlines| and the use of +% the specifier ``"|"'' in the preamble of the environment: the rules drawn by +% |vlines| completely cross the double-rules drawn by |\hline\hline| (you don't +% need \pkg{hhline}). % -% For the clarity of the explanations, we will use those names. +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=11.5cm] +% $\begin{NiceMatrix}[~emphase#vlines@] \hline +% a & b & c & d \\ \hline \hline +% 1 & 2 & 3 & 4 \\ +% 1 & 2 & 3 & 4 \\ \hline +% \end{NiceMatrix}$ +% \end{BVerbatim} +% $\begin{NiceMatrix}[vlines] +% \hline +% a & b & c & d \\ +% \hline \hline +% 1 & 2 & 3 & 4 \\ +% 1 & 2 & 3 & 4 \\ +% \hline +% \end{NiceMatrix}$ % -% \bigskip -% \textbf{The option xdots/color}\par\nobreak % -% \smallskip -% The option |xdots/color| fixes the color or the dotted line. However, one should -% remark that the dotted lines drawn in the exterior rows and columns have a -% special treatment: cf. p.~\pageref{exterior}. -% -% \bigskip -% \textbf{The option xdots/shorten}\par\nobreak +% \bigskip +% If you use \pkg{booktabs} (which provides |\toprule|, |midrule|, |bottomrule|, +% etc.) and you really want to draw vertical rules (something opposed to the +% spirit of \pkg{booktabs}), you should remark that the key |vlines| in +% compatible with \pkg{booktabs}. % -% \smallskip -% The option |xdots/shorten| fixes the margin of both extremities of the line. -% The name is derived from the options ``|shorten >|'' and ``|shorten <|'' of -% Tikz but one should notice that \pkg{nicematrix} only provides -% |xdots/shorten|. The initial value of this parameter is 0.3~em (it is -% recommanded to use a unit of length dependent of the current font). -% -% \bigskip -% \textbf{The option xdots/line-style}\par\nobreak -% -% \smallskip -% It should be pointed that, by default, the lines drawn by Tikz with the -% parameter |dotted| are composed of square dots (and not rounded -% ones).\footnote{The first reason of this behaviour is that the \textsc{pdf} -% format includes a description for dashed lines. The lines specified with this -% descriptor are displayed very efficiently by the \textsc{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 \textsc{pdf} file.} -% -% \begin{BVerbatim}[baseline=c,boxwidth=9cm] -% \tikz \draw [dotted] (0,0) -- (5,0) ; +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=11.5cm] +% $\begin{NiceMatrix}[~emphase#vlines@] \toprule +% a & b & c & d \\ \midrule +% 1 & 2 & 3 & 4 \\ +% 1 & 2 & 3 & 4 \\ \bottomrule +% \end{NiceMatrix}$ % \end{BVerbatim} -% \tikz \draw [dotted] (0,0) -- (5,0) ; +% $\begin{NiceMatrix}[vlines] +% \toprule +% a & b & c & d \\ +% \midrule +% 1 & 2 & 3 & 4 \\ +% 1 & 2 & 3 & 4 \\ +% \bottomrule +% \end{NiceMatrix}$ % -% \medskip -% In order to provide lines with rounded dots in the style of those provided by -% |\ldots| (at least with the \emph{Computer Modern} fonts), the package -% \pkg{nicematrix} embeds its own system to draw a dotted line (and this system -% uses \textsc{pgf} and not Tikz). This style is called |standard| and that's -% the initial value of the parameter |xdots/line-style|. % -% However (when Tikz is loaded) it's possible to use for |xdots/line-style| any style -% provided by Tikz, that is to say any sequence of options provided by Tikz for -% the Tizk pathes (with the exception of ``|color|'', ``|shorten >|'' and -% ``|shorten <|''). +% \subsection{The key hvlines} +% \label{hvlines} +% +% The key |hvlines| draws all the vertical and horizontal rules \emph{excepted +% in the blocks}.\footnote{In fact, when the key |hvlines| is in force, the +% rules are also not drawn in the virtual blocks delimited by cells relied par +% dotted lines (cf. p. \pageref{dotted-and-hvlines}).} % % \medskip -% Here is for example a tridiagonal matrix with the style |loosely dotted|:\par\nobreak +% \begin{Verbatim} +% \setlength{\arrayrulewidth}{1pt} +% \begin{NiceTabular}{CCCC}[~emphase#hvlines@,rules/color=blue] +% rose & tulipe & marguerite & dahlia \\ +% violette & \Block{2-2}{\LARGE\color{blue} fleurs} & & souci \\ +% pervenche & & & lys \\ +% arum & iris & jacinthe & muguet +% \end{NiceTabular} +% \end{Verbatim} +% +% \begin{center} +% \setlength{\arrayrulewidth}{1pt} +% \begin{NiceTabular}{CCCC}[hvlines,rules/color=blue] +% rose & tulipe & marguerite & dahlia \\ +% violette & \Block{2-2}{\LARGE\color{blue} fleurs} & & souci \\ +% pervenche & & & lys \\ +% arum & iris & jacinthe & muguet +% \end{NiceTabular} +% \end{center} +% +% +% +% \subsection{La commande \textbackslash diagbox} +% +% The command |\diagbox| (inspired by the package \pkg{diagbox}), allows, when +% it is used in a cell, to slash that cell diagonally downwards.\footnote{The +% author of this document considers that type of construction as graphically +% poor.}. % % \medskip -% \begin{BVerbatim}[baseline=c] -% $\begin{pNiceMatrix}[nullify-dots,~emphase#xdots/line-style=loosely dotted@] -% a & b & 0 & & \Cdots & 0 \\ -% b & a & b & \Ddots & & \Vdots \\ -% 0 & b & a & \Ddots & & \\ -% & \Ddots & \Ddots & \Ddots & & 0 \\ -% \Vdots & & & & & b \\ -% 0 & \Cdots & & 0 & b & a -% \end{pNiceMatrix}$ +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% $\begin{NiceArray}{*{5}{C}}[hvlines] +% ~emphase#\diagbox{x}{y}@ & e & a & b & c \\ +% e & e & a & b & c \\ +% a & a & e & c & b \\ +% b & b & c & e & a \\ +% c & c & b & a & e +% \end{NiceArray}$ % \end{BVerbatim} +% $\begin{NiceArray}{*{5}{C}}[hvlines] +% \diagbox{x}{y} & e & a & b & c \\ +% e & e & a & b & c \\ +% a & a & e & c & b \\ +% b & b & c & e & a \\ +% c & c & b & a & e +% \end{NiceArray}$ % % -% \[\begin{pNiceMatrix}[nullify-dots,xdots/line-style=loosely dotted] -% a & b & 0 & & \Cdots & 0 \\ -% b & a & b & \Ddots & & \Vdots \\ -% 0 & b & a & \Ddots & & \\ -% & \Ddots & \Ddots & \Ddots & & 0 \\ -% \Vdots & & & & & b \\ -% 0 & \Cdots & & 0 & b & a -% \end{pNiceMatrix}\] % +% \subsection{Dotted rules} % -% -% \section{The PGF/Tikz nodes created by nicematrix} -% -% \label{name} % -% The package \pkg{nicematrix} creates a PGF/Tikz node for each (non-empty) cell -% of the considered array. These nodes are used to draw the dotted lines between -% the cells of the matrix. However, the user may wish to use directly these -% nodes. It's possible (if Tikz has been loaded\footnote{We remind that, since -% the version 3.13, \pkg{nicematrix} doesn't load Tikz by default by only -% \textsc{pgf} (Tikz is a layer over \textsc{pfg}).}). First, the user have to -% give a name to the array (with the key called |name|). Then, the nodes are -% accessible through the names ``\textsl{name}-$i$-$j$'' where \textsl{name} is -% the name given to the array and $i$ and $j$ the numbers of the row and the -% column of the considered cell. -% +% In the environments of the package \pkg{nicematrix}, it's possible to use +% the command |\hdottedline| (provided by \pkg{nicematrix}) which is a +% counterpart of the classical commands |\hline| and |\hdashline| (the latter is +% a command of \pkg{arydshln}). +% % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% $\begin{pNiceMatrix}[name=~emphase#mymatrix@] -% 1 & 2 & 3 \\ -% 4 & 5 & 6 \\ -% 7 & 8 & 9 -% \end{pNiceMatrix}$ -% \tikz[remember picture,overlay] -% \draw ~emphase#(mymatrix-2-2)@ circle (2mm) ; +% \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] +% \begin{pNiceMatrix} +% 1 & 2 & 3 & 4 & 5 \\ +% ~emphase#\hdottedline@ +% 6 & 7 & 8 & 9 & 10 \\ +% 11 & 12 & 13 & 14 & 15 +% \end{pNiceMatrix} % \end{BVerbatim} -% $\begin{pNiceMatrix}[name=mymatrix] -% 1 & 2 & 3 \\ -% 4 & 5 & 6 \\ -% 7 & 8 & 9 +% $\begin{pNiceMatrix} +% 1 & 2 & 3 & 4 & 5 \\ +% \hdottedline +% 6 & 7 & 8 & 9 & 10 \\ +% 11 & 12 & 13 & 14 & 15 % \end{pNiceMatrix}$ -% \tikz[remember picture,overlay] -% \draw (mymatrix-2-2) circle (2mm) ; % -% \medskip -% Don't forget the options |remember picture| and |overlay|. % % \bigskip -% In the following example, we have underlined all the nodes of the matrix. -% \[\begin{pNiceMatrix}[ -% code-after = {\begin{tikzpicture} -% [every node/.style = {blend mode = multiply, -% fill = red!15, -% inner sep = 0 pt }] -% \node [fit = (1-1)] {} ; -% \node [fit = (1-3)] {} ; -% \node [fit = (2-2)] {} ; -% \node [fit = (3-1)] {} ; -% \node [fit = (3-3)] {} ; -% \node [fit = (1-2)] {} ; -% \node [fit = (2-1)] {} ; -% \node [fit = (2-3)] {} ; -% \node [fit = (3-2)] {} ; -% \end{tikzpicture}}] -% a & a + b & a + b + c \\ -% a & a & a + b \\ -% a & a & a -% \end{pNiceMatrix}\] +% In the environments with an explicit preamble (like |{NiceTabular}|, +% |{NiceArray}|, etc.), it's possible to draw a vertical dotted line with the +% specifier ``|:|''. % +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] +% \left(\begin{NiceArray}{CCCC~emphase#:@C} +% 1 & 2 & 3 & 4 & 5 \\ +% 6 & 7 & 8 & 9 & 10 \\ +% 11 & 12 & 13 & 14 & 15 +% \end{NiceArray}\right) +% \end{BVerbatim} +% $\left(\begin{NiceArray}{CCCC:C} +% 1 & 2 & 3 & 4 & 5 \\ +% 6 & 7 & 8 & 9 & 10 \\ +% 11 & 12 & 13 & 14 & 15 +% \end{NiceArray}\right)$ % % \bigskip -% In fact, the package \pkg{nicematrix} can create ``extra nodes'': the ``medium -% nodes'' and the ``large nodes''. The first ones -% are created with the option |create-medium-nodes| and the second ones with the -% option |create-large-nodes|.\footnote{There is also an option -% |create-extra-nodes| which is an alias for the conjonction of -% |create-medium-nodes| and |create-large-nodes|.} +% It's possible to change in \pkg{nicematrix} the letter used to specify a +% vertical dotted line with the option |letter-for-dotted-lines| available in +% |\NiceMatrixOptions|. +% +% \bigskip +% \emph{Remark} : In the package \pkg{array} (on which the package +% \pkg{nicematrix} relies), horizontal and vertical rules make the array larger +% or wider by a quantity equal to the width of the rule\footnote{In fact, this +% is true only for |\hline| and ``"|"'' but not for |\cline|.}. In +% \pkg{nicematrix}, the dotted lines drawn by |\hdottedline| and ``|:|'' do +% likewise. +% +% +% +%\section{The color of the rows and columns} +% +% With the classical package \pkg{colortbl}, it's possible to color the cells, +% rows and columns of a tabular. However, the resulting \textsc{pdf} is not +% always perfectly displayed by the \textsc{pdf} viewers, in particular in +% conjonction with rules. With some \textsc{pdf} viewers, some vertical rules +% seem to vanish. On the other side, some thin horizontal white lines may appear +% in some circonstances. +% % % \medskip -% The names of the ``medium nodes'' are constructed by adding the suffix -% ``|-medium|'' to the names of the ``normal nodes''. In the following example, -% we have underlined the ``medium nodes''. We consider that this example is -% self-explanatory. -% \[\begin{pNiceMatrix}[ -% create-medium-nodes, -% code-after = {\begin{tikzpicture} -% [every node/.style = {fill = red!15, -% blend mode = multiply, -% inner sep = 0pt}, -% name suffix = -medium] -% \node [fit = (1-1)] {} ; -% \node [fit = (1-2)] {} ; -% \node [fit = (1-3)] {} ; -% \node [fit = (2-1)] {} ; -% \node [fit = (2-2)] {} ; -% \node [fit = (2-3)] {} ; -% \node [fit = (3-1)] {} ; -% \node [fit = (3-2)] {} ; -% \node [fit = (3-3)] {} ; -% \end{tikzpicture}}] -% a & a + b & a + b + c \\ -% a & a & a + b \\ -% a & a & a -% \end{pNiceMatrix}\] -% +% The package \pkg{nicematrix} provides similar tools which do not present these +% drawbacks. It provides a key |code-before|\footnote{There is also a key +% |code-after| : see p.~\pageref{code-after}.} for some code which will be +% executed \emph{before} the drawing of the tabular. In this |code-before|, new +% commands are available: |\cellcolor|, |\rectanglecolor|, |\rowcolor|, +% |\columncolor|, |\rowcolors| and |\chessboardcolors|. +% \label{code-before} % % \medskip -% 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.\footnote{There is no ``large nodes'' created in the exterior -% rows and columns (for these rows and columns, cf. p.~\pageref{exterior}).} -% -% \[\begin{pNiceMatrix}[ -% create-large-nodes, -% code-after = {\begin{tikzpicture} -% [every node/.style = {blend mode = multiply, -% inner sep = 0pt}, -% name suffix = -large] -% \node [fit = (1-1),fill = red!15] {} ; -% \node [fit = (1-3),fill = red!15] {} ; -% \node [fit = (2-2),fill = red!15] {} ; -% \node [fit = (3-1),fill = red!15] {} ; -% \node [fit = (3-3),fill = red!15] {} ; -% \node [fit = (1-2),fill = blue!15] {} ; -% \node [fit = (2-1),fill = blue!15] {} ; -% \node [fit = (2-3),fill = blue!15] {} ; -% \node [fit = (3-2),fill = blue!15] {} ; -% \end{tikzpicture}}] -% a & a + b & a + b + c \\ -% a & a & a + b \\ -% a & a & a -% \end{pNiceMatrix}\] +% These commands are independent of \pkg{colortbl}.\footnote{Thus, it's possible +% to coloror the rules, the cells, the rows, the columns, etc. without loading \pkg{colortbl}.} % -% % \medskip -% 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 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|.\footnote{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.} -% \[\begin{pNiceMatrix}[ -% create-large-nodes,left-margin,right-margin, -% code-after = {\begin{tikzpicture} -% [every node/.style = {blend mode = multiply, -% inner sep = 0pt}, -% name suffix = -large] -% \node [fit = (1-1),fill = red!15] {} ; -% \node [fit = (1-3),fill = red!15] {} ; -% \node [fit = (2-2),fill = red!15] {} ; -% \node [fit = (3-1),fill = red!15] {} ; -% \node [fit = (3-3),fill = red!15] {} ; -% \node [fit = (1-2),fill = blue!15] {} ; -% \node [fit = (2-1),fill = blue!15] {} ; -% \node [fit = (2-3),fill = blue!15] {} ; -% \node [fit = (3-2),fill = blue!15] {} ; -% \end{tikzpicture}}] -% a & a + b & a + b + c \\ -% a & a & a + b \\ -% a & a & a -% \end{pNiceMatrix}\] +% All these commands accept an optional argument (between square brackets and +% in first position) which is the color model for the specification of the colors. % % \medskip -% 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. -% \[\begin{pNiceMatrix}[ -% create-large-nodes,margin,extra-margin=3pt, -% code-after = {\begin{tikzpicture} -% [every node/.style = {blend mode = multiply, -% inner sep = 0 pt}, -% name suffix = -large] -% \node [fit = (1-1),fill = red!15] {} ; -% \node [fit = (1-3),fill = red!15] {} ; -% \node [fit = (2-2),fill = red!15] {} ; -% \node [fit = (3-1),fill = red!15] {} ; -% \node [fit = (3-3),fill = red!15] {} ; -% \node [fit = (1-2),fill = blue!15] {} ; -% \node [fit = (2-1),fill = blue!15] {} ; -% \node [fit = (2-3),fill = blue!15] {} ; -% \node [fit = (3-2),fill = blue!15] {} ; -% \end{tikzpicture}}] -% a & a + b & a + b + c \\ -% a & a & a + b \\ -% a & a & a -% \end{pNiceMatrix}\] +% \begin{itemize} +% \item The command |\cellcolor| takes its name from the command |\cellcolor| of +% \pkg{colortbl}. % -% \medskip -% In this case, if we want a control over the height of the rows, we can add a -% |\strut| in each row of the array. -% \[\begin{pNiceMatrix}[ -% create-large-nodes,left-margin,right-margin,extra-right-margin=3pt, -% extra-left-margin=3pt, -% code-after = {\begin{tikzpicture} -% [every node/.style = {blend mode = multiply, -% inner sep = 0 pt}, -% name suffix = -large] -% \node [fit = (1-1),fill = red!15] {} ; -% \node [fit = (1-3),fill = red!15] {} ; -% \node [fit = (2-2),fill = red!15] {} ; -% \node [fit = (3-1),fill = red!15] {} ; -% \node [fit = (3-3),fill = red!15] {} ; -% \node [fit = (1-2),fill = blue!15] {} ; -% \node [fit = (2-1),fill = blue!15] {} ; -% \node [fit = (2-3),fill = blue!15] {} ; -% \node [fit = (3-2),fill = blue!15] {} ; -% \end{tikzpicture}}] -% \strut a & a + b & a + b + c \\ -% \strut a & a & a + b \\ -% \strut a & a & a -% \end{pNiceMatrix}\] +% This command takes in mandatory arguments a color and a list of cells, each of +% which with the format $i$-$j$ where $i$ is the number of row and $j$ the +% number of colummn of the cell. % -% \bigskip -% We explain below how to fill the nodes created by \pkg{nicematrix} (cf. p. -% \pageref{highlight}). % -% \section{The code-after} +% \medskip +% \begin{scope} +% \hfuzz=10cm +% \begin{BVerbatim}[boxwidth=10cm,baseline=c] +% \begin{NiceTabular}{|C|C|C|}[code-before = +% ~emphase#\cellcolor{red!15}{3-1,2-2,1-3}@] +% \hline +% a & b & c \\ \hline +% e & f & g \\ \hline +% h & i & j \\ \hline +% \end{NiceTabular} +% \end{BVerbatim} +% \begin{NiceTabular}{|C|C|C|}[hvlines, code-before = +% \cellcolor{red!15}{3-1,2-2,1-3}] +% \hline +% a & b & c \\ \hline +% e & f & g \\ \hline +% h & i & j \\ \hline +% \end{NiceTabular} +% \end{scope} +% +% \bigskip +% \item 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. % -% \label{code-after} -% The option |code-after| may be used to give some code that will be excuted -% after the construction of the matrix (and thus after the construction of -% all the nodes). +% \medskip +% \begin{scope} +% \hfuzz=10cm +% \begin{BVerbatim}[boxwidth=10cm,baseline=c] +% \begin{NiceTabular}{|C|C|C|}[code-before = +% ~emphase#\rectanglecolor{blue!15}{2-2}{3-3}@] +% \hline +% a & b & c \\ \hline +% e & f & g \\ \hline +% h & i & j \\ \hline +% \end{NiceTabular} +% \end{BVerbatim} +% \begin{NiceTabular}{|C|C|C|}[hvlines, code-before = +% \rectanglecolor{blue!15}{2-2}{3-3}] +% \hline +% a & b & c \\ \hline +% e & f & g \\ \hline +% h & i & j \\ \hline +% \end{NiceTabular} +% \end{scope} +% % -% \smallskip -% \textbf{If Tikz is loaded}\footnote{We remind that, since the version 3.13, -% \pkg{nicematrix} doesn't load Tikz by default but only \textsc{pgf} (Tikz is a -% layer over \textsc{pfg}).}, one may access to that nodes with classical Tikz -% instructions. The nodes should be designed as $i$-$j$ (without the prefix -% corresponding to the name of the environment). -% -% Moreover, a special command, called |\line|, is available to draw directly -% dotted lines between nodes. It may be used, for example, to draw a dotted line -% between two adjacents cells. \label{line-in-code-after} % +% \bigskip +% \item The command |\rowcolor| takes its name from the command |\rowcolor| of +% \pkg{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). +% % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% \NiceMatrixOptions{xdots/shorten = 0.6 em} -% \begin{pNiceMatrix}[~emphase#code-after=\line{2-2}{3-3}@] -% I & 0 & \Cdots &0 \\ -% 0 & I & \Ddots &\Vdots\\ -% \Vdots &\Ddots & I &0 \\ -% 0 &\Cdots & 0 &I -% \end{pNiceMatrix} -% \end{BVerbatim} % \begin{scope} -% \NiceMatrixOptions{xdots/shorten = 0.6 em} -% $\begin{pNiceMatrix}[code-after=\line{2-2}{3-3}] -% I & 0 & \Cdots &0 \\ -% 0 & I & \Ddots &\Vdots\\ -% \Vdots &\Ddots & I &0 \\ -% 0 &\Cdots & 0 &I -% \end{pNiceMatrix}$ +% \hfuzz = 10cm +% \begin{BVerbatim}[boxwidth=9cm,baseline=c] +% $\begin{NiceArray}{LLL}[hvlines, ~emphase#code-before = \rowcolor{red!15}{1,3-5,8-}@] +% a_1 & b_1 & c_1 \\ +% a_2 & b_2 & c_2 \\ +% a_3 & b_3 & c_3 \\ +% a_4 & b_4 & c_4 \\ +% a_5 & b_5 & c_5 \\ +% a_6 & b_6 & c_6 \\ +% a_7 & b_7 & c_7 \\ +% a_8 & b_8 & c_8 \\ +% a_9 & b_9 & c_9 \\ +% a_{10} & b_{10} & c_{10} \\ +% \end{NiceArray}$ +% \end{BVerbatim} +% $\begin{NiceArray}{LLL}[baseline=4,hvlines, code-before = \rowcolor{red!15}{1,3-5,8-}] +% a_1 & b_1 & c_1 \\ +% a_2 & b_2 & c_2 \\ +% a_3 & b_3 & c_3 \\ +% a_4 & b_4 & c_4 \\ +% a_5 & b_5 & c_5 \\ +% a_6 & b_6 & c_6 \\ +% a_7 & b_7 & c_7 \\ +% a_8 & b_8 & c_8 \\ +% a_9 & b_9 & c_9 \\ +% a_{10} & b_{10} & c_{10} \\ +% \end{NiceArray}$ % \end{scope} +% % +% \bigskip +% \item The command |\columncolor| takes its name from the command +% |\columncolor| of \pkg{colortbl}. Its syntax is similar to the syntaxe of +% |\rowcolor|. +% +% \bigskip +% \item The command |\rowcolors| (with a \emph{s}) takes its name from the +% command |\rowcolors| of \pkg{xcolor}\footnote{The command |\rowcolors| of +% \pkg{color} is available when \pkg{xcolor} is loaded with the +% option~|table|.}. The \emph{s} emphasizes the fact that there is \emph{two} +% colors. This command colors alternately the rows of the tabular, beginning +% with the row whose number is given in first (mandatory) argument. The two +% other (mandatory) arguments are the colors. +% % \medskip -% For the readability 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|. For an example, cf. -% p.~\pageref{example-CodeAfter}. +% \begin{scope} +% \hfuzz=10cm +% \begin{BVerbatim}[baseline=c,boxwidth=9cm] +% \begin{NiceTabular}{LR}[hlines,code-before = ~emphase#\rowcolors{1}{blue!10}{}@] +% John & 12 \\ +% Stephen & 8 \\ +% Sarah & 18 \\ +% Ashley & 20 \\ +% Henry & 14 \\ +% Madison & 15 +% \end{NiceTabular} +% \end{BVerbatim} +% \begin{NiceTabular}{LR}[hlines,code-before = \rowcolors{1}{blue!10}{},baseline=3] +% John & 12 \\ +% Stephen & 8 \\ +% Sarah & 18 \\ +% Ashley & 20 \\ +% Henry & 14 \\ +% Madison & 15 +% \end{NiceTabular} +% \end{scope} +% +% \bigskip +% \item The command |\chessboardcolors| takes in mandatory arguments two colors +% and colors the cells of the tabular in quincunx with these colors. % +% \medskip +% \begin{scope} +% \hfuzz=10cm +% \begin{BVerbatim}[baseline=c,boxwidth=9cm] +% $\begin{pNiceMatrix}[R,margin, ~emphase#code-before=\chessboardcolors{red!15}{blue!15}@] +% 1 & -1 & 1 \\ +% -1 & 1 & -1 \\ +% 1 & -1 & 1 +% \end{pNiceMatrix}$ +% \end{BVerbatim} +% $\begin{pNiceMatrix}[R,baseline=1, margin, code-before = \chessboardcolors{red!15}{blue!15}] +% 1 & -1 & 1 \\ +% -1 & 1 & -1 \\ +% 1 & -1 & 1 +% \end{pNiceMatrix}$ +% \end{scope} % -% \section{The environments \{NiceArray\} and \{NiceTabular\}} -% \label{NiceArray} +% \medskip +% We have used the key |R| which aligns all the columns rightwards (cf. p.~\pageref{key-R}). +% \end{itemize} % -% The environments |{NiceArray}| and |{NiceTabular}| are similar to the -% environments |{array}| and |{tabular}|. The mandatory argument is the preamble -% of the array. However, for technical reasons, in this preamble, the user must -% use the letters |L|, |C| and~|R|\footnote{The column types |L|, |C| and |R| -% are defined locally inside |{NiceArray}| with |\newcolumntype| of \pkg{array}. -% This definition overrides an eventual previous definition.} instead of |l|, -% |c| and |r|. In a command |\multicolumn|, one should also use the letters |L|, -% |C|, |R|. % -% It's possible to use the constructions |p{...}|, |m{...}|, |b{...}|, -% |w{...}{...}|, |W{...}{...}|, "|", |>{...}|, |<{...}|, |@{...}|, |!{...}| and -% |*{n}{...}|. However, in the environment |{NiceArray}| (and its variants), the -% content of the columns of type |w| or |W| is composed in math mode (in -% |{array}| of \pkg{array}, they are composed in text mode). % % \bigskip -% The package \pkg{nicematrix} provides also the variants |{pNiceArray}|, -%|{vNiceArray}|, |{VNiceArray}|, |{bNiceArray}| and |{BNiceArray}|. +% One should remark that these commands are compatible with the commands de +% \pkg{booktabs} (|\toprule|, |\midrule|, |\bottomrule|, etc). +% +% \medskip +% \begin{scope} +% \hfuzz=10cm +% \begin{BVerbatim}[baseline=c,boxwidth=8.5cm] +% \begin{NiceTabular}[c]{LSSSS}% +% [code-before = \rowcolor{red!15}{1-2} \rowcolors{3}{blue!15}{}] +% ~emphase#\toprule@ +% \Block{2-1}{Product} \\ +% \Block{1-3}{dimensions (cm)} & & & +% \Block{2-1}{\rotate Price} \\ +% ~emphase#\cmidrule(rl){2-4}@ +% & L & l & h \\ +% ~emphase#\midrule@ +% small & 3 & 5.5 & 1 & 30 \\ +% standard & 5.5 & 8 & 1.5 & 50.5 \\ +% premium & 8.5 & 10.5 & 2 & 80 \\ +% extra & 8.5 & 10 & 1.5 & 85.5 \\ +% special & 12 & 12 & 0.5 & 70 \\ +% ~emphase#\bottomrule@ +% \end{NiceTabular} +% \end{BVerbatim} +% \begin{NiceTabular}[c]{LSSSS}[code-before = \rowcolor{red!15}{1-2} +% \rowcolors{3}{blue!15}{}] +% \toprule +% \Block{2-1}{Product} & +% \Block{1-3}{dimensions (cm)} & & & +% \Block{2-1}{\rotate Price} \\ +% \cmidrule(rl){2-4} +% & L & l & h \\ +% \midrule +% small & 3 & 5.5 & 1 & 30 \\ +% standard & 5.5 & 8 & 1.5 & 50.5 \\ +% premium & 8.5 & 10.5 & 2 & 80 \\ +% extra & 8.5 & 10 & 1.5 & 85.5 \\ +% special & 12 & 12 & 0.5 & 70 \\ +% \bottomrule +% \end{NiceTabular} +% \end{scope} % -% \bigskip -% Of course, one of the benefits of |{pNiceArray}| over |{pNiceMatrix}| is the -% possibility of drawing vertical rules: +% \medskip +% We have used the type of column |S| of \pkg{siunitx}. % -%\bigskip -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $\left[\begin{NiceArray}{CCCC|C} -% a_1 & ? & \Cdots & ? & ? \\ -% 0 & & \Ddots & \Vdots & \Vdots\\ -% \Vdots & \Ddots & \Ddots & ? \\ -% 0 & \Cdots & 0 & a_n & ? -% \end{NiceArray}\right]$ -% \end{BVerbatim} -% $\left[\begin{NiceArray}{CCCC|C} -% a_1 & ? & \Cdots & ? & ? \\ -% 0 & & \Ddots & \Vdots & \Vdots\\ -% \Vdots & \Ddots & \Ddots & ? \\ -% 0 & \Cdots & 0 & a_n & ? -% \end{NiceArray}\right]$ +% \section{The width of the columns} +% \label{width} +% +% In the environments with an explicit preamble (like |{NiceTabular}|, +% |{NiceArray}|, etc.), it's possible to fix the width of a given column with +% the standard letters |w| and |W| of the package \pkg{array}. In +% |{NiceTabular}|, the cells of such columns are composed in texte mode but, in +% |{NiceArray}|, |{pNiceArray}|, etc., they are composed in math mode (whereas, +% in |{array}| of \pkg{array}, they are composed in text mode). +% +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=9cm] +% \begin{NiceTabular}{~emphase#Wc{2cm}@CC}[hvlines] +% Paris & New York & Madrid \\ +% Berlin & London & Roma \\ +% Rio & Tokyo & Oslo +% \end{NiceTabular} +% \end{BVerbatim} +% \begin{NiceTabular}{Wc{2cm}CC}[hvlines] +% Paris & New York & Madrid \\ +% Berlin & London & Roma \\ +% Rio & Tokyo & Oslo +% \end{NiceTabular} % -% \bigskip -% Another benefit is the possibility of using different alignments of columns. % % \bigskip +% In the environments of \pkg{nicematrix}, it's also possible to fix the \emph{minimal} +% width of all the columns of an array directly with the key |columns-width|. +% +% \medskip % \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $\begin{pNiceArray}{LCR} -% a_{11} & \Cdots & a_{1n} \\ -% a_{21} & & a_{2n} \\ -% \Vdots & & \Vdots \\ -% a_{n-1,1} & \Cdots & a_{n-1,n} -% \end{pNiceArray}$ +% $\begin{pNiceMatrix}[~emphase#columns-width = 1cm@] +% 1 & 12 & -123 \\ +% 12 & 0 & 0 \\ +% 4 & 1 & 2 +% \end{pNiceMatrix}$ % \end{BVerbatim} -% $\begin{pNiceArray}{LCR} -% a_{11} & \Cdots & a_{1n} \\ -% a_{21} & & a_{2n} \\ -% \Vdots & & \Vdots \\ -% a_{n-1,1} & \Cdots & a_{n-1,n} -% \end{pNiceArray}$ +% $\begin{pNiceMatrix}[columns-width = 1cm] +% 1 & 12 & -123 \\ +% 12 & 0 & 0 \\ +% 4 & 1 & 2 +% \end{pNiceMatrix}$ % +% \medskip +% 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). % % \bigskip -% 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. +% 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.\footnote{The result is achieved with only one compilation (but Tikz +% will have written informations in the |.aux| file and a message requiring a +% second compilation will appear).}\par\nobreak % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% $\begin{~emphase#NiceArrayWithDelims@} -% {\downarrow}{\uparrow}{CCC}[margin] -% 1 & 2 & 3 \\ -% 4 & 5 & 6 \\ -% 7 & 8 & 9 -% \end{~emphase#NiceArrayWithDelims@}$ +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% $\begin{pNiceMatrix}[~emphase#columns-width = auto@] +% 1 & 12 & -123 \\ +% 12 & 0 & 0 \\ +% 4 & 1 & 2 +% \end{pNiceMatrix}$ % \end{BVerbatim} -% $\begin{NiceArrayWithDelims} -% {\downarrow}{\uparrow}{CCC}[margin] -% 1 & 2 & 3 \\ -% 4 & 5 & 6 \\ -% 7 & 8 & 9 -% \end{NiceArrayWithDelims}$ -% -% +% $\begin{pNiceMatrix}[columns-width = auto] +% 1 & 12 & -123 \\ +% 12 & 0 & 0 \\ +% 4 & 1 & 2 +% \end{pNiceMatrix}$ +% % \bigskip -% \section{The vertical position of the arrays} -% -% The package \pkg{nicematrix} provides a option |baseline| for the vertical -% position of the arrays. This option takes as value an integer which is the -% number of the row on which the array will be aligned. +% Without surprise, it's possible to fix the minimal width of the columns of all +% the matrices of a current scope with the command +% |\NiceMatrixOptions|.\par\nobreak % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=9cm] -% $A = \begin{pNiceMatrix}[~emphase#baseline=2@] -% \frac{1}{\sqrt{1+p^2}} & p & 1-p \\ -% 1 & 1 & 1 \\ -% 1 & p & 1+p +% \begin{BVerbatim}[baseline=c,boxwidth=8.5cm] +% ~emphase#\NiceMatrixOptions{columns-width=10mm}@ +% $\begin{pNiceMatrix} +% a & b \\ c & d +% \end{pNiceMatrix} +% = +% \begin{pNiceMatrix} +% 1 & 1245 \\ 345 & 2 % \end{pNiceMatrix}$ % \end{BVerbatim} -% $A = \begin{pNiceMatrix}[baseline=2] -% \frac{1}{\sqrt{1+p^2}} & p & 1-p \\ -% 1 & 1 & 1 \\ -% 1 & p & 1+p +% \begin{scope} +% \NiceMatrixOptions{columns-width=10mm} +% $\begin{pNiceMatrix} +% a & b \\ +% c & d +% \end{pNiceMatrix} +% = +% \begin{pNiceMatrix} +% 1 & 1245 \\ +% 345 & 2 % \end{pNiceMatrix}$ +% \end{scope} % % +% \bigskip +% But 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-width|\footnote{At this time, this is the only usage of the +% environment |{NiceMatrixBlock}| but it may have other usages in the future.}. +% The environment |{NiceMatrixBlock}| has no direct link with the command +% |\Block| presented previously in this document (cf.~p.~\pageref{Block}). +% % \medskip -% It's also possible to use the option |baseline| with one of the special values -% |t|, |c| or |b|. These letters may also be used absolutely like the option of -% the environment |{array}| of \pkg{array}. The initial value of |baseline| is~|c|. -% +% \begin{BVerbatim}[baseline=c,boxwidth=8.5cm] +% ~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@ +% $\begin{array}{c} +% \begin{bNiceMatrix} +% 9 & 17 \\ -2 & 5 +% \end{bNiceMatrix} \\ \\ +% \begin{bNiceMatrix} +% 1 & 1245345 \\ 345 & 2 +% \end{bNiceMatrix} +% \end{array}$ +% ~emphase#\end{NiceMatrixBlock}@ +% \end{BVerbatim} +% \begin{NiceMatrixBlock}[auto-columns-width] +% $\begin{array}{c} +% \begin{bNiceMatrix} +% 9 & 17 \\ -2 & 5 +% \end{bNiceMatrix} \\ \\ +% \begin{bNiceMatrix} +% 1 & 1245345 \\ 345 & 2 +% \end{bNiceMatrix} +% \end{array}$ +% \end{NiceMatrixBlock} % % \medskip -% In the following example, we use the option |t| (equivalent to |baseline=t|) -% immediately after an |\item| of list. One should remark that the presence of -% a |\hline| at the beginning of the array doesn't prevent the alignment of the -% baseline with the baseline of the first row (with |{array}| of \pkg{array}, -% one must use |\firsthline|\footnote{It's also possible to use |\firsthline| -% with |{NiceArray}|.}). +% \textbf{Several compilations may be necessary to achieve the job.} % -% \smallskip -% \begin{BVerbatim}[baseline=c,boxwidth=9cm] -% \begin{enumerate} -% \item an item -% \smallskip -% \item \renewcommand{\arraystretch}{1.2} -% $\begin{NiceArray}~emphase#[t]@{LCCCCCC} -% \hline -% n & 0 & 1 & 2 & 3 & 4 & 5 \\ -% u_n & 1 & 2 & 4 & 8 & 16 & 32 -% \hline -% \end{NiceArray}$ -% \end{enumerate} -% \end{BVerbatim} -% \begin{minipage}{5cm} -% \begin{enumerate} -% \item an item -% \smallskip -% \item \renewcommand{\arraystretch}{1.2} -% $\begin{NiceArray}[t]{LCCCCCC} -% \hline -% n & 0 & 1 & 2 & 3 & 4 & 5 \\ -% u_n & 1 & 2 & 4 & 8 & 16 & 32 \\ -% \hline -% \end{NiceArray}$ -% \end{enumerate} -% \end{minipage} -% -% \medskip -% However, it's also possible to use the tools of \pkg{booktabs}: |\toprule|, -% |\bottomrule| and |\midrule|.\par\nobreak % -% \smallskip -% \begin{BVerbatim}[baseline=c,boxwidth=9cm] -% \begin{enumerate} -% \item an item -% \smallskip -% \item -% $\begin{NiceArray}[t]{LCCCCCC} -% ~emphase#\toprule@ -% n & 0 & 1 & 2 & 3 & 4 & 5 \\ -% ~emphase#\midrule@ -% u_n & 1 & 2 & 4 & 8 & 16 & 32 -% ~emphase#\bottomrule@ -% \end{NiceArray}$ -% \end{enumerate} -% \end{BVerbatim} -% \begin{minipage}{5cm} -% \begin{enumerate} -% \item an item -% \smallskip -% \item -% $\begin{NiceArray}[t]{LCCCCCC} -% \toprule -% n & 0 & 1 & 2 & 3 & 4 & 5 \\ -% \midrule -% u_n & 1 & 2 & 4 & 8 & 16 & 32 \\ -% \bottomrule -% \end{NiceArray}$ -% \end{enumerate} -% \end{minipage} -% % % \bigskip % \section{The exterior rows and columns} +% % The options |first-row|, |last-row|, |first-col| and |last-col| allow the % composition of exterior rows and columns in the environments of % \pkg{nicematrix}. @@ -1166,6 +1181,8 @@ version 2005/12/01 or later. % & C_1 & \Cdots & & C_4 & % \end{pNiceMatrix}\] % +% \medskip +% The dotted lines have been drawn with the tools presented p.~\pageref{Cdots}. % % \bigskip % We have several remarks to do. @@ -1244,19 +1261,13 @@ version 2005/12/01 or later. % % \emph{Remarks} % \begin{itemize}[beginpenalty=10000] -% \item As shown in the previous example, an horizontal rule (drawn by |\hline|) -% doesn't extend in the exterior columns and a vertical rule (specified by a -% ``\verb+|+'' in the preamble of the array) doesn't extend in the exterior -% rows.\footnote{The latter is not true when the package \pkg{arydshln} is -% loaded besides \pkg{nicematrix}. In fact, \pkg{nicematrix} and \pkg{arydhsln} -% are not totally compatible because \pkg{arydshln} redefines many internals of -% \pkg{array}. On another hand, if one really wants a vertical rule running in -% the first and in the last row, he should use |!{\vline}| instead of \verb+|+ -% in the preamble of the array.} +% \item As shown in the previous example, the horizontal and rules doesn't +% extend in the exterior rows and columns. % -% If one wishes to define new specifiers for columns in order to draw vertical -% rules (for example thicker than the standard rules), he should consider the -% command |\OnlyMainNiceMatrix| described on page~\pageref{OnlyMainNiceMatrix}. +% However, if one wishes to define new specifiers for columns in order to draw +% vertical rules (for example thicker than the standard rules), he should +% consider the command |\OnlyMainNiceMatrix| described on +% page~\pageref{OnlyMainNiceMatrix}. % % \item A specification of color present in |code-for-first-row| also applies to % a dotted line draw in this exterior ``first row'' (excepted if a value has @@ -1272,500 +1283,562 @@ version 2005/12/01 or later. % % % +% +% \section{The continuous dotted lines} % -% \section{The dotted lines to separate rows or columns} +% \label{Cdots} +% Inside the environments of the package \pkg{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|.\footnote{The command |\iddots|, defined in \pkg{nicematrix}, is a +% variant of |\ddots| with dots going forward. If |mathdots| is loaded, the +% version of |mathdots| is used. It corresponds to the command |\adots| of +% \pkg{unicode-math}.} +% \newcounter{fniddots} +% \setcounter{fniddots}{\thefootnote} % +% \smallskip +% Each of them must be used alone in the cell of the array and it draws a dotted +% line between the first non-empty cells\footnote{The precise definition of a +% ``non-empty cell'' is given below (cf. p.~\pageref{empty-cells}).} 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|.\footnote{It's also possible to change the color of +% all theses dotted lines with the option |xdots/color| (\textsl{xdots} to +% remind that it works for |\Cdots|, |\Ldots|, |\Vdots|, etc.): cf. p. +% \pageref{customization}.}\par\nobreak % -% In the environments of the package \pkg{nicematrix}, it's possible to use -% the command |\hdottedline| (provided by \pkg{nicematrix}) which is a -% counterpart of the classical commands |\hline| and |\hdashline| (the latter is -% a command of \pkg{arydshln}). +% \bigskip +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% \begin{bNiceMatrix} +% a_1 & \Cdots & & & a_1 \\ +% \Vdots & a_2 & \Cdots & & a_2 \\ +% & \Vdots & \Ddots[color=red] \\ +% \\ +% a_1 & a_2 & & & a_n +% \end{bNiceMatrix} +% \end{BVerbatim} +% $\begin{bNiceMatrix} +% a_1 & \Cdots & & & a_1 \\ +% \Vdots & a_2 & \Cdots & & a_2 \\ +% & \Vdots & \Ddots[color=red] \\ +% \\ +% a_1 & a_2 & & & a_n +% \end{bNiceMatrix}$ +% +% \interitem +% In order to represent the null matrix, one can use the following +% codage:\par\nobreak % -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] -% \begin{pNiceMatrix} -% 1 & 2 & 3 & 4 & 5 \\ -% ~emphase#\hdottedline@ -% 6 & 7 & 8 & 9 & 10 \\ -% 11 & 12 & 13 & 14 & 15 -% \end{pNiceMatrix} +% \bigskip +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% \begin{bNiceMatrix} +% 0 & \Cdots & 0 \\ +% \Vdots & & \Vdots \\ +% 0 & \Cdots & 0 +% \end{bNiceMatrix} % \end{BVerbatim} -% $\begin{pNiceMatrix} -% 1 & 2 & 3 & 4 & 5 \\ -% \hdottedline -% 6 & 7 & 8 & 9 & 10 \\ -% 11 & 12 & 13 & 14 & 15 -% \end{pNiceMatrix}$ +% $\begin{bNiceMatrix} +% 0 & \Cdots & 0 \\ +% \Vdots & & \Vdots \\ +% 0 & \Cdots & 0 +% \end{bNiceMatrix}$ +% +% \bigskip +% 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 \pkg{nicematrix}:\par\nobreak +% +% \bigskip +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% \begin{bNiceMatrix} +% 0 & \Cdots & \Cdots & 0 \\ +% \Vdots & & & \Vdots \\ +% \Vdots & & & \Vdots \\ +% 0 & \Cdots & \Cdots & 0 +% \end{bNiceMatrix} +% \end{BVerbatim} +% $\begin{bNiceMatrix} +% 0 & \Cdots & \Cdots & 0 \\ +% \Vdots & & & \Vdots \\ +% \Vdots & & & \Vdots \\ +% 0 & \Cdots & \Cdots & 0 +% \end{bNiceMatrix}$ +% +% \bigskip +% In the first column of this exemple, there are two instructions |\Vdots| but +% only one dotted line is drawn (there is no overlapping graphic objects in the +% resulting \textsc{pdf}\footnote{And it's not possible to draw a |\Ldots| and a +% |\Cdots| line between the same cells.}). % +% \bigskip +% In fact, in this example, it would be possible to draw the same matrix more +% easily with the following code:\par\nobreak % % \bigskip -% In the environments with an explicit preamble (like |{NiceArray}|, etc.), it's -% possible to draw a vertical dotted line with the specifier ``|:|''. -% -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] -% \left(\begin{NiceArray}{CCCC~emphase#:@C} -% 1 & 2 & 3 & 4 & 5 \\ -% 6 & 7 & 8 & 9 & 10 \\ -% 11 & 12 & 13 & 14 & 15 -% \end{NiceArray}\right) +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% \begin{bNiceMatrix} +% 0 & \Cdots & & 0 \\ +% \Vdots & & & \\ +% & & & \Vdots \\ +% 0 & & \Cdots & 0 +% \end{bNiceMatrix} % \end{BVerbatim} -% $\left(\begin{NiceArray}{CCCC:C} -% 1 & 2 & 3 & 4 & 5 \\ -% 6 & 7 & 8 & 9 & 10 \\ -% 11 & 12 & 13 & 14 & 15 -% \end{NiceArray}\right)$ -% +% $\begin{bNiceMatrix} +% 0 & \Cdots & & 0 \\ +% \Vdots & & & \\ +% & & & \Vdots \\ +% 0 & & \Cdots & 0 +% \end{bNiceMatrix}$ % % \bigskip -% These dotted lines do \emph{not} extend in the potential exterior rows and -% columns. -% +% 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.\footnote{In \pkg{nicematrix}, one should use |\hspace*| and not +% |\hspace| for such an usage because \pkg{nicematrix} loads \pkg{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.~\pageref{width}} % -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=9.5cm] -% $\begin{pNiceArray}{CCC:C}[ -% first-row,last-col, -% code-for-first-row = \color{blue}\scriptstyle, -% code-for-last-col = \color{blue}\scriptstyle ] -% C_1 & C_2 & C_3 & C_4 \\ -% 1 & 2 & 3 & 4 & L_1 \\ -% 5 & 6 & 7 & 8 & L_2 \\ -% 9 & 10 & 11 & 12 & L_3 \\ -% \hdottedline -% 13 & 14 & 15 & 16 & L_4 -% \end{pNiceArray}$ +% However, a command~|\hspace*| might interfer with the construction of the +% dotted lines. That's why the package \pkg{nicematrix} provides a +% command~|\Hspace| which is a variant of |\hspace| transparent for the dotted +% lines of \pkg{nicematrix}.\par\nobreak +% +% \bigskip +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% \begin{bNiceMatrix} +% 0 & \Cdots & ~emphase#\Hspace*{1cm}@ & 0 \\ +% \Vdots & & & \Vdots \\~emphase#[1cm]@ +% 0 & \Cdots & & 0 +% \end{bNiceMatrix} % \end{BVerbatim} -% $\begin{pNiceArray}{CCC:C}[ -% first-row,last-col, -% code-for-first-row = \color{blue}\scriptstyle, -% code-for-last-col = \color{blue}\scriptstyle ] -% C_1 & C_2 & C_3 & C_4 \\ -% 1 & 2 & 3 & 4 & L_1 \\ -% 5 & 6 & 7 & 8 & L_2 \\ -% 9 & 10 & 11 & 12 & L_3 \\ -% \hdottedline -% 13 & 14 & 15 & 16 & L_4 -% \end{pNiceArray}$ +% $\begin{bNiceMatrix} +% 0 & \Cdots & \Hspace*{1cm} & 0 \\ +% \Vdots & & & \Vdots \\[1cm] +% 0 & \Cdots & & 0 +% \end{bNiceMatrix}$ % -% \bigskip -% It's possible to change in \pkg{nicematrix} the letter used to specify a -% vertical dotted line with the option |letter-for-dotted-lines| available in -% |\NiceMatrixOptions|. +% \subsection{The option nullify-dots} % -% \bigskip -% \emph{Remark} : In the package \pkg{array} (on which the package -% \pkg{nicematrix} relies), horizontal and vertical rules make the array larger -% or wider by a quantity equal to the width of the rule\footnote{In fact, this -% is true only for |\hline| and ``"|"'' but not for |\cline|.}. In -% \pkg{nicematrix}, the dotted lines drawn by |\hdottedline| and ``|:|'' do -% likewise. % -% -% -% \section{The width of the columns} -% \label{width} +% Consider the following matrix composed classicaly with the environment +% \verb|{pmatrix}| of \pkg{amsmath}.\par\nobreak % -% In the environments with an explicit preamble (like |{NiceArray}|, -% |{pNiceArray}|, etc.), it's possible to fix the width of a given column with -% the standard letters |w| and |W| of the package \pkg{array}. In the -% environments of \pkg{nicematrix}, the cells of such columns are composed in -% mathematical mode, whereas, in |{array}| of \pkg{array}, they are composed in -% text mode. -% % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $\left(\begin{NiceArray}{~emphase#wc{1cm}@CC} -% 1 & 12 & -123 \\ -% 12 & 0 & 0 \\ -% 4 & 1 & 2 -% \end{NiceArray}\right)$ +% $A = \begin{pmatrix} +% h & i & j & k & l & m \\ +% x & & & & & x +% \end{pmatrix}$ % \end{BVerbatim} -% $\left(\begin{NiceArray}{wc{1cm}CC} -% 1 & 12 & -123 \\ -% 12 & 0 & 0 \\ -% 4 & 1 & 2 -% \end{NiceArray}\right)$ +% $A = \begin{pmatrix} +% h & i & j & k & l & m \\ +% x & & & & & x +% \end{pmatrix}$ % % % \bigskip -% In the environments of \pkg{nicematrix}, it's also possible to fix the \emph{minimal} -% width of all the columns of a matrix directly with the option |columns-width|. -% +% If we add \verb|\ldots| instructions in the second row, the geometry of the +% matrix is modified.\par\nobreak +% % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $\begin{pNiceMatrix}[~emphase#columns-width = 1cm@] -% 1 & 12 & -123 \\ -% 12 & 0 & 0 \\ -% 4 & 1 & 2 -% \end{pNiceMatrix}$ +% $B = \begin{pmatrix} +% h & i & j & k & l & m \\ +% x & \ldots & \ldots & \ldots & \ldots & x +% \end{pmatrix}$ % \end{BVerbatim} -% $\begin{pNiceMatrix}[columns-width = 1cm] -% 1 & 12 & -123 \\ -% 12 & 0 & 0 \\ -% 4 & 1 & 2 -% \end{pNiceMatrix}$ -% -% \medskip -% Note that the space inserted between two columns (equal to 2 |\arraycolsep|) -% is not suppressed (of course, it's possible to suppress this space by setting -% |\arraycolsep| equal to $0$~pt). +% $B = \begin{pmatrix} +% h & i & j & k & l & m \\ +% x & \ldots & \ldots & \ldots & \ldots & x +% \end{pmatrix}$ % % \bigskip -% 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.\footnote{The result is achieved with only one compilation (but Tikz -% will have written informations in the |.aux| file and a message requiring a -% second compilation will appear).}\par\nobreak +% By default, with \pkg{nicematrix}, if we replace \verb|{pmatrix}| by +% \verb|{pNiceMatrix}| and \verb|\ldots| by \verb|\Ldots|, the geometry of the matrix is not +% changed.\par\nobreak % % \medskip % \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $\begin{pNiceMatrix}[~emphase#columns-width = auto@] -% 1 & 12 & -123 \\ -% 12 & 0 & 0 \\ -% 4 & 1 & 2 +% $C = \begin{pNiceMatrix} +% h & i & j & k & l & m \\ +% x & \Ldots & \Ldots & \Ldots & \Ldots & x % \end{pNiceMatrix}$ % \end{BVerbatim} -% $\begin{pNiceMatrix}[columns-width = auto] -% 1 & 12 & -123 \\ -% 12 & 0 & 0 \\ -% 4 & 1 & 2 +% $C = \begin{pNiceMatrix} +% h & i & j & k & l & m \\ +% x & \Ldots & \Ldots & \Ldots & \Ldots & x % \end{pNiceMatrix}$ -% -% \bigskip -% Without surprise, it's possible to fix the minimal width of the columns of all -% the matrices of a current scope with the command -% |\NiceMatrixOptions|.\par\nobreak % -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=8.5cm] -% ~emphase#\NiceMatrixOptions{columns-width=10mm}@ -% $\begin{pNiceMatrix} -% a & b \\ c & d -% \end{pNiceMatrix} -% = -% \begin{pNiceMatrix} -% 1 & 1245 \\ 345 & 2 -% \end{pNiceMatrix}$ -% \end{BVerbatim} -% \begin{scope} -% \NiceMatrixOptions{columns-width=10mm} -% $\begin{pNiceMatrix} -% a & b \\ -% c & d -% \end{pNiceMatrix} -% = -% \begin{pNiceMatrix} -% 1 & 1245 \\ -% 345 & 2 -% \end{pNiceMatrix}$ -% \end{scope} -% -% % \bigskip -% But 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-width|\footnote{At this time, this is the only usage of the -% environment |{NiceMatrixBlock}| but it may have other usages in the future.}. -% The environment |{NiceMatrixBlock}| has no direct link with the command -% |\Block| presented just below (cf.~p.~\pageref{Block}). -% +% 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 \verb|nullify-dots| (and only one instruction \verb|\Ldots| is +% necessary).\par\nobreak +% % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=8.5cm] -% ~emphase#\begin{NiceMatrixBlock}[auto-columns-width]@ -% $\begin{pNiceMatrix} -% a & b \\ c & d -% \end{pNiceMatrix} -% = -% \begin{pNiceMatrix} -% 1 & 1245 \\ 345 & 2 +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% $D = \begin{pNiceMatrix}[~emphase#nullify-dots@] +% h & i & j & k & l & m \\ +% x & \Ldots & & & & x % \end{pNiceMatrix}$ -% ~emphase#\end{NiceMatrixBlock}@ % \end{BVerbatim} -% \begin{NiceMatrixBlock}[auto-columns-width] -% $\begin{pNiceMatrix} -% a & b \\ c & d -% \end{pNiceMatrix} -% = -% \begin{pNiceMatrix} -% 1 & 1245 \\ 345 & 2 +% $D = \begin{pNiceMatrix}[nullify-dots] +% h & i & j & k & l & m \\ +% x & \Ldots & & & & x % \end{pNiceMatrix}$ -% \end{NiceMatrixBlock} % % \medskip -% \textbf{Several compilations may be necessary to achieve the job.} +% The option |nullify-dots| smashes the instructions |\Ldots| (and the variants) +% horizontally but also vertically. % % -% \section{Block matrices} -% \label{Block} % -% This section has no direct link with the previous one where an environment -% |{NiceMatrixBlock}| was introduced. -% -% In the environments of \pkg{nicematrix}, it's possible to use the command -% |\Block| in order to place an element in the center of a rectangle of merged -% cells of the array. +% \subsection{The command \textbackslash Hdotsfor} % -% The command |\Block| must be used in the upper leftmost cell of the array with -% two arguments. The first argument is the size of the block with the syntax -% $i$\verb|-|$j$ where $i$ is the number of rows of the block and $j$ its number -% of columns. The second argument is the content of the block (composed in math -% mode). A Tikz node corresponding to the merged cells is created with the name -% ``$i$-$j$-block''. If the user has required the creation of the ``medium -% nodes'', a node of this type is also created with a name suffixed by -% |-medium|. +% Some people commonly use the command |\hdotsfor| of \pkg{amsmath} in order to +% draw horizontal dotted lines in a matrix. In the environments of +% \pkg{nicematrix}, one should use instead |\Hdotsfor| in order to draw dotted +% lines similar to the other dotted lines drawn by the package \pkg{nicematrix}. % -% \medskip -% In the following examples, we use the command |\arrayrulecolor| of -% \pkg{colortbl}. +% As with the other commands of \pkg{nicematrix} (like |\Cdots|, |\Ldots|, +% |\Vdots|, etc.), the dotted line drawn with |\Hdotsfor| extends until the +% contents of the cells on both sides. % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] -% \arrayrulecolor{blue} -% $\begin{bNiceArray}{CCC|C}[margin] -% ~emphase#\Block{3-3}{A}@ & & & 0 \\ -% & \hspace*{1cm} & & \Vdots \\ -% & & & 0 \\ -% \hline -% 0 & \Cdots& 0 & 0 -% \end{bNiceArray}$ -% \arrayrulecolor{black} +% \begin{BVerbatim}[baseline=c,boxwidth=7cm] +% $\begin{pNiceMatrix} +% 1 & 2 & 3 & 4 & 5 \\ +% 1 & ~emphase#\Hdotsfor{3}@ & 5 \\ +% 1 & 2 & 3 & 4 & 5 \\ +% 1 & 2 & 3 & 4 & 5 +% \end{pNiceMatrix}$ % \end{BVerbatim} -% \begin{scope} -% \arrayrulecolor{blue} -% $\begin{bNiceArray}{CCC|C}[margin] -% \Block{3-3}{A} & & & 0 \\ -% & \hspace*{1cm} & & \Vdots \\ -% & & & 0 \\ -% \hline -% 0 & \Cdots& 0 & 0 -% \end{bNiceArray}$ -% \arrayrulecolor{black} -% \end{scope} +% $\begin{pNiceMatrix} +% 1 & 2 & 3 & 4 & 5 \\ +% 1 & \Hdotsfor{3} & 5 \\ +% 1 & 2 & 3 & 4 & 5 \\ +% 1 & 2 & 3 & 4 & 5 +% \end{pNiceMatrix}$ % % \bigskip -% One may wish to raise the size of the ``$A$'' placed in the block of the -% previous example. Since this element is composed in math mode, it's not -% possible to use directly a command like |\large|, |\Large| and |\LARGE|. -% That's why the command |\Block| provides an option between angle brackets to -% specify some TeX code which will be inserted before the beginning of the -% math mode. +% However, if these cells are empty, the dotted line extends only in the cells +% specified by the argument of |\Hdotsfor| (by design). % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] -% \arrayrulecolor{blue} -% $\begin{bNiceArray}{CCC|C}[margin] -% \Block{3-3}~emphase#<\Large>@{A} & & & 0 \\ -% & \hspace*{1cm} & & \Vdots \\ -% & & & 0 \\ -% \hline -% 0 & \Cdots& 0 & 0 -% \end{bNiceArray}$ -% \arrayrulecolor{black} +% \begin{BVerbatim}[baseline=c,boxwidth=7cm] +% $\begin{pNiceMatrix} +% 1 & 2 & 3 & 4 & 5 \\ +% & ~emphase#\Hdotsfor{3}@ \\ +% 1 & 2 & 3 & 4 & 5 \\ +% 1 & 2 & 3 & 4 & 5 +% \end{pNiceMatrix}$ % \end{BVerbatim} -% \begin{scope} -% \arrayrulecolor{blue} -% $\begin{bNiceArray}{CCC|C}[margin] -% \Block{3-3}<\Large>{A} & & & 0 \\ -% & \hspace*{1cm} & & \Vdots \\ -% & & & 0 \\ -% \hline -% 0 & \Cdots& 0 & 0 -% \end{bNiceArray}$ -% \arrayrulecolor{black} -% \end{scope} +% $\begin{pNiceMatrix} +% 1 & 2 & 3 & 4 & 5 \\ +% & \Hdotsfor{3} \\ +% 1 & 2 & 3 & 4 & 5 \\ +% 1 & 2 & 3 & 4 & 5 +% \end{pNiceMatrix}$ % -% \medskip -% For technical reasons, you can't write |\Block{|$i$|-|$j$|}{<}|. But you can -% write |\Block{|$i$|-|$j$|}<>{<}| with the expected result. +% +% Remark: Unlike the command |\hdotsfor| of \pkg{amsmath}, the command +% |\Hdotsfor| may be used when the package \pkg{colortbl} is loaded (but you +% might have problem if you use |\rowcolor| on the same row as |\Hdotsfor|). % +% \subsection{How to generate the continuous dotted lines transparently} % -% \section{The color of the rows and columns} +% The package \pkg{nicematrix} provides an option called |transparent| for using +% existing code transparently in the environments of the \pkg{amsmath} : +% |{matrix}|, |{pmatrix}|, |{bmatrix}|, etc. In fact, this +% option is an alias for the conjonction of two options: +% |renew-dots| and |renew-matrix|.\footnote{The options |renew-dots|, +% |renew-matrix| and |transparent| can be fixed with the command +% |\NiceMatrixOptions| like the other options. However, they can also be fixed +% as options of the command |\usepackage| (it's an exception for these three +% specific options.)} % -% With the classical package \pkg{colortbl}, it's possible to color the cells, -% rows and columns of a tabular. However, the resulting \textsc{pdf} is not -% always perfectly displayed by the \textsc{pdf} viewers, in particular in -% conjonction with rules. With some \textsc{pdf} viewers, some vertical rules -% seem to vanish. On the other side, some thin horizontal white lines may appear -% in some circonstances. +% \smallskip % +% \begin{itemize} +% \item The option |renew-dots|\par\nobreak % -% \medskip -% The version 4.0 of \pkg{nicematrix} provide similar tools which do not -% present these drawbacks. This version provides a key |code-before| for some -% code which will be executed \emph{before} the drawing of the tabular. In this -% |code-before|, new commands are available: |\cellcolor|, |\rectanglecolor|, -% |\rowcolor|, |\columncolor|, |\rowcolors| and |\chessboardcolors|. +% With this option, the commands |\ldots|, |\cdots|, |\vdots|, |\ddots|, +% |\iddots|\footnotemark[\thefniddots] and |\hdotsfor| are redefined within the +% environments provided by \pkg{nicematrix} and behave like |\Ldots|, |\Cdots|, +% |\Vdots|, |\Ddots|, |\Iddots| and |\Hdotsfor|; the command |\dots| +% (``automatic dots'' of |amsmath|) is also redefined to behave like |\Ldots|. % -% \medskip -% \begin{itemize} -% \item The command |\cellcolor| takes its name from the command |\cellcolor| of -% \pkg{colortbl}. +% \item The option |renew-matrix|\par\nobreak % -% This command takes in arguments a color and a list of cells, each of which -% with the format $i$-$j$ where $i$ is the number of row and $j$ the number of -% colummn of the cell. +% With this option, the environment |{matrix}| is redefined and behave like +% |{NiceMatrix}|, and so on for the five variants. +% \end{itemize} % +% \bigskip +% Therefore, with the option |transparent|, a classical code gives directly the +% ouput of \pkg{nicematrix}.\par\nobreak % -% \medskip +% \bigskip % \begin{scope} -% \hfuzz=10cm -% \begin{BVerbatim}[boxwidth=10cm,baseline=c] -% \begin{NiceTabular}{|C|C|C|}[code-before = ~emphase#\cellcolor{red!15}{3-1,2-2,1-3}@] -% \hline -% a & b & c \\ \hline -% e & f & g \\ \hline -% h & i & j \\ \hline -% \end{NiceTabular} +% \NiceMatrixOptions{transparent} +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% ~emphase#\NiceMatrixOptions{transparent}@ +% \begin{pmatrix} +% 1 & \cdots & \cdots & 1 \\ +% 0 & \ddots & & \vdots \\ +% \vdots & \ddots & \ddots & \vdots \\ +% 0 & \cdots & 0 & 1 +% \end{pmatrix} % \end{BVerbatim} -% \begin{NiceTabular}{|C|C|C|}[code-before = \cellcolor{red!15}{3-1,2-2,1-3}] -% \hline -% a & b & c \\ \hline -% e & f & g \\ \hline -% h & i & j \\ \hline -% \end{NiceTabular} +% $\begin{pmatrix} +% 1 & \cdots & \cdots & 1 \\ +% 0 & \ddots & & \vdots \\ +% \vdots & \ddots & \ddots & \vdots \\ +% 0 & \cdots & 0 & 1 +% \end{pmatrix}$ % \end{scope} % -% \bigskip -% \item The command |\rectanglecolor| takes three 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. -% -% \medskip -% \begin{scope} -% \hfuzz=10cm -% \begin{BVerbatim}[boxwidth=10cm,baseline=c] -% \begin{NiceTabular}{|C|C|C|}[code-before = ~emphase#\rectanglecolor{red!15}{2-2}{3-3}@] -% \hline -% a & b & c \\ \hline -% e & f & g \\ \hline -% h & i & j \\ \hline -% \end{NiceTabular} +% \subsection{The labels of the dotted lines} +% +% The commands |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| and |\Hdotsfor| +% (and the command |\line| in the |code-after| which is described +% p.~\pageref{line-in-code-after}) accept two optional arguments specified +% by the tokens |_| and |^| for labels positionned below and above the line. The +% arguments are composed in math mode with |\scriptstyle|. +% +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% $\begin{bNiceMatrix} +% 1 & \hspace*{1cm} & 0 \\[8mm] +% & ~emphase#\Ddots^{n \text{ times}}@ & \\ +% 0 & & 1 +% \end{bNiceMatrix}$ % \end{BVerbatim} -% \begin{NiceTabular}{|C|C|C|}[code-before = \rectanglecolor{red!15}{2-2}{3-3}] -% \hline -% a & b & c \\ \hline -% e & f & g \\ \hline -% h & i & j \\ \hline -% \end{NiceTabular} -% \end{scope} +% $\begin{bNiceMatrix} +% 1 & \hspace*{1cm} & 0 \\[8mm] +% & \Ddots^{n \text{ times}} & \\ +% 0 & & 1 +% \end{bNiceMatrix}$ +% +% \subsection{Customization of the dotted lines} % +% \label{customization} +% The dotted lines drawn by |\Ldots|, |\Cdots|, |\Vdots|, |\Ddots|, |\Iddots| +% and |\Hdotsfor| (and by the command |\line| in the |code-after| which is described +% p.~\pageref{line-in-code-after}) may be customized by three options (specified +% between square brackets after the command): +% \begin{itemize} +% \item |color|; +% \item |shorten|; +% \item |line-style|. +% \end{itemize} +% +% These options may also be fixed with |\NiceMatrixOptions| or at the level of a +% given environment but, in those cases, they must be prefixed by |xdots|, and, +% thus have for names: +% \begin{itemize} +% \item |xdots/color|; +% \item |xdots/shorten|; +% \item |xdots/line-style|. +% \end{itemize} % +% For the clarity of the explanations, we will use those names. % % \bigskip -% \item The command |\rowcolor| takes its name from the command |\rowcolor| of -% \pkg{colortbl}. Its first 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). +% \textbf{The option xdots/color}\par\nobreak +% +% \smallskip +% The option |xdots/color| fixes the color or the dotted line. However, one should +% remark that the dotted lines drawn in the exterior rows and columns have a +% special treatment: cf. p.~\pageref{exterior}. +% +% \bigskip +% \textbf{The option xdots/shorten}\par\nobreak +% +% \smallskip +% The option |xdots/shorten| fixes the margin of both extremities of the line. +% The name is derived from the options ``|shorten >|'' and ``|shorten <|'' of +% Tikz but one should notice that \pkg{nicematrix} only provides +% |xdots/shorten|. The initial value of this parameter is 0.3~em (it is +% recommanded to use a unit of length dependent of the current font). +% +% \bigskip +% \textbf{The option xdots/line-style}\par\nobreak +% +% \smallskip +% It should be pointed that, by default, the lines drawn by Tikz with the +% parameter |dotted| are composed of square dots (and not rounded +% ones).\footnote{The first reason of this behaviour is that the \textsc{pdf} +% format includes a description for dashed lines. The lines specified with this +% descriptor are displayed very efficiently by the \textsc{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 \textsc{pdf} file.} % +% \begin{BVerbatim}[baseline=c,boxwidth=9cm] +% \tikz \draw [dotted] (0,0) -- (5,0) ; +% \end{BVerbatim} +% \tikz \draw [dotted] (0,0) -- (5,0) ; +% % \medskip -% \begin{scope} -% \hfuzz = 10cm -% \begin{BVerbatim}[boxwidth=9cm,baseline=c] -% $\begin{NiceArray}{LLL}[hvlines, ~emphase#code-before = \rowcolor{red!15}{1,3-5,8-}@] -% a_1 & b_1 & c_1 \\ -% a_2 & b_2 & c_2 \\ -% a_3 & b_3 & c_3 \\ -% a_4 & b_4 & c_4 \\ -% a_5 & b_5 & c_5 \\ -% a_6 & b_6 & c_6 \\ -% a_7 & b_7 & c_7 \\ -% a_8 & b_8 & c_8 \\ -% a_9 & b_9 & c_9 \\ -% a_{10} & b_{10} & c_{10} \\ -% \end{NiceArray}$ +% In order to provide lines with rounded dots in the style of those provided by +% |\ldots| (at least with the \emph{Computer Modern} fonts), the package +% \pkg{nicematrix} embeds its own system to draw a dotted line (and this system +% uses \textsc{pgf} and not Tikz). This style is called |standard| and that's +% the initial value of the parameter |xdots/line-style|. +% +% However (when Tikz is loaded) it's possible to use for |xdots/line-style| any style +% provided by Tikz, that is to say any sequence of options provided by Tikz for +% the Tizk pathes (with the exception of ``|color|'', ``|shorten >|'' and +% ``|shorten <|''). +% +% \medskip +% Here is for example a tridiagonal matrix with the style |loosely dotted|:\par\nobreak +% +% \medskip +% \begin{BVerbatim}[baseline=c] +% $\begin{pNiceMatrix}[nullify-dots,~emphase#xdots/line-style=loosely dotted@] +% a & b & 0 & & \Cdots & 0 \\ +% b & a & b & \Ddots & & \Vdots \\ +% 0 & b & a & \Ddots & & \\ +% & \Ddots & \Ddots & \Ddots & & 0 \\ +% \Vdots & & & & & b \\ +% 0 & \Cdots & & 0 & b & a +% \end{pNiceMatrix}$ % \end{BVerbatim} -% $\begin{NiceArray}{LLL}[baseline=4,hvlines, code-before = \rowcolor{red!15}{1,3-5,8-}] -% a_1 & b_1 & c_1 \\ -% a_2 & b_2 & c_2 \\ -% a_3 & b_3 & c_3 \\ -% a_4 & b_4 & c_4 \\ -% a_5 & b_5 & c_5 \\ -% a_6 & b_6 & c_6 \\ -% a_7 & b_7 & c_7 \\ -% a_8 & b_8 & c_8 \\ -% a_9 & b_9 & c_9 \\ -% a_{10} & b_{10} & c_{10} \\ -% \end{NiceArray}$ -% \end{scope} -% % -% \bigskip -% \item The command |\columncolor| takes its name from the command -% |\columncolor| of \pkg{colortbl}. Its syntax is similar to the syntaxe of -% |\rowcolor|. -% -% \bigskip -% \item The command |\rowcolors| (with a \emph{s}) takes its name from the -% command |\rowcolors| of \pkg{xcolor}. The \emph{s} emphasizes the fact that -% there is \emph{two} colors. This command colors alternately the rows of the -% tabular, beginning with the row whose number is given in first argument. The -% two other arguments are the colors. +% +% \[\begin{pNiceMatrix}[nullify-dots,xdots/line-style=loosely dotted] +% a & b & 0 & & \Cdots & 0 \\ +% b & a & b & \Ddots & & \Vdots \\ +% 0 & b & a & \Ddots & & \\ +% & \Ddots & \Ddots & \Ddots & & 0 \\ +% \Vdots & & & & & b \\ +% 0 & \Cdots & & 0 & b & a +% \end{pNiceMatrix}\] +% +% +% \subsection{The dotted lines and the key hvlines} +% +% \label{dotted-and-hvlines} % +% We have said (cf. p. \pageref{hvlines}) that the key |hvlines| draws all the +% horizontal and vertical rules, excepted in the blocks. In fact, when this key +% is in force, the rules are also not drawn in the virtual blocks delimited by +% cells relied par dotted lines. +% % \medskip -% \begin{scope} -% \hfuzz=10cm -% \begin{BVerbatim}[baseline=c,boxwidth=9cm] -% \begin{NiceTabular}{LR}% -% [~emphase#code-before = \rowcolor{red!15}{1} \rowcolors{3}{blue!10}{}@] -% \toprule -% Town & Habitants \\ -% \midrule -% Pau & 80000 \\ -% Paris & 2000000 \\ -% Toulouse & 700000 \\ -% Reims & 40000 \\ -% \bottomrule -% \end{NiceTabular} +% \begin{BVerbatim}[baseline=c,boxwidth=11cm] +% \NiceMatrixOptions{nullify-dots} +% $\begin{pNiceMatrix}[rules/color=gray,~emphase#hvlines@,margin] +% 0 & \Cdots & & & & 0 \\ +% 1 & \Cdots & & & 1 & 2 \\ +% 0 & \Ddots & & & \Vdots & \Vdots \\ +% \Vdots & \Ddots & & & & \\ +% & & & & & \\ +% 0 & \Cdots & & 0 & 1 & 2 \\ +% \end{pNiceMatrix}$ % \end{BVerbatim} -% \begin{NiceTabular}{LR}[code-before =\rowcolor{red!15}{1} \rowcolors{3}{blue!10}{}] -% \toprule -% Ville & habitants \\ -% \midrule -% Pau & 80000 \\ -% Paris & 2000000 \\ -% Toulouse & 700000 \\ -% Reims & 40000 \\ -% \bottomrule -% \end{NiceTabular} +% \begin{scope} +% \NiceMatrixOptions{nullify-dots} +% $\begin{pNiceMatrix}[rules/color=gray,hvlines,margin] +% 0 & \Cdots & & & & 0 \\ +% 1 & \Cdots & & & 1 & 2 \\ +% 0 & \Ddots & & & \Vdots & \Vdots \\ +% \Vdots & \Ddots & & & & \\ +% & & & & & \\ +% 0 & \Cdots & & 0 & 1 & 2 \\ +% \end{pNiceMatrix}$ % \end{scope} % -% \bigskip -% \item The command |\chessboardcolors| take in arguments two colors and colors -% the cells of the tabular in quincunx with these colors. +% +% +% \section{The code-after} +% +% \label{code-after} +% The option |code-after| may be used to give some code that will be excuted +% after the construction of the matrix.\footnote{There is also a key +% |code-before| described p.~\pageref{code-before}.} +% +% A special command, called |\line|, is available to draw directly +% dotted lines between nodes. It takes two arguments for the two cells to rely, +% both of the form $i$-$j$ where is the number of row and $j$ is the number of +% column. It may be used, for example, to draw a dotted line +% between two adjacents cells. \label{line-in-code-after} % % \medskip -% \begin{scope} -% \hfuzz=10cm -% \begin{BVerbatim}[baseline=c,boxwidth=9cm] -% $\begin{pNiceMatrix}[R,margin, ~emphase#code-before=\chessboardcolors{red!15}{blue!15}@] -% 1 & -1 & 1 \\ -% -1 & 1 & -1 \\ -% 1 & -1 & 1 -% \end{pNiceMatrix}$ +% \begin{BVerbatim}[baseline=c,boxwidth=11cm] +% \NiceMatrixOptions{xdots/shorten = 0.6 em} +% \begin{pNiceMatrix}[~emphase#code-after=\line{2-2}{3-3}@] +% I & 0 & \Cdots &0 \\ +% 0 & I & \Ddots &\Vdots\\ +% \Vdots &\Ddots & I &0 \\ +% 0 &\Cdots & 0 &I +% \end{pNiceMatrix} % \end{BVerbatim} -% $\begin{pNiceMatrix}[R,baseline=1, margin, code-before = \chessboardcolors{red!15}{blue!15}] -% 1 & -1 & 1 \\ -% -1 & 1 & -1 \\ -% 1 & -1 & 1 +% \begin{scope} +% \NiceMatrixOptions{xdots/shorten = 0.6 em} +% $\begin{pNiceMatrix}[code-after=\line{2-2}{3-3}] +% I & 0 & \Cdots &0 \\ +% 0 & I & \Ddots &\Vdots\\ +% \Vdots &\Ddots & I &0 \\ +% 0 &\Cdots & 0 &I % \end{pNiceMatrix}$ % \end{scope} +% +% \medskip +% For the readability 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|. For an example, cf. +% p.~\pageref{example-CodeAfter}. +% % -% \end{itemize} +% +% +% \section{Other features} % +% \subsection{Use of the column type S of siunitx} % +% If the package \pkg{siunitx} is loaded (before or after \pkg{nicematrix}), +% it's possible to use the |S| column type of \pkg{siunitx} in the environments +% of \pkg{nicematrix}. The implementation doesn't use explicitly any private +% macro of \pkg{siunitx}. +% +% +% \medskip +% \begin{BVerbatim}[baseline = c, boxwidth = 10.5cm] +% $\begin{pNiceArray}{~emphase#S@CWc{1cm}C}[nullify-dots,first-row] +% {C_1} & \Cdots & & C_n \\ +% 2.3 & 0 & \Cdots & 0 \\ +% 12.4 & \Vdots & & \Vdots \\ +% 1.45 \\ +% 7.2 & 0 & \Cdots & 0 +% \end{pNiceArray}$ +% \end{BVerbatim} +% $\begin{pNiceArray}{SCWc{1cm}C}[nullify-dots,first-row] +% {C_1} & \Cdots & & C_n \\ +% 2.3 & 0 & \Cdots & 0 \\ +% 12.4 & \Vdots & & \Vdots \\ +% 1.45 \\ +% 7.2 & 0 & \Cdots & 0 +% \end{pNiceArray}$ % -% \section{Advanced features} +% \medskip +% On the other hand, the |d| columns of the package \pkg{dcolumn} are not +% supported by \pkg{nicematrix}. +% % +% \subsection{Alignement option in \{NiceMatrix\}} % -% \subsection{Alignement option in NiceMatrix} +% \label{key-R} % % The environments without preamble (|{NiceMatrix}|, |{pNiceMatrix}|, % |{bNiceMatrix}|, etc.) provide two options |l| and |r| (equivalent at |L| and % |R|) which generate all the columns aligned leftwards (or -% rightwards).\footnote{This is a part of the functionality provided by the -% environments |{pmatrix*}|, |{bmatrix*}|, etc. of \pkg{mathtools}.} +% rightwards). % % % \medskip @@ -1780,6 +1853,11 @@ version 2005/12/01 or later. % \sin x & \cos x % \end{bNiceMatrix}$ % +% \medskip +% There is also a key |S| which sets all the columns all type |S| of +% \pkg{siunitx} (if this package is loaded).\footnote{This is a part of the +% functionality provided by the environments |{pmatrix*}|, |{bmatrix*}|, etc. of +% \pkg{mathtools}.} % % \subsection{The command \textbackslash rotate} % @@ -1891,225 +1969,526 @@ version 2005/12/01 or later. % \item the characteristics of the dotted lines are also modified. % \end{itemize} % -% \subsection{The counters iRow and jCol} +% \subsection{The counters iRow and jCol} +% +% In the cells of the array, it's possible to use the LaTeX counters |iRow| and +% |jCol| which represent the number of the current row and the number of the +% current column\footnote{We recall that the exterior ``first row'' (if it +% exists) has the number~$0$ and that the exterior ``first column'' (if it +% exists) has also the number~$0$.}. Of course, the user must not change the +% value of these counters which are used internally by \pkg{nicematrix}. +% +% In the |code-before| (cf. p. \pageref{code-before}) and in the |code-after| +% (cf. p. \pageref{code-after}), |iRow| represents the total number of rows +% (excepted the potential exterior rows) and |jCol| represents the total number +% of columns (excepted the potential exterior columns). +% +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] +% $\begin{pNiceMatrix}% don't forget the % +% [first-row, +% first-col, +% code-for-first-row = \mathbf{~emphase#\alph{jCol}@} , +% code-for-first-col = \mathbf{~emphase#\arabic{iRow}@} ] +% & & & & \\ +% & 1 & 2 & 3 & 4 \\ +% & 5 & 6 & 7 & 8 \\ +% & 9 & 10 & 11 & 12 +% \end{pNiceMatrix}$ +% \end{BVerbatim} +% $\begin{pNiceMatrix}[first-row, +% first-col, +% code-for-first-row = \mathbf{\alph{jCol}} , +% code-for-first-col = \mathbf{\arabic{iRow}} ] +% & & & & \\ +% & 1 & 2 & 3 & 4 \\ +% & 5 & 6 & 7 & 8 \\ +% & 9 & 10 & 11 & 12 +% \end{pNiceMatrix}$ +% +% \medskip +% If LaTeX counters called |iRow| and |jCol| are defined in the document by +% packages other than \pkg{nicematrix} (or by the final user), they are shadowed +% in the environments of \pkg{nicematrix}. +% +% \bigskip +% The package \pkg{nicematrix} also provides commands in order to compose +% automatically matrices from a general pattern. These commands are +% |\AutoNiceMatrix|, |\pAutoNiceMatrix|, |\bAutoNiceMatrix|, |\vAutoNiceMatrix|, +% |\VAutoNiceMatrix| and |\BAutoNiceMatrix|. +% +% These commands take 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, excepted in the +% cells of the eventual exterior rows and columns). +% +% \medskip +% \begin{Verbatim} +% $C = ~emphase#\pAutoNiceMatrix@{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$ +% \end{Verbatim} +% +% +% \[C = \pAutoNiceMatrix{3-3}{C_{\arabic{iRow},\arabic{jCol}}}\] +% +% +% \subsection{The option light-syntax} +% +% \label{light-syntax} +% The option |light-syntax| (inpired by the package \pkg{spalign}) allows the +% user to compose the arrays with a lighter syntax, which gives a better +% legibility of the TeX source. +% +% When this option is used, one should use the semicolon for the end of a row +% and spaces or tabulations to separate the columns. However, as usual in the +% TeX world, the spaces after a control sequence are discarded and the elements +% between curly braces are considered as a whole. +% +% \bigskip +% The following example has been composed with XeLaTeX with \pkg{unicode-math}, +% which allows the use of greek letters directly in the TeX source. +% +% \medskip +% \begin{scope} +% \begin{BVerbatim}[baseline=c,boxwidth=10cm] +% $\begin{bNiceMatrix}[~emphase#light-syntax@,first-row,first-col] +% {} a b ; +% a 2\cos a {\cos a + \cos b} ; +% b \cos a+\cos b { 2 \cos b } +% \end{bNiceMatrix}$ +% \end{BVerbatim} +% \end{scope} +% $\begin{bNiceMatrix}[light-syntax,first-row,first-col] +% {} a b ; +% a 2\cos a {\cos a + \cos b} ; +% b \cos a+\cos b { 2 \cos b } +% \end{bNiceMatrix}$ +% +% \medskip +% 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. +% +% \medskip +% 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.\footnote{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.} +% +% +% +% \subsection{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. +% +% \medskip +% \begin{BVerbatim}[baseline=c,boxwidth=11cm] +% $\begin{~emphase#NiceArrayWithDelims@} +% {\downarrow}{\uparrow}{CCC}[margin] +% 1 & 2 & 3 \\ +% 4 & 5 & 6 \\ +% 7 & 8 & 9 +% \end{~emphase#NiceArrayWithDelims@}$ +% \end{BVerbatim} +% $\begin{NiceArrayWithDelims} +% {\downarrow}{\uparrow}{CCC}[margin] +% 1 & 2 & 3 \\ +% 4 & 5 & 6 \\ +% 7 & 8 & 9 +% \end{NiceArrayWithDelims}$ +% +% +% +% \section{Utilisation of Tikz with nicematrix} +% +% \label{name} +% \subsection{The nodes corresponding to the contents of the cells} +% +% The package \pkg{nicematrix} creates a PGF/Tikz node for each (non-empty) cell +% of the considered array. These nodes are used to draw the dotted lines between +% the cells of the matrix (inter alia). % -% In the cells of the array, it's possible to use the LaTeX counters |iRow| and -% |jCol| which represent the number of the current row and the number of the -% current column\footnote{We recall that the exterior ``first row'' (if it -% exists) has the number~$0$ and that the exterior ``first column'' (if it -% exists) has also the number~$0$.}. Of course, the user must not change the -% value of these counters which are used internally by \pkg{nicematrix}. +% \smallskip +% The nodes of a document must have distinct names. That's why the names of the +% nodes created by \pkg{nicematrix} contains the number of the current +% environment. Indeed, the environments of \pkg{nicematrix} are numbered by a +% internal global counter. % -% In the |code-after| (cf. p. \pageref{code-after}), |iRow| represents the total -% number of rows (excepted the potential exterior rows) and |jCol| represents -% the total number of columns (excepted the potential exterior columns). +% \smallskip +% In the environment with the number $n$, the node of the row $i$ and +% column~$j$ has for name |nm-|$n$|-|$i$|-|$j$. % -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] -% $\begin{pNiceMatrix}% don't forget the % -% [first-row, -% first-col, -% code-for-first-row = \mathbf{~emphase#\alph{jCol}@} , -% code-for-first-col = \mathbf{~emphase#\arabic{iRow}@} ] -% & & & & \\ -% & 1 & 2 & 3 & 4 \\ -% & 5 & 6 & 7 & 8 \\ -% & 9 & 10 & 11 & 12 +% \smallskip +% The command |\NiceMatrixLastEnv| provides the number of the last environment +% of \pkg{nicematrix} (for LaTeX, it's a ``fully expandable'' command and not a +% counter). +% +% \smallskip +% However, it's advisable to use instead the key |name|. This key gives a name +% to the current environment. When the environment has a name, the nodes are +% accessible with the name ``\textsl{name}-$i$-$j$'' where \textsl{name} is the +% name given to the array and $i$ and $j$ the numbers of row and column. It's +% possible to use these nodes with \textsc{pgf} but the final user will +% probably prefer to use Tikz (which is a convenient layer upon \textsc{pgf}). +% However, one should remind that \pkg{nicematrix} doesn't load Tikz by default. +% +% \bigskip +% \begin{BVerbatim}[baseline=c,boxwidth=11cm] +% $\begin{pNiceMatrix}[name=~emphase#mymatrix@] +% 1 & 2 & 3 \\ +% 4 & 5 & 6 \\ +% 7 & 8 & 9 % \end{pNiceMatrix}$ +% \tikz[remember picture,overlay] +% \draw ~emphase#(mymatrix-2-2)@ circle (2mm) ; % \end{BVerbatim} -% $\begin{pNiceMatrix}[first-row, -% first-col, -% code-for-first-row = \mathbf{\alph{jCol}} , -% code-for-first-col = \mathbf{\arabic{iRow}} ] -% & & & & \\ -% & 1 & 2 & 3 & 4 \\ -% & 5 & 6 & 7 & 8 \\ -% & 9 & 10 & 11 & 12 +% $\begin{pNiceMatrix}[name=mymatrix] +% 1 & 2 & 3 \\ +% 4 & 5 & 6 \\ +% 7 & 8 & 9 % \end{pNiceMatrix}$ -% +% \tikz[remember picture,overlay] +% \draw (mymatrix-2-2) circle (2mm) ; +% % \medskip -% If LaTeX counters called |iRow| and |jCol| are defined in the document by -% packages other than \pkg{nicematrix} (or by the user), they are shadowed in -% the environments of \pkg{nicematrix}. +% Don't forget the options |remember picture| and |overlay|. % % \bigskip -% The package \pkg{nicematrix} also provides commands in order to compose -% automatically matrices from a general pattern. These commands are -% |\AutoNiceMatrix|, |\pAutoNiceMatrix|, |\bAutoNiceMatrix|, |\vAutoNiceMatrix|, -% |\VAutoNiceMatrix| and |\BAutoNiceMatrix|. +% In the |code-after|, and if Tikz is loaded, the things are easier. One may +% design the nodes with the form $i$-$j$: there is no need to indicate the +% environment which is of course the current environment. % -% These commands take 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, excepted in the -% cells of the eventual exterior rows and columns). % % \medskip -% \begin{Verbatim} -% $C = ~emphase#\pAutoNiceMatrix@{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$ -% \end{Verbatim} +% \begin{BVerbatim}[baseline=c,boxwidth=11cm] +% $\begin{pNiceMatrix} +% 1 & 2 & 3 \\ +% 4 & 5 & 6 \\ +% 7 & 8 & 9 +% \CodeAfter +% \tikz \draw ~emphase#(2-2)@ circle (2mm) ; +% \end{pNiceMatrix}$ +% \end{BVerbatim} +% $\begin{pNiceMatrix} +% 1 & 2 & 3 \\ +% 4 & 5 & 6 \\ +% 7 & 8 & 9 +% \CodeAfter +% \tikz \draw (2-2) circle (2mm) ; +% \end{pNiceMatrix}$ % % -% $C = \pAutoNiceMatrix{3-3}{C_{\arabic{iRow},\arabic{jCol}}}$ +% \bigskip +% In the following example, we have underlined all the nodes of the matrix (we +% explain below the technic used : cf. p. \pageref{highlight}). % -% \subsection{The options hlines, vlines and hvlines} +% \[\begin{pNiceMatrix}[ +% code-after = {\begin{tikzpicture} +% [every node/.style = {blend mode = multiply, +% fill = red!15, +% inner sep = 0 pt }] +% \node [fit = (1-1)] {} ; +% \node [fit = (1-3)] {} ; +% \node [fit = (2-2)] {} ; +% \node [fit = (3-1)] {} ; +% \node [fit = (3-3)] {} ; +% \node [fit = (1-2)] {} ; +% \node [fit = (2-1)] {} ; +% \node [fit = (2-3)] {} ; +% \node [fit = (3-2)] {} ; +% \end{tikzpicture}}] +% a & a + b & a + b + c \\ +% a & a & a + b \\ +% a & a & a +% \end{pNiceMatrix}\] % -% \label{hvlines} -% You can add horizontal rules between rows in the environments of -% \pkg{nicematrix} with the usual command |\hline| and you can use the specifier -% ``"|"'' to add vertical rules. However, by convenience, the package -% \pkg{nicematrix} also provides the option |hlines| (resp. |vlines|) which will -% draw all the horizontal (resp. vertical) rules (excepted, of course, the -% exterior rules corresponding to the exterior rows and columns). The key -% |hvlines| is an alias for the conjonction for the keys |hlines| et |vlines|. +% % -% % \medskip -% In the following example, we use the command |\arrayrulecolor| of -% \pkg{colortbl}. +% \subsection{The ``medium nodes'' and the ``large nodes''} % -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% \arrayrulecolor{blue} -% $\begin{NiceArray}{CCCC}% -% [~emphase#hvlines@,first-row,first-col] -% & e & a & b & c \\ -% e & e & a & b & c \\ -% a & a & e & c & b \\ -% b & b & c & e & a \\ -% c & c & b & a & e -% \end{NiceArray}$ -% \arrayrulecolor{black} -% \end{BVerbatim} -% \arrayrulecolor{blue} -% $\begin{NiceArray}{CCCC}[hvlines,first-row,first-col] -% & e & a & b & c \\ -% e & e & a & b & c \\ -% a & a & e & c & b \\ -% b & b & c & e & a \\ -% c & c & b & a & e -% \end{NiceArray}$ -% \arrayrulecolor{black} +% In fact, the package \pkg{nicematrix} can create ``extra nodes'': the ``medium +% nodes'' and the ``large nodes''. The first ones +% are created with the option |create-medium-nodes| and the second ones with the +% option |create-large-nodes|.\footnote{There is also an option +% |create-extra-nodes| which is an alias for the conjonction of +% |create-medium-nodes| and |create-large-nodes|.} % -% \bigskip -% However, there is a difference between the key |vlines| and the use of -% the specifier ``"|"'' in the preamble of the environment: the rules drawn by -% |vlines| completely cross the double-rules drawn by |\hline\hline|. +% \medskip +% These nodes are not used by \pkg{nicematrix} by default, and that's why they +% are not created by default. % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11.5cm] -% $\begin{NiceArray}{CCCC}[vlines] \hline -% a & b & c & d \\ \hline \hline -% 1 & 2 & 3 & 4 \\ -% 1 & 2 & 3 & 4 \\ \hline -% \end{NiceArray}$ -% \end{BVerbatim} -% $\begin{NiceArray}{CCCC}[vlines] -% \hline -% a & b & c & d \\ -% \hline \hline -% 1 & 2 & 3 & 4 \\ -% 1 & 2 & 3 & 4 \\ -% \hline -% \end{NiceArray}$ +% The names of the ``medium nodes'' are constructed by adding the suffix +% ``|-medium|'' to the names of the ``normal nodes''. In the following example, +% we have underlined the ``medium nodes''. We consider that this example is +% self-explanatory. +% \[\begin{pNiceMatrix}[ +% create-medium-nodes, +% code-after = {\begin{tikzpicture} +% [every node/.style = {fill = red!15, +% blend mode = multiply, +% inner sep = 0pt}, +% name suffix = -medium] +% \node [fit = (1-1)] {} ; +% \node [fit = (1-2)] {} ; +% \node [fit = (1-3)] {} ; +% \node [fit = (2-1)] {} ; +% \node [fit = (2-2)] {} ; +% \node [fit = (2-3)] {} ; +% \node [fit = (3-1)] {} ; +% \node [fit = (3-2)] {} ; +% \node [fit = (3-3)] {} ; +% \end{tikzpicture}}] +% a & a + b & a + b + c \\ +% a & a & a + b \\ +% a & a & a +% \end{pNiceMatrix}\] % -% \bigskip -% For the environments with delimiters (for example |{pNiceArray}| or -% |{pNiceMatrix}|), the option |vlines| don't draw vertical rules on both sides, -% where are the delimiters (fortunately). % % \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=10.6cm] -% \setlength{\arrayrulewidth}{0.2pt} -% $\begin{pNiceMatrix}[vlines] -% 1 & 2 & 3 & 4 & 5 & 6 \\ -% 1 & 2 & 3 & 4 & 5 & 6 \\ -% 1 & 2 & 3 & 4 & 5 & 6 -% \end{pNiceMatrix}$ -% \end{BVerbatim} -% \begin{scope} -% \setlength{\arrayrulewidth}{0.2pt} -% $\begin{pNiceMatrix}[vlines] -% 1 & 2 & 3 & 4 & 5 & 6 \\ -% 1 & 2 & 3 & 4 & 5 & 6 \\ -% 1 & 2 & 3 & 4 & 5 & 6 -% \end{pNiceMatrix}$ -% \end{scope} +% 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.\footnote{There is no ``large nodes'' created in the exterior +% rows and columns (for these rows and columns, cf. p.~\pageref{exterior}).} +% +% \[\begin{pNiceMatrix}[ +% create-large-nodes, +% code-after = {\begin{tikzpicture} +% [every node/.style = {blend mode = multiply, +% inner sep = 0pt}, +% name suffix = -large] +% \node [fit = (1-1),fill = red!15] {} ; +% \node [fit = (1-3),fill = red!15] {} ; +% \node [fit = (2-2),fill = red!15] {} ; +% \node [fit = (3-1),fill = red!15] {} ; +% \node [fit = (3-3),fill = red!15] {} ; +% \node [fit = (1-2),fill = blue!15] {} ; +% \node [fit = (2-1),fill = blue!15] {} ; +% \node [fit = (2-3),fill = blue!15] {} ; +% \node [fit = (3-2),fill = blue!15] {} ; +% \end{tikzpicture}}] +% a & a + b & a + b + c \\ +% a & a & a + b \\ +% a & a & a +% \end{pNiceMatrix}\] +% % +% \medskip +% 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 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|.\footnote{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.} +% \[\begin{pNiceMatrix}[ +% create-large-nodes,left-margin,right-margin, +% code-after = {\begin{tikzpicture} +% [every node/.style = {blend mode = multiply, +% inner sep = 0pt}, +% name suffix = -large] +% \node [fit = (1-1),fill = red!15] {} ; +% \node [fit = (1-3),fill = red!15] {} ; +% \node [fit = (2-2),fill = red!15] {} ; +% \node [fit = (3-1),fill = red!15] {} ; +% \node [fit = (3-3),fill = red!15] {} ; +% \node [fit = (1-2),fill = blue!15] {} ; +% \node [fit = (2-1),fill = blue!15] {} ; +% \node [fit = (2-3),fill = blue!15] {} ; +% \node [fit = (3-2),fill = blue!15] {} ; +% \end{tikzpicture}}] +% a & a + b & a + b + c \\ +% a & a & a + b \\ +% a & a & a +% \end{pNiceMatrix}\] +% +% \medskip +% 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. +% \[\begin{pNiceMatrix}[ +% create-large-nodes,margin,extra-margin=3pt, +% code-after = {\begin{tikzpicture} +% [every node/.style = {blend mode = multiply, +% inner sep = 0 pt}, +% name suffix = -large] +% \node [fit = (1-1),fill = red!15] {} ; +% \node [fit = (1-3),fill = red!15] {} ; +% \node [fit = (2-2),fill = red!15] {} ; +% \node [fit = (3-1),fill = red!15] {} ; +% \node [fit = (3-3),fill = red!15] {} ; +% \node [fit = (1-2),fill = blue!15] {} ; +% \node [fit = (2-1),fill = blue!15] {} ; +% \node [fit = (2-3),fill = blue!15] {} ; +% \node [fit = (3-2),fill = blue!15] {} ; +% \end{tikzpicture}}] +% a & a + b & a + b + c \\ +% a & a & a + b \\ +% a & a & a +% \end{pNiceMatrix}\] % -% \subsection{The option light-syntax} % -% \label{light-syntax} -% The option |light-syntax|\footnote{This option is inspired by the package -% \pkg{spalign} of Joseph Rabinoff.} allows the user to compose the arrays with a -% lighter syntax, which gives a more readable TeX source. % -% When this option is used, one should use the semicolon for the end of a row -% and spaces or tabulations to separate the columns. However, as usual in the -% TeX world, the spaces after a control sequence are discarded and the elements -% between curly braces are considered as a whole. +% \bigskip +% \textbf{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). % % \bigskip -% The following example has been composed with XeLaTeX with \pkg{unicode-math}, -% which allows the use of greek letters directly in the TeX source. +% \begin{minipage}[c]{7.6cm} +% Here is a array composed with the following code: % % \medskip -% \begin{scope} -% \begin{BVerbatim}[baseline=c,boxwidth=10cm] -% $\begin{bNiceMatrix}[~emphase#light-syntax@,first-row,first-col] -% {} a b ; -% a 2\cos a {\cos a + \cos b} ; -% b \cos a+\cos b { 2 \cos b } -% \end{bNiceMatrix}$ +% \begin{BVerbatim} +% \large +% \begin{NiceTabular}{wl{2cm}LL}[hvlines] +% fraise & amande & abricot \\ +% prune & pêche & poire \\[1ex] +% noix & noisette & brugnon +% \end{NiceTabular} % \end{BVerbatim} +% \end{minipage} +% \hspace{0.9cm} +% \begin{scope} +% \large +% \begin{NiceTabular}[c]{wl{2cm}LL}[hvlines] +% fraise & amande & abricot \\ +% prune & pêche & poire \\[1ex] +% noix & noisette & brugnon +% \end{NiceTabular} +% \end{scope} +% +% \vspace{1cm} +% \begin{minipage}[c]{7cm} +% Here, we have colored all the cells of the array with |\chessboardcolors|. +% \end{minipage} +% \hspace{1.5cm} +% \begin{scope} +% \large +% \begin{NiceTabular}[c]{wl{2cm}LL}[hvlines,code-before = \chessboardcolors{red!15}{blue!15}] +% fraise & amande & abricot \\ +% prune & pêche & poire \\[1ex] +% noix & noisette & brugnon +% \end{NiceTabular} +% \end{scope} +% +% +% \vspace{1cm} +% \begin{minipage}[c]{7cm} +% Here are the ``large nodes'' of this array (without utilisation of |margin| +% nor |extra-margin|). +% \end{minipage} +% \hspace{1.5cm} +% \begin{scope} +% \large +% \begin{NiceTabular}[c]{wl{2cm}LL}[hvlines, +% create-large-nodes, +% code-after = {\begin{tikzpicture} +% [every node/.style = {blend mode = multiply, +% inner sep = 0 pt}, +% name suffix = -large] +% \node [fit = (1-1),fill = red!15] {} ; +% \node [fit = (1-3),fill = red!15] {} ; +% \node [fit = (2-2),fill = red!15] {} ; +% \node [fit = (3-1),fill = red!15] {} ; +% \node [fit = (3-3),fill = red!15] {} ; +% \node [fit = (1-2),fill = blue!15] {} ; +% \node [fit = (2-1),fill = blue!15] {} ; +% \node [fit = (2-3),fill = blue!15] {} ; +% \node [fit = (3-2),fill = blue!15] {} ; +% \end{tikzpicture}}] +% fraise & amande & abricot \\ +% prune & pêche & poire \\[1ex] +% noix & noisette & brugnon +% \end{NiceTabular} % \end{scope} -% $\begin{bNiceMatrix}[light-syntax,first-row,first-col] -% {} a b ; -% a 2\cos a {\cos a + \cos b} ; -% b \cos a+\cos b { 2 \cos b } -% \end{bNiceMatrix}$ % -% \medskip -% 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. % -% \medskip -% 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.\footnote{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.} -% -% \subsection{Use of the column type S of siunitx} % -% If the package \pkg{siunitx} is loaded (before or after \pkg{nicematrix}), -% it's possible to use the |S| column type of \pkg{siunitx} in the environments -% of \pkg{nicematrix}. The implementation doesn't use explicitly any private -% macro of \pkg{siunitx}. -% % -% \medskip -% \begin{BVerbatim}[baseline = c, boxwidth = 10.5cm] -% $\begin{pNiceArray}{~emphase#S@CWc{1cm}C}[nullify-dots,first-row] -% {C_1} & \Cdots & & C_n \\ -% 2.3 & 0 & \Cdots & 0 \\ -% 12.4 & \Vdots & & \Vdots \\ -% 1.45 \\ -% 7.2 & 0 & \Cdots & 0 -% \end{pNiceArray}$ -% \end{BVerbatim} -% $\begin{pNiceArray}{SCWc{1cm}C}[nullify-dots,first-row] -% {C_1} & \Cdots & & C_n \\ -% 2.3 & 0 & \Cdots & 0 \\ -% 12.4 & \Vdots & & \Vdots \\ -% 1.45 \\ -% 7.2 & 0 & \Cdots & 0 -% \end{pNiceArray}$ +% \subsection{The ``row-nodes'' and the ``col-nodes''} +% +% The package \pkg{nicematrix} creates a PGF/Tikz node indicating the potential +% position of each horizontal rule (with the names |row-|$i$) and each vertical +% rule (with the names |col-|$j$), as described in the following figure. These +% nodes are available in the |code-before| and the |code-after|. +% \begin{center} +% \begin{NiceTabular}{CCC}[hvlines,rules/width=1pt,rules/color=gray] +% rose & tulipe & lys \\ +% arum & iris & violette \\ +% muguet & dahlia & souci +% \CodeAfter +% \tiny +% \begin{tikzpicture} +% \foreach \i in {1,2,3,4} +% { +% \fill [red] (row-\i) circle (0.5mm) ; +% \node [red,anchor=east] at (row-\i) {row-\i} ; +% } +% \foreach \j in {1,2,3,4} +% { +% \fill [blue] (col-\j) circle (0.5mm) ; +% \node [blue,anchor=north] at (col-\j) {col-\j} ; +% } +% \end{tikzpicture} +% \end{NiceTabular} +% \end{center} % -% \medskip -% On the other hand, the |d| columns of the package \pkg{dcolumn} are not -% supported by \pkg{nicematrix}. +% \bigskip +% If we use Tikz (we remind that \pkg{nicematrix} does not load Tikz by +% default), we can access (in the |code-before| and the |code-after|) to the +% intersection of the horizontal rule~$i$ and the vertical rule~$j$ with the +% syntax |(row-|$i$\verb+-|col-+$j$|)|. % +% \medskip +% \begin{Verbatim} +% \[\begin{NiceMatrix}[ +% code-before = +% { +% ~emphase# \tikz \draw [fill = red!15] @ +% ~emphase# (row-7-|col-4) -- (row-8-|col-4) -- (row-8-|col-5) -- @ +% ~emphase# (row-9-|col-5) -- (row-9-|col-6) |- cycle ; @ +% } +% ] +% 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}\] +% \end{Verbatim} +% \[\begin{NiceMatrix}[ +% code-before = +% { +% \tikz \draw [fill = red!15] +% (row-7-|col-4) -- (row-8-|col-4) -- (row-8-|col-5) -- +% (row-9-|col-5) -- (row-9-|col-6) |- cycle ; +% } +% ] +% 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}\] % % % \section{Technical remarks} @@ -2153,28 +2532,10 @@ version 2005/12/01 or later. % \end{scope} % % \medskip -% The specifier |?| may be used in a standard environment |{array}| (of the -% package \pkg{array}) and, in this case, the command |\OnlyMainNiceMatrix| is -% no-op. -% -% -% \subsection{The names of the PGF nodes created by nicematrix} -% -% We have said that, when a name is given to an environment of \pkg{nicematrix}, -% it's possible to access the PGF/Tikz nodes through this name (cf. -% p.~\pageref{name}). +% This specifier |?| may be used in the standard environments |{tabular}| and +% |{array}| (of the package \pkg{array}) and, in this case, the command +% |\OnlyMainNiceMatrix| is no-op. % -% That's the recommended way to access these nodes. However, we describe now the -% internal names of these nodes. -% -% The environments created by \pkg{nicematrix} are numbered by an internal -% global counter. The command |\NiceMatrixLastEnv| provides the number of the -% last environment of \pkg{nicematrix} (for LaTeX, it's a ``fully expandable'' -% command and not a counter). -% -% For the environment of number~$n$, the node in row~$i$ and column~$j$ has the -% name |nm-|$n$|-|$i$|-|$j$. The |medium| and |large| nodes have the same name, -% suffixed by |-medium| and |-large|. % % % \subsection{Diagonal lines} @@ -2310,95 +2671,16 @@ version 2005/12/01 or later. % environments of \pkg{nicematrix} are not affected). % % -% -% \subsection{A technical problem with the argument of -% \textbackslash\textbackslash} -% -% -% For technical, reasons, if you use the optional argument of the command |\\|, -% the vertical space added will also be added to the ``normal'' node -% corresponding at the previous node. -% -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% \begin{pNiceMatrix} -% a & \frac AB \\~emphase#[2mm]@ -% b & c -% \end{pNiceMatrix} -% \end{BVerbatim} -% $\begin{pNiceMatrix}[ -% code-after = {\tikz \node [inner sep = 0pt, -% fill = red!15, -% blend mode = multiply, -% fit = (1-2) ] {} ; } ] -% a & \frac AB \\[2mm] -% b & c -% \end{pNiceMatrix}$ -% -% \bigskip -% There are two solutions to solve this problem. The first solution is to use a -% TeX command to insert space between the rows. -% -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% \begin{pNiceMatrix} -% a & \frac AB \\ -% ~emphase#\noalign{\kern2mm}@ -% b & c -% \end{pNiceMatrix} -% \end{BVerbatim} -% $\begin{pNiceMatrix}[ -% code-after = {\tikz \node [inner sep = 0pt, -% fill = red!15, -% blend mode = multiply, -% fit = (1-2) ] {} ; } ] -% a & \frac AB \\ -% \noalign{\kern2mm} -% b & c -% \end{pNiceMatrix}$ -% -% -% \bigskip -% The other solution is to use the command |\multicolumn| in the previous cell. -% -% \medskip -% \begin{BVerbatim}[baseline=c,boxwidth=11cm] -% \begin{pNiceMatrix} -% a & ~emphase#\multicolumn1C{\frac AB}@ \\[2mm] -% b & c -% \end{pNiceMatrix} -% \end{BVerbatim} -% $\begin{pNiceMatrix}[ -% code-after = {\tikz \node [inner sep = 0pt, -% fill = red!15, -% blend mode = multiply, -% fit = (1-2) ] {} ; } ] -% a & \multicolumn1C{\frac AB} \\[2mm] -% b & c -% \end{pNiceMatrix}$ % +% \subsection{Incompatibilities} % -% \subsection{Obsolete environments which have been deleted} +% The package \pkg{nicematrix} is not compatible with \pkg{threeparttable}. % -% The version 3.0 of \pkg{nicematrix} has introduced the environment -% |{pNiceArray}| (and its variants) with the options |first-row|, |last-row|, -% |first-col| and |last-col|. +% \medskip +% The package \pkg{nicematrix} is not fully compatible with the package +% \pkg{arydshln} (because this package redefines many internal of \pkg{array}). % -% Consequently the following environments present in previous versions of -% have been deleted from \pkg{nicematrix}. -% % -% \begin{itemize} -% \item |{NiceArrayCwithDelims}| ; -% \item |{pNiceArrayC}|, |{bNiceArrayC}|, |{BNiceArrayC}|, |{vNiceArrayC}|, -% |{VNiceArrayC}| ; -% \item |{NiceArrayRCwithDelims}| ; -% \item |{pNiceArrayRC}|, |{bNiceArrayRC}|, |{BNiceArrayRC}|, |{vNiceArrayRC}|, -% |{VNiceArrayRC}|. -% \end{itemize} % -% However, the definition of those environments is still available (temporarily) -% at the end of the file |nicematrix.sty| after a command |\file_input_stop:|. -% % \section{Examples} % % \subsection{Dotted lines} @@ -2531,11 +2813,9 @@ version 2005/12/01 or later. % \end{scope} % % \vspace{2cm} -% An example for a linear system (the vertical rule has been drawn in blue with -% the tools of \pkg{colortbl}):\par\nobreak +% An example for a linear system:\par\nobreak % % \begin{Verbatim} -% \arrayrulecolor{blue} % $\begin{pNiceArray}{*6C|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 \\ @@ -2544,10 +2824,9 @@ version 2005/12/01 or later. % \Vdots & & &\Ddots & & 0 & \\ % 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 % \end{pNiceArray}$ -% \arrayrulecolor{black} % \end{Verbatim} % -% \arrayrulecolor{blue} +% % \[\begin{pNiceArray}{*6C|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 \\ @@ -2556,7 +2835,6 @@ version 2005/12/01 or later. % \Vdots & & &\Ddots & & 0 & \\ % 0 & & &\Cdots & 0 & 1 & 0 & L_n \gets L_n-L_1 % \end{pNiceArray}\] -% \arrayrulecolor{black} % % % @@ -2746,24 +3024,22 @@ version 2005/12/01 or later. % % % We should remark that the rules we have drawn are drawn \emph{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 command |\hline|, the specifier -% ``"|"'' and the options |hlines| and |vlines| spread the cells (when the -% package \pkg{array} is loaded but, when the package \pkg{nicematrix} is -% loaded, \pkg{array} is always loaded).\footnote{On the other side, the command -% |\cline| doesn't spread the rows of the array.} +% construction of the array and thus, they don't spread the cells of the array. +% We recall that, on the other side, the command |\hline|, the specifier ``"|"'' +% and the options |hlines|, |vlines| and |hvlines| spread the +% cells.\footnote{For the command |\cline|, see the remark +% p.~\pageref{remark-cline}.} % % % \vspace{1cm} -% The package \pkg{nicematrix} is constructed upon the environment |{array}| -% and, therefore, it's possible to use the package \pkg{colortbl} in the -% environments of \pkg{nicematrix}. However, it's not always easy to do a fine -% tuning of \pkg{colortbl}. That's why we propose another method to highlight a +% It's possible to color a row with |\rowcolor| in the |code-before| (or with +% |\rowcolor| of \pkg{colortbl} in the first cell of the row). However, it's not +% possible to do a fine tuning. That's why we describe now method to highlight a % row of the matrix. We create a rectangular Tikz node which encompasses the % nodes of the second row with the Tikz library \pkg{fit}. This Tikz node is % filled after the construction of the matrix. In order to see the text % \emph{under} this node, we have to use transparency with the |blend mode| -% equal to |multiply|. +% equal to |multiply|. % % \tikzset{highlight/.style={rectangle, % fill=red!15, @@ -3318,28 +3594,91 @@ version 2005/12/01 or later. % the rules even if \pkg{colortbl} is not loaded. % \begin{macrocode} \cs_set_protected:Npn \CT@arc@ { } - \NewDocumentCommand { \arrayrulecolor } { m } - { \tl_gset:Nn \CT@arc@ { \color { #1 } } } -% \end{macrocode} -% The following line are from the redefinition of |\hline| of standard LaTeX by -% \pkg{colortbl} (\pkg{array} does not redefine |\hline|). -% \begin{macrocode} + \cs_set:Npn \arrayrulecolor #1 # { \CT@arc { #1 } } + \cs_set:Npn \CT@arc #1 #2 + { + \dim_compare:nNnT \baselineskip = \c_zero_dim \noalign + { \cs_gset:Npn \CT@arc@ { \color #1 { #2 } } } + } \cs_set:Npn \hline { \noalign { \ifnum 0 = `} \fi - \let \hskip \vskip - \let \vrule \hrule - \let \@width \@height + \cs_set_eq:NN \hskip \vskip + \cs_set_eq:NN \vrule \hrule + \cs_set_eq:NN \@width \@height { \CT@arc@ \vline } \futurelet \reserved@a \@xhline } } + } +% \end{macrocode} +% +% \bigskip +% We have to redefine |\cline| for several reasons. The command |\@@_cline| will +% be linked to |\cline| in the beginning of |{NiceArrayWithDelims}|. The +% following commands must \emph{not} be protected. +% \begin{macrocode} +\cs_set:Npn \@@_standard_cline #1 { \@@_standard_cline:w #1 \q_stop } +\cs_set:Npn \@@_standard_cline:w #1-#2 \q_stop + { + \int_compare:nNnT \l_@@_first_col_int = 0 { \omit & } + \int_compare:nNnT { #1 } > 1 { \multispan { \@@_pred:n { #1 } } & } + \multispan { \int_eval:n { #2 - #1 + 1 } } + { \CT@arc@ \leaders \hrule \@height \arrayrulewidth \hfill } +% \end{macrocode} +% Our |\everycr| has been modified. In particular, the creation of the |row| +% node is in the |\everycr| (maybe we should put it with the incrementation of +% |\c@iRow|). Since the following |\cr| correspond to a ``false row'', we have +% to nullify |\everycr|. +% \begin{macrocode} + \everycr { } + \cr + \noalign { \skip_vertical:N -\arrayrulewidth } } % \end{macrocode} % % \bigskip -% The following command are only for efficiency. It must \emph{not} be protected +% The following version of |\cline| spreads the array of a quantity equal +% to |\arrayrulewidth| as does |\hline|. It will be loaded except if the key +% |standard-cline| has been used. +% \begin{macrocode} +\cs_set:Npn \@@_cline +% \end{macrocode} +% We have to act in a fully expandable way since there may be |\noalign| (in the +% |\multispan|) to detect. That's why we use |\exp_arg:Ne| and not |\exp_arg:Nx|. +% \begin{macrocode} + { \exp_args:Ne \@@_cline_i:nn \l_@@_first_col_int } +% \end{macrocode} +% The command |\cline_i:nn| has two arguments. The first is the number of the +% current column (it \emph{must} be used in that column). The second is a +% standard argument of |\cline| of the form \textsl{i}-\textsl{j}. +% \begin{macrocode} +\cs_set:Npn \@@_cline_i:nn #1 #2 { \@@_cline_i:w #1-#2 \q_stop } +\cs_set:Npn \@@_cline_i:w #1-#2-#3 \q_stop + { +% \end{macrocode} +% Now, |#1| is the number of the current column and we have to draw a line from +% the column |#2| to the column |#3| (both included). +% \begin{macrocode} + \int_compare:nNnT { #1 } < { #2 } + { \multispan { \int_eval:n { #2 - #1 } } & } + \multispan { \int_eval:n { #3 - #2 + 1 } } + { \CT@arc@ \leaders \hrule \@height \arrayrulewidth \hfill } +% \end{macrocode} +% You look whether there is another |\cline| to draw (the final user may put +% several |\cline|). +% \begin{macrocode} + \peek_meaning_remove_ignore_spaces:NTF \cline + { & \exp_args:Ne \@@_cline_i:nn { \@@_succ:n { #3 } } } + { \everycr { } \cr } + } + + +% \end{macrocode} +% +% \bigskip +% The following commands are only for efficiency. It must \emph{not} be protected % because it will be used (for instance) in names of \textsc{pgf} nodes. % \begin{macrocode} \cs_new:Npn \@@_succ:n #1 { \the \numexpr #1 + 1 \relax } @@ -3347,6 +3686,23 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip +% The following command is a small shortcut. +% \begin{macrocode} +\cs_new:Npn \@@_math_toggle_token: + { \bool_if:NF \l_@@_NiceTabular_bool \c_math_toggle_token } +% \end{macrocode} +% +% \bigskip +% \begin{macrocode} +\cs_new_protected:Npn \@@_set_CT@arc@: + { \peek_meaning:NTF [ \@@_set_CT@arc@_i: \@@_set_CT@arc@_ii: } +\cs_new_protected:Npn \@@_set_CT@arc@_i: [ #1 ] #2 \q_stop + { \cs_set:Npn \CT@arc@ { \color [ #1 ] { #2 } } } +\cs_new_protected:Npn \@@_set_CT@arc@_ii: #1 \q_stop + { \cs_set:Npn \CT@arc@ { \color { #1 } } } +% \end{macrocode} +% +% \bigskip % \textbf{The column S of siunitx}\par\nobreak % % \medskip @@ -3486,6 +3842,20 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip +% The command |\NiceMatrixLastEnv| is not used by the package \pkg{nicematrix}. +% It's only a facility given to the final user. It gives the number of the last +% environment (in fact the number of the current environment but it's meant to +% be used after the environment in order to refer to that environment --- and +% its nodes --- without having to give it a name). This command \emph{must} be +% expandable since it will be used in \pkg{pgf} nodes. +% \begin{macrocode} +\NewExpandableDocumentCommand \NiceMatrixLastEnv { } + { \int_use:N \g_@@_env_int } +% \end{macrocode} +% +% +% +% \bigskip % The following command is only a syntaxic shortcut. The |q| in |qpoint| means % \emph{quick}. % \begin{macrocode} @@ -3525,11 +3895,8 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip -% If the user uses |{NiceArray}| (and not another environment relying upon -% |{NiceArrayWithDelims}| like |{pNiceArray}|), we will raise the flag -% |\l_@@_NiceArray_bool|. We have to know that, because, in |{NiceArray}|, we -% won't use a structure with |\left| and |\right| and we will use the option of -% position (|t|, |b| or |c|). +% If the user uses |{NiceArray}| or |{NiceTabular}| the flag +% |\l_@@_NiceArray_bool| will be raised. % \begin{macrocode} \bool_new:N \l_@@_NiceArray_bool % \end{macrocode} @@ -3615,7 +3982,14 @@ version 2005/12/01 or later. % % The TeX counters |\c@iRow| and |\c@jCol| will be created in the beginning of % |{NiceArrayWithDelims}| (if they don't exist previously). -% +% +% \bigskip +% The following token list corresponds to the key |rules/color| available +% in the environments. +% \begin{macrocode} +\tl_new:N \l_@@_rules_color_tl +% \end{macrocode} +% % \bigskip % A kind of false row will be inserted at the end of the array for the % construction of the |col| nodes (and also to fix the width of the columns when @@ -3676,6 +4050,42 @@ version 2005/12/01 or later. \dim_new:N \g_@@_width_first_col_dim % \end{macrocode} % +% \bigskip +% The following sequence will contain the caracteristics of the blocks of the +% array, specified by the command |\Block|. Each block is represented by 6 +% components surrounded by braces: +% +% |{|\textsl{imin}|}{|\textsl{jmin}|}{|\textsl{imax}|}{|\textsl{jmax}|}{|\textsl{options}|}{|\textsl{contents}|}|. +% +% The variable is global because it will be modified in the cells of the array. +% \begin{macrocode} +\seq_new:N \g_@@_blocks_seq +% \end{macrocode} +% We also manage a sequence of the \emph{positions} of the blocks. Of course, +% it's redundant with the previous sequence, but it's for efficiency. In that +% sequence, each block is represented by only the four first components: +% |{|\textsl{imin}|}{|\textsl{jmin}|}{|\textsl{imax}|}{|\textsl{jmax}|}|. +% \begin{macrocode} +\seq_new:N \g_@@_pos_of_blocks_seq +% \end{macrocode} +% The sequence |\g_@@_pos_of_blocks_seq| will be used by the test of +% non-overlapping of two blocks and when we will draw the rules required by the +% key |hvlines| (these rules won't be drawn within the blocks). +% +% \bigskip +% We will also manage a sequence for the positions of the dotted lines. These +% dotted lines are created in the array by |\Cdots|, |\Vdots|, |\Ddots|, etc. +% However, their positions, that is to say, their extremities, will be +% determined only after the construction of the array. In this sequence, each +% item contains four components: +% |{|\textsl{imin}|}{|\textsl{jmin}|}{|\textsl{imax}|}{|\textsl{jmax}|}|. +% \begin{macrocode} +\seq_new:N \g_@@_pos_of_xdots_seq +% \end{macrocode} +% The sequence |\g_@@_pos_of_xdots_seq| will be used when we will draw the rules +% required by the key |hvlines| (these rules won't be drawn within the virtual +% blocks corresponding to the dotted lines). +% % % \bigskip % \textbf{Variables for the exterior rows and columns}\par\nobreak @@ -3841,7 +4251,15 @@ version 2005/12/01 or later. % \bigskip % \subsection*{The options} % +% By default, the behaviour of |\cline| is changed in the environments of +% \pkg{nicematrix}: a |\cline| spreads the array by an amount equal to +% |\arrayrulewidht|. It's possible to disable this feature with the key +% |\l_@@_standard_line_bool|. +% \begin{macrocode} +\bool_new:N \l_@@_standard_cline_bool +% \end{macrocode} % +% \bigskip % The following dimensions correspond to the options |cell-space-top-limit| and co % (these parameters are inspired by the package \pkg{cellspace}). % \begin{macrocode} @@ -3922,11 +4340,15 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip -% The flag |\l_@@_hlines_bool| corresponds to the option |\hlines| and the flag -% |\l_@@_vlines_bool| to the option |\vlines|. +% The flag |\l_@@_hlines_bool| corresponds to the key |hlines|, the flag +% |\l_@@_vlines_bool| to the key |vlines| and the flag |hvlines| to the key +% |hvlines|. Since version 4.1, the key |hvlines| is no longer a mere alias for +% the conjonction of |hlines| and |vlines|. Indeed, with |hvlines|, the vertical +% and horizontal rules are \emph{not} drawn within the blocks (created by |\Block|). % \begin{macrocode} \bool_new:N \l_@@_hlines_bool \bool_new:N \l_@@_vlines_bool +\bool_new:N \l_@@_hvlines_bool % \end{macrocode} % % \bigskip @@ -4052,8 +4474,20 @@ version 2005/12/01 or later. % % % \begin{macrocode} +\keys_define:nn { NiceMatrix / rules } + { + color .tl_set:N = \l_@@_rules_color_tl , + color .value_required:n = true , + width .dim_set:N = \arrayrulewidth , + width .value_required:n = true + } +% \end{macrocode} +% +% \begin{macrocode} \keys_define:nn { NiceMatrix / Global } { + standard-cline .bool_set:N = \l_@@_standard_cline_bool , + standard-cline .default:n = true , cell-space-top-limit .dim_set:N = \l_@@_cell_space_top_limit_dim , cell-space-top-limit .value_required:n = true , cell-space-bottom-limit .dim_set:N = \l_@@_cell_space_bottom_limit_dim , @@ -4078,7 +4512,12 @@ version 2005/12/01 or later. code-for-last-row .value_required:n = true , hlines .bool_set:N = \l_@@_hlines_bool , vlines .bool_set:N = \l_@@_vlines_bool , - hvlines .meta:n = { hlines , vlines } , + hvlines .code:n = + { + \bool_set_true:N \l_@@_hvlines_bool + \bool_set_true:N \l_@@_vlines_bool + \bool_set_true:N \l_@@_hlines_bool + } , parallelize-diags .bool_set:N = \l_@@_parallelize_diags_bool , % \end{macrocode} % @@ -4175,24 +4614,28 @@ version 2005/12/01 or later. NiceMatrix / Env , } , NiceMatrix / xdots .inherit:n = NiceMatrix / xdots , + NiceMatrix / rules .inherit:n = NiceMatrix / rules , NiceTabular .inherit:n = { NiceMatrix / Global , NiceMatrix / Env } , NiceTabular / xdots .inherit:n = NiceMatrix / xdots , + NiceTabular / rules .inherit:n = NiceMatrix / rules , NiceArray .inherit:n = { NiceMatrix / Global , NiceMatrix / Env , } , NiceArray / xdots .inherit:n = NiceMatrix / xdots , + NiceArray / rules .inherit:n = NiceMatrix / rules , pNiceArray .inherit:n = { NiceMatrix / Global , NiceMatrix / Env , } , - pNiceArray / xdots .inherit:n = NiceMatrix / xdots + pNiceArray / xdots .inherit:n = NiceMatrix / xdots , + pNiceArray / rules .inherit:n = NiceMatrix / rules , } % \end{macrocode} % @@ -4358,6 +4801,9 @@ version 2005/12/01 or later. % \begin{macrocode} \keys_define:nn { NiceMatrix / NiceTabular } { + last-col .code:n = \tl_if_empty:nF {#1} + { \@@_error:n { last-col~non~empty~for~NiceArray } } + \int_zero:N \l_@@_last_col_int , unknown .code:n = \@@_error:n { Unknown~option~for~NiceTabular } } % \end{macrocode} @@ -4480,7 +4926,7 @@ version 2005/12/01 or later. % \begin{macrocode} \cs_new_protected:Npn \@@_end_Cell: { - \bool_if:NF \l_@@_NiceTabular_bool \c_math_toggle_token + \@@_math_toggle_token: \hbox_set_end: % \end{macrocode} % @@ -4712,7 +5158,8 @@ version 2005/12/01 or later. { \@@_create_row_node: % \end{macrocode} -% We add the potential horizontal lines specified by the option |hlines|. +% We don't draw the rules of the key |hlines| (or |hvlines|) but we reserve the +% vertical space for theses rules. % \begin{macrocode} \bool_if:NT \l_@@_hlines_bool { @@ -4730,7 +5177,7 @@ version 2005/12/01 or later. % \pkg{colortbl} is not loaded. We use a TeX group in order to limit the scope % of |\CT@arc@|. % \begin{macrocode} - { { \CT@arc@ \hrule height \arrayrulewidth } } + { \hrule height \arrayrulewidth width \c_zero_dim } } } } @@ -4895,6 +5342,9 @@ version 2005/12/01 or later. \cs_set_eq:NN \@@_old_iddots \iddots \cs_set_eq:NN \firsthline \hline \cs_set_eq:NN \lasthline \hline + \bool_if:NTF \l_@@_standard_cline_bool + { \cs_set_eq:NN \cline \@@_standard_cline } + { \cs_set_eq:NN \cline \@@_cline } \cs_set_eq:NN \Ldots \@@_Ldots \cs_set_eq:NN \Cdots \@@_Cdots \cs_set_eq:NN \Vdots \@@_Vdots @@ -4910,7 +5360,7 @@ version 2005/12/01 or later. \cs_set_eq:NN \OnlyMainNiceMatrix \@@_OnlyMainNiceMatrix:n \cs_set_eq:NN \dotfill \@@_dotfill: \cs_set_eq:NN \CodeAfter \@@_CodeAfter:n - \cs_set_eq:NN \slashbox \@@_slashbox:nn + \cs_set_eq:NN \diagbox \@@_diagbox:nn \bool_if:NT \l_@@_renew_dots_bool { \cs_set_eq:NN \ldots \@@_Ldots @@ -5123,9 +5573,19 @@ version 2005/12/01 or later. \bool_if:NT \l_@@_in_env_bool { \@@_fatal:n { Yet~in~env } } \bool_set_true:N \l_@@_in_env_bool % \end{macrocode} +% The command |\CT@arc@| contains the instruction of color for the rules of the +% array\footnote{e.g. |\color[rgb]{0.5,0.5,0}|)}. This command is used by |\CT@arc@| but +% we use it also for compatibility with \pkg{colortbl}. But we want also to be +% able to use color for the rules of the array when \pkg{colortbl} is \emph{not} +% loaded. That's why we do the following instruction which is in the patch of +% the beginning of arrays done by \pkg{colortbl}. Of course, we restore the +% value of |\CT@arc@| at the end of our environment. +% \begin{macrocode} + \cs_gset_eq:NN \@@_old_CT@arc@ \CT@arc@ +% \end{macrocode} % -% We deactivate Tikz externalization because we will use \textsc{pgf} pictures with the -% options |overlay| and |remember picture| (or equivalent forms). +% We deactivate Tikz externalization because we will use \textsc{pgf} pictures +% with the options |overlay| and |remember picture| (or equivalent forms). % \begin{macrocode} \cs_if_exist:NT \tikz@library@external@loaded { @@ -5151,7 +5611,16 @@ version 2005/12/01 or later. \cs_set_protected:Npn \@arrayrule { \@addtopreamble \@@_vline: } % \end{macrocode} % -% +% The sequence |\g_@@_blocks_seq| will contain the carateristics of the blocks +% (specified by |\Block|) of the array. The sequence |\g_@@_pos_of_blocks_seq| +% will contain only the position of the blocks. Of course, this is redundant but +% it's for efficiency. +% \begin{macrocode} + \seq_clear:N \g_@@_blocks_seq + \seq_clear:N \g_@@_pos_of_blocks_seq +% \end{macrocode} +% +% % The set of keys is not exactly the same for |{NiceArray}| and for the variants % of |{NiceArray}| (|{pNiceArray}|, |{bNiceArray}|, etc.) because, for % |{NiceArray}|, we have the options |t|, |c|, |b| and |baseline|. @@ -5161,7 +5630,13 @@ version 2005/12/01 or later. { \keys_set:nn { NiceMatrix / pNiceArray } } { #3 , #5 } % \end{macrocode} -% +% +% \bigskip +% \begin{macrocode} + \tl_if_empty:NF \l_@@_rules_color_tl + { \exp_after:wN \@@_set_CT@arc@: \l_@@_rules_color_tl \q_stop } +% \end{macrocode} +% % \bigskip % If the key |code-before| is used, we have to create the |col| nodes and the % |row| nodes before the creation of the array. First, we have to test whether @@ -5228,21 +5703,18 @@ version 2005/12/01 or later. \group_begin: \bool_if:NT \c_@@_tikz_loaded_bool { -% \end{macrocode} -% Be careful: we must \emph{not} put ``|remember picture|'' in the |\pgfset|. -% \begin{macrocode} - \pgfset + \tikzset { every~picture / .style = - { overlay , name~prefix = \@@_env: - } + { overlay , name~prefix = \@@_env: - } } - } - \cs_set_eq:NN \cellcolor \@@_cellcolor:nn - \cs_set_eq:NN \rectanglecolor \@@_rectanglecolor:nnn - \cs_set_eq:NN \rowcolor \@@_rowcolor:nn - \cs_set_eq:NN \rowcolors \@@_rowcolors:nnn - \cs_set_eq:NN \columncolor \@@_columncolor:nn - \cs_set_eq:NN \chessboardcolors \@@_chessboardcolors:nn + } + \cs_set_eq:NN \cellcolor \@@_cellcolor + \cs_set_eq:NN \rectanglecolor \@@_rectanglecolor + \cs_set_eq:NN \rowcolor \@@_rowcolor + \cs_set_eq:NN \rowcolors \@@_rowcolors + \cs_set_eq:NN \columncolor \@@_columncolor + \cs_set_eq:NN \chessboardcolors \@@_chessboardcolors % \end{macrocode} % We compose the |code-before| in math mode in order to nullify the spaces put % by the user between instructions in the |code-before|. @@ -5745,7 +6217,7 @@ version 2005/12/01 or later. { \box_ht:N \l_tmpa_box + \box_dp:N \l_tmpa_box } { } } - \right . + \right . \c_math_toggle_token } \dim_set:Nn \l_@@_real_left_delim_dim @@ -6106,7 +6578,7 @@ version 2005/12/01 or later. % have to compute some dimensions of this box. % \begin{macrocode} \hbox_set:Nw \l_@@_cell_box - \bool_if:NF \l_@@_NiceTabular_bool \c_math_toggle_token + \@@_math_toggle_token: \bool_if:NT \l_@@_small_bool \scriptstyle % \end{macrocode} % We insert |\l_@@_code_for_first_col_tl|... but we don't insert it in the @@ -6131,7 +6603,7 @@ version 2005/12/01 or later. l < { - \bool_if:NF \l_@@_NiceTabular_bool \c_math_toggle_token + \@@_math_toggle_token: \hbox_set_end: \@@_update_for_first_and_last_row: % \end{macrocode} @@ -6178,7 +6650,7 @@ version 2005/12/01 or later. % have to compute some dimensions of this box. % \begin{macrocode} \hbox_set:Nw \l_@@_cell_box - \bool_if:NF \l_@@_NiceTabular_bool \c_math_toggle_token + \@@_math_toggle_token: \bool_if:NT \l_@@_small_bool \scriptstyle % \end{macrocode} % We insert |\l_@@_code_for_last_col_tl|... but we don't insert it in the @@ -6198,7 +6670,7 @@ version 2005/12/01 or later. l < { - \bool_if:NF \l_@@_NiceTabular_bool \c_math_toggle_token + \@@_math_toggle_token: \hbox_set_end: \@@_update_for_first_and_last_row: % \end{macrocode} @@ -6354,6 +6826,7 @@ version 2005/12/01 or later. % \begin{macrocode} \NewDocumentEnvironment { NiceTabular } { O { } m ! O { } } { + \str_gset:Nn \g_@@_name_env_str { NiceTabular } \keys_set:nn { NiceMatrix / NiceTabular } { #1 , #3 } \bool_set_true:N \l_@@_NiceTabular_bool \NiceArray { #2 } @@ -6537,18 +7010,26 @@ version 2005/12/01 or later. } % \end{macrocode} % -% % \bigskip -% Now, we really draw the dotted lines. +% Now, we actually draw the dotted lines. % \begin{macrocode} \@@_draw_dotted_lines: % \end{macrocode} % -% We draw the vertical rules of the option |vlines| before the -% |internal-code-after| because the option |white| of a |\Block| may have to -% erase these vertical rules. % \begin{macrocode} - \bool_if:NT \l_@@_vlines_bool \@@_draw_vlines: + \bool_if:NTF \l_@@_hvlines_bool + \@@_draw_hvlines: + { + \bool_if:NT \l_@@_hlines_bool \@@_draw_hlines: + \bool_if:NT \l_@@_vlines_bool \@@_draw_vlines: + } +% \end{macrocode} +% +% We have to revert to a clean version of |\ialign| because there may be +% tabulars in the |\Block| instructions that will be composed now. +% \begin{macrocode} + \cs_set_eq:NN \ialign \@@_old_ialign: + \seq_if_empty:NF \g_@@_blocks_seq \@@_draw_blocks: \g_@@_internal_code_after_tl \tl_gclear:N \g_@@_internal_code_after_tl \bool_if:NT \c_@@_tikz_loaded_bool @@ -6579,9 +7060,19 @@ version 2005/12/01 or later. \group_end: \str_gclear:N \g_@@_name_env_str \@@_restore_iRow_jCol: +% \end{macrocode} +% The command |\CT@arc@| contains the instruction of color for the rules of the +% array\footnote{e.g. |\color[rgb]{0.5,0.5,0}|)}. This command is used by +% |\CT@arc@| but we use it also for compatibility with \pkg{colortbl}. But we +% want also to be able to use color for the rules of the array when +% \pkg{colortbl} is \emph{not} loaded. That's why we do the following +% instruction which is in the patch of the end of arrays done by \pkg{colortbl}. +% \begin{macrocode} + \cs_gset_eq:NN \CT@arc@ \@@_old_CT@arc@ } % \end{macrocode} % +% % \bigskip % We recall that, when externalization is used, |\tikzpicture| and % |\endtikzpicture| (or |\pgfpicture| and |\endpgfpicture|) must be directly @@ -6625,7 +7116,10 @@ version 2005/12/01 or later. } % \end{macrocode} % +% % \bigskip +% \subsection*{We draw the dotted lines} +% % A dotted line will be said \emph{open} in one of its extremities when it stops % on the edge of the matrix and \emph{closed} otherwise. In the following % matrix, the dotted line is closed on its left extremity and open on its right. @@ -6847,6 +7341,21 @@ version 2005/12/01 or later. } } } +% \end{macrocode} +% If the key |hvlines| is used, we remind the rectangle described by all the +% dotted lines in order to respect the corresponding virtual ``block'' when +% drawing the horizontal and vertical rules. +% \begin{macrocode} + \bool_if:NT \l_@@_hvlines_bool + { + \seq_gput_right:Nx \g_@@_pos_of_xdots_seq + { + { \int_use:N \l_@@_initial_i_int } + { \int_use:N \l_@@_initial_j_int } + { \int_use:N \l_@@_final_i_int } + { \int_use:N \l_@@_final_j_int } + } + } } % \end{macrocode} % @@ -7354,17 +7863,6 @@ version 2005/12/01 or later. % % % \bigskip -% The command |\NiceMatrixLastEnv| is not used by the package \pkg{nicematrix}. -% It's only a facility given to the final user. It gives the number of the last -% environment (in fact the number of the current environment but it's meant to -% be used after the environment in order to refer to that environment --- and -% its nodes --- without having to give it a name). -% \begin{macrocode} -\NewExpandableDocumentCommand \NiceMatrixLastEnv { } - { \int_use:N \g_@@_env_int } -% \end{macrocode} -% -% \bigskip % \subsection*{The actual instructions for drawing the dotted line with Tikz} % % The command |\@@_draw_line:| should be used in a |{pgfpicture}|. It has six @@ -7653,23 +8151,19 @@ version 2005/12/01 or later. % \begin{macrocode} \AtBeginDocument { - \tl_set:Nn \l_@@_argspec_tl { s O { } E { _ ^ } { { } { } } } + \tl_set:Nn \l_@@_argspec_tl { O { } E { _ ^ } { { } { } } } \tl_set_rescan:Nno \l_@@_argspec_tl { } \l_@@_argspec_tl \exp_args:NNV \NewDocumentCommand \@@_Ldots \l_@@_argspec_tl { - \bool_if:nTF { #1 } - { \@@_error:n { starred~commands } } + \int_compare:nNnTF \c@jCol = 0 + { \@@_error:nn { in~first~col } \Ldots } { - \int_compare:nNnTF \c@jCol = 0 - { \@@_error:nn { in~first~col } \Ldots } + \int_compare:nNnTF \c@jCol = \l_@@_last_col_int + { \@@_error:nn { in~last~col } \Ldots } { - \int_compare:nNnTF \c@jCol = \l_@@_last_col_int - { \@@_error:nn { in~last~col } \Ldots } - { - \@@_instruction_of_type:nn { Ldots } - { #2 , down = #3 , up = #4 } - } - } + \@@_instruction_of_type:nn { Ldots } + { #1 , down = #2 , up = #3 } + } } \bool_if:NF \l_@@_nullify_dots_bool { \phantom \@@_old_ldots } \bool_gset_true:N \g_@@_empty_cell_bool @@ -7680,19 +8174,15 @@ version 2005/12/01 or later. % \begin{macrocode} \exp_args:NNV \NewDocumentCommand \@@_Cdots \l_@@_argspec_tl { - \bool_if:nTF { #1 } - { \@@_error:n { starred~commands } } + \int_compare:nNnTF \c@jCol = 0 + { \@@_error:nn { in~first~col } \Cdots } { - \int_compare:nNnTF \c@jCol = 0 - { \@@_error:nn { in~first~col } \Cdots } + \int_compare:nNnTF \c@jCol = \l_@@_last_col_int + { \@@_error:nn { in~last~col } \Cdots } { - \int_compare:nNnTF \c@jCol = \l_@@_last_col_int - { \@@_error:nn { in~last~col } \Cdots } - { - \@@_instruction_of_type:nn { Cdots } - { #2 , down = #3 , up = #4 } - } - } + \@@_instruction_of_type:nn { Cdots } + { #1 , down = #2 , up = #3 } + } } \bool_if:NF \l_@@_nullify_dots_bool { \phantom \@@_old_cdots } \bool_gset_true:N \g_@@_empty_cell_bool @@ -7703,18 +8193,16 @@ version 2005/12/01 or later. % \begin{macrocode} \exp_args:NNV \NewDocumentCommand \@@_Vdots \l_@@_argspec_tl { - \bool_if:nTF { #1 } - { \@@_error:n { starred~commands } } - \int_compare:nNnTF \c@iRow = 0 - { \@@_error:nn { in~first~row } \Vdots } + \int_compare:nNnTF \c@iRow = 0 + { \@@_error:nn { in~first~row } \Vdots } + { + \int_compare:nNnTF \c@iRow = \l_@@_last_row_int + { \@@_error:nn { in~last~row } \Vdots } { - \int_compare:nNnTF \c@iRow = \l_@@_last_row_int - { \@@_error:nn { in~last~row } \Vdots } - { - \@@_instruction_of_type:nn { Vdots } - { #2 , down = #3 , up = #4 } - } - } + \@@_instruction_of_type:nn { Vdots } + { #1 , down = #2 , up = #3 } + } + } \bool_if:NF \l_@@_nullify_dots_bool { \phantom \@@_old_vdots } \bool_gset_true:N \g_@@_empty_cell_bool } @@ -7724,27 +8212,23 @@ version 2005/12/01 or later. % \begin{macrocode} \exp_args:NNV \NewDocumentCommand \@@_Ddots \l_@@_argspec_tl { - \bool_if:nTF { #1 } - { \@@_error:n { starred~commands } } + \int_case:nnF \c@iRow + { + 0 { \@@_error:nn { in~first~row } \Ddots } + \l_@@_last_row_int { \@@_error:nn { in~last~row } \Ddots } + } { - \int_case:nnF \c@iRow + \int_case:nnF \c@jCol { - 0 { \@@_error:nn { in~first~row } \Ddots } - \l_@@_last_row_int { \@@_error:nn { in~last~row } \Ddots } + 0 { \@@_error:nn { in~first~col } \Ddots } + \l_@@_last_col_int { \@@_error:nn { in~last~col } \Ddots } } - { - \int_case:nnF \c@jCol - { - 0 { \@@_error:nn { in~first~col } \Ddots } - \l_@@_last_col_int { \@@_error:nn { in~last~col } \Ddots } - } - { - \@@_instruction_of_type:nn { Ddots } - { #2 , down = #3 , up = #4 } - } + { + \@@_instruction_of_type:nn { Ddots } + { #1 , down = #2 , up = #3 } + } - } - } + } \bool_if:NF \l_@@_nullify_dots_bool { \phantom \@@_old_ddots } \bool_gset_true:N \g_@@_empty_cell_bool } @@ -7754,27 +8238,23 @@ version 2005/12/01 or later. % \begin{macrocode} \exp_args:NNV \NewDocumentCommand \@@_Iddots \l_@@_argspec_tl { - \bool_if:nTF { #1 } - { \@@_error:n { starred~commands } } + \int_case:nnF \c@iRow + { + 0 { \@@_error:nn { in~first~row } \Iddots } + \l_@@_last_row_int { \@@_error:nn { in~last~row } \Iddots } + } { - \int_case:nnF \c@iRow + \int_case:nnF \c@jCol { - 0 { \@@_error:nn { in~first~row } \Iddots } - \l_@@_last_row_int { \@@_error:nn { in~last~row } \Iddots } + 0 { \@@_error:nn { in~first~col } \Iddots } + \l_@@_last_col_int { \@@_error:nn { in~last~col } \Iddots } } - { - \int_case:nnF \c@jCol - { - 0 { \@@_error:nn { in~first~col } \Iddots } - \l_@@_last_col_int { \@@_error:nn { in~last~col } \Iddots } - } - { - \@@_instruction_of_type:nn { Iddots } - { #2 , down = #3 , up = #4 } - } + { + \@@_instruction_of_type:nn { Iddots } + { #1 , down = #2 , up = #3 } + } - } - } + } \bool_if:NF \l_@@_nullify_dots_bool { \phantom \@@_old_iddots } \bool_gset_true:N \g_@@_empty_cell_bool } @@ -7803,13 +8283,26 @@ version 2005/12/01 or later. \cs_new:Npn \@@_multicolumn:nnn #1 #2 #3 { \@@_old_multicolumn { #1 } { #2 } { #3 } - \int_compare:nNnT #1 > 1 +% \end{macrocode} +% The |\peek_remove_spaces:n| is mandatory. +% \begin{macrocode} + \peek_remove_spaces:n { - \seq_gput_left:Nx \g_@@_multicolumn_cells_seq - { \int_use:N \c@iRow - \int_use:N \c@jCol } - \seq_gput_left:Nn \g_@@_multicolumn_sizes_seq { #1 } - } - \int_gadd:Nn \c@jCol { #1 - 1 } + \int_compare:nNnT #1 > 1 + { + \seq_gput_left:Nx \g_@@_multicolumn_cells_seq + { \int_use:N \c@iRow - \int_use:N \c@jCol } + \seq_gput_left:Nn \g_@@_multicolumn_sizes_seq { #1 } + \seq_gput_right:Nx \g_@@_pos_of_blocks_seq + { + { \int_use:N \c@iRow } + { \int_use:N \c@jCol } + { \int_use:N \c@iRow } + { \int_eval:n { \c@jCol + #1 - 1 } } + } + } + \int_gadd:Nn \c@jCol { #1 - 1 } + } } % \end{macrocode} % @@ -8044,14 +8537,20 @@ version 2005/12/01 or later. % The command |\@@_rotate:| will be linked to |\rotate| in % |{NiceArrayWithDelims}|. % -% The command will exit three levels of groups in order +% The command will exit three levels of groups (only two in |{NiceTabular}| +% because there is not the group of the math mode to exit) in order % to execute the command % % \qquad ``|\box_rotate:Nn \l_@@_cell_box { 90 }|'' % % just after the construction of the box |\l_@@_cell_box|. % \begin{macrocode} -\cs_new_protected:Npn \@@_rotate: { \group_insert_after:N \@@_rotate_i: } +\cs_new_protected:Npn \@@_rotate: + { + \bool_if:NTF \l_@@_NiceTabular_bool + { \group_insert_after:N \@@_rotate_ii: } + { \group_insert_after:N \@@_rotate_i: } + } \cs_new_protected:Npn \@@_rotate_i: { \group_insert_after:N \@@_rotate_ii: } \cs_new_protected:Npn \@@_rotate_ii: { \group_insert_after:N \@@_rotate_iii: } \cs_new_protected:Npn \@@_rotate_iii: @@ -8196,21 +8695,25 @@ version 2005/12/01 or later. % % % \bigskip -% Here an example : |\@@_rowcolor:nn {red!15} {1,3,5-7,10-}| +% Here an example : |\@@_rowcolor {red!15} {1,3,5-7,10-}| % \begin{macrocode} -\cs_new_protected:Npn \@@_rowcolor:nn #1 #2 +\NewDocumentCommand \@@_rowcolor { O { } m m } { - \tl_if_blank:nF { #1 } + \tl_if_blank:nF { #2 } { \pgfpicture \pgf@relevantforpicturesizefalse - \pgfsetfillcolor { #1 } + \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 } % \end{macrocode} -% |\l_tmpa_dim| is the $x$-value of the left side of the rows. +% |\l_tmpa_dim| is the $x$-value of the right side of the rows. % \begin{macrocode} + \@@_qpoint:n { col - 1} + \int_compare:nNnTF \l_@@_first_col_int = 0 + { \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth } } + { \dim_set:Nn \l_tmpc_dim { \pgf@x - 0.5 \arrayrulewidth } } \@@_qpoint:n { col - \@@_succ:n \c@jCol } - \dim_set_eq:NN \l_tmpa_dim \pgf@x - \clist_map_inline:nn { #2 } + \dim_set:Nn \l_tmpa_dim { \pgf@x + 0.5 \arrayrulewidth } + \clist_map_inline:nn { #3 } { \tl_set:Nn \l_tmpa_tl { ##1 } \tl_if_in:NnTF \l_tmpa_tl { - } @@ -8225,9 +8728,12 @@ version 2005/12/01 or later. % Now, the numbers of both rows are in |\l_tmpa_tl| and |\l_tmpb_tl|. % \begin{macrocode} \@@_qpoint:n { row - \@@_succ:n \l_tmpb_tl } + \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth } + \@@_qpoint:n { row - \l_tmpa_tl } + \dim_set:Nn \l_tmpd_dim { \pgf@y + 0.5 \arrayrulewidth } \pgfpathrectanglecorners - { \@@_qpoint:n { row - \l_tmpa_tl } } - { \pgfpoint \l_tmpa_dim \pgf@y } + { \pgfpoint \l_tmpc_dim \l_tmpd_dim } + { \pgfpoint \l_tmpa_dim \l_tmpb_dim } } \pgfusepathqfill \endpgfpicture @@ -8238,22 +8744,22 @@ version 2005/12/01 or later. % \bigskip % Here an example : |\@@_columncolor:nn {red!15} {1,3,5-7,10-}| % \begin{macrocode} -\cs_new_protected:Npn \@@_columncolor:nn #1 #2 +\NewDocumentCommand \@@_columncolor { O { } m m } { - \tl_if_blank:nF { #1 } + \tl_if_blank:nF { #2 } { \pgfpicture \pgf@relevantforpicturesizefalse - \pgfsetfillcolor { #1 } + \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 } \@@_qpoint:n { row - 1 } % \end{macrocode} % |\l_tmpa_dim| is the $y$-value of the top of the columns et |\l_tmpb_dim| is % the $y$-value of the bottom. % \begin{macrocode} - \dim_set_eq:NN \l_tmpa_dim \pgf@y + \dim_set:Nn \l_tmpa_dim {\pgf@y + 0.5 \arrayrulewidth } \@@_qpoint:n { row - \@@_succ:n \c@iRow } - \dim_set_eq:NN \l_tmpb_dim \pgf@y - \clist_map_inline:nn { #2 } + \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth } + \clist_map_inline:nn { #3 } { \tl_set:Nn \l_tmpa_tl { ##1 } \tl_if_in:NnTF \l_tmpa_tl { - } @@ -8268,11 +8774,14 @@ version 2005/12/01 or later. % Now, the numbers of both columns are in |\l_tmpa_tl| and |\l_tmpb_tl|. % \begin{macrocode} \@@_qpoint:n { col - \l_tmpa_tl } - \dim_set_eq:NN \l_tmpc_dim \pgf@x + \int_compare:nNnTF \l_@@_first_col_int = \l_tmpa_tl + { \dim_set:Nn \l_tmpc_dim { \pgf@x - 0.5 \arrayrulewidth } } + { \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth } } \@@_qpoint:n { col - \@@_succ:n \l_tmpb_tl } + \dim_set:Nn \l_tmpd_dim { \pgf@x + 0.5 \arrayrulewidth } \pgfpathrectanglecorners { \pgfpoint \l_tmpc_dim \l_tmpa_dim } - { \pgfpoint \pgf@x \l_tmpb_dim } + { \pgfpoint \l_tmpd_dim \l_tmpb_dim } } \pgfusepathqfill \endpgfpicture @@ -8281,16 +8790,16 @@ version 2005/12/01 or later. % \end{macrocode} % % \bigskip -% Here an example : |\@@_cellcolor:nn {red!15}{2-3,3-4,4-5,5-6}| +% Here an example : |\@@_cellcolor[rgb]{0.5,0.5,0}{2-3,3-4,4-5,5-6}| % \begin{macrocode} -\cs_new_protected:Npn \@@_cellcolor:nn #1 #2 +\NewDocumentCommand \@@_cellcolor { O { } m m } { - \tl_if_blank:nF { #1 } + \tl_if_blank:nF { #2 } { \pgfpicture \pgf@relevantforpicturesizefalse - \pgfsetfillcolor { #1 } - \clist_map_inline:nn { #2 } + \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 } + \clist_map_inline:nn { #3 } { \@@_cut_on_hyphen:w ##1 \q_stop \@@_qpoint:n { row - \l_tmpa_tl } @@ -8298,13 +8807,15 @@ version 2005/12/01 or later. { \int_compare_p:n { \l_tmpa_tl <= \c@iRow } } { \int_compare_p:n { \l_tmpb_tl <= \c@jCol } } { - \dim_set_eq:NN \l_tmpb_dim \pgf@y + \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth } \@@_qpoint:n { row - \@@_succ:n \l_tmpa_tl } - \dim_set_eq:NN \l_tmpa_dim \pgf@y + \dim_set:Nn \l_tmpa_dim { \pgf@y + 0.5 \arrayrulewidth } \@@_qpoint:n { col - \l_tmpb_tl } - \dim_set_eq:NN \l_tmpc_dim \pgf@x + \int_compare:nNnTF \l_@@_first_col_int = \l_tmpb_tl + { \dim_set:Nn \l_tmpc_dim { \pgf@x - 0.5 \arrayrulewidth } } + { \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth } } \@@_qpoint:n { col - \@@_succ:n \l_tmpb_tl } - \dim_set_eq:NN \l_tmpd_dim \pgf@x + \dim_set:Nn \l_tmpd_dim { \pgf@x + 0.5 \arrayrulewidth } \pgfpathrectanglecorners { \pgfpoint \l_tmpc_dim \l_tmpb_dim } { \pgfpoint \l_tmpd_dim \l_tmpa_dim } @@ -8312,38 +8823,40 @@ version 2005/12/01 or later. } \pgfusepathqfill \endpgfpicture - } + } } % \end{macrocode} % % \bigskip -% Here an example : |\@@_rectanglecolor:nn {red!15}{2-3}{5-6}| +% Here an example : |\@@_rectanglecolor{red!15}{2-3}{5-6}| % \begin{macrocode} -\cs_new_protected:Npn \@@_rectanglecolor:nnn #1 #2 #3 +\NewDocumentCommand \@@_rectanglecolor { O { } m m m } { - \tl_if_blank:nF { #1 } + \tl_if_blank:nF { #2 } { \pgfpicture \pgf@relevantforpicturesizefalse - \pgfsetfillcolor { #1 } - \@@_cut_on_hyphen:w #2 \q_stop + \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 } + \@@_cut_on_hyphen:w #3 \q_stop \bool_lazy_and:nnT { \int_compare_p:n { \l_tmpa_tl <= \c@iRow } } { \int_compare_p:n { \l_tmpb_tl <= \c@jCol } } { \@@_qpoint:n { row - \l_tmpa_tl } - \dim_set_eq:NN \l_tmpb_dim \pgf@y + \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth } \@@_qpoint:n { col - \l_tmpb_tl } - \@@_cut_on_hyphen:w #3 \q_stop + \int_compare:nNnTF \l_@@_first_col_int = \l_tmpb_tl + { \dim_set:Nn \l_tmpc_dim { \pgf@x - 0.5 \arrayrulewidth } } + { \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth } } + \@@_cut_on_hyphen:w #4 \q_stop \int_compare:nNnT \l_tmpa_tl > \c@iRow { \tl_set:Nx \l_tmpa_tl { \int_use:N \c@iRow } } \int_compare:nNnT \l_tmpb_tl > \c@jCol { \tl_set:Nx \l_tmpb_tl { \int_use:N \c@jCol } } - \dim_set_eq:NN \l_tmpc_dim \pgf@x \@@_qpoint:n { row - \@@_succ:n \l_tmpa_tl } - \dim_set_eq:NN \l_tmpa_dim \pgf@y + \dim_set:Nn \l_tmpa_dim { \pgf@y + 0.5 \arrayrulewidth } \@@_qpoint:n { col - \@@_succ:n \l_tmpb_tl } - \dim_set_eq:NN \l_tmpd_dim \pgf@x + \dim_set:Nn \l_tmpd_dim { \pgf@x + 0.5 \arrayrulewidth } \pgfpathrectanglecorners { \pgfpoint \l_tmpc_dim \l_tmpb_dim } { \pgfpoint \l_tmpd_dim \l_tmpa_dim } @@ -8361,30 +8874,32 @@ version 2005/12/01 or later. % However, the command |\rowcolors| of \pkg{nicematrix} has \emph{not} the % optional argument of the command |\rowcolors| of \pkg{xcolor}. % \begin{macrocode} -\cs_new_protected:Npn \@@_rowcolors:nnn #1 #2 #3 +\NewDocumentCommand \@@_rowcolors { O { } m m m } { - \int_step_inline:nnn { #1 } { \int_use:N \c@iRow } + \int_step_inline:nnn { #2 } { \int_use:N \c@iRow } { \int_if_odd:nTF { ##1 } - { \@@_rowcolor:nn { #2 } { ##1 } } - { \@@_rowcolor:nn { #3 } { ##1 } } - } + { \@@_rowcolor [ #1 ] { #3 } } + { \@@_rowcolor [ #1 ] { #4 } } + { ##1 } + } } % \end{macrocode} % % \bigskip % \begin{macrocode} -\cs_new_protected:Npn \@@_chessboardcolors:nn #1 #2 +\NewDocumentCommand \@@_chessboardcolors { O { } m m } { \int_step_inline:nn { \int_use:N \c@iRow } { \int_step_inline:nn { \int_use:N \c@jCol } { \int_if_even:nTF { ####1 + ##1 } - { \@@_cellcolor:nn { #1 } { ####1 - ##1 } } - { \@@_cellcolor:nn { #2 } { ####1 - ##1 } } + { \@@_cellcolor [ #1 ] { #2 } } + { \@@_cellcolor [ #1 ] { #3 } } + { ##1 - ####1 } } - } + } } % \end{macrocode} % @@ -8500,10 +9015,8 @@ version 2005/12/01 or later. % \begin{macrocode} \@@_qpoint:n { row - 1 } \dim_set_eq:NN \l_tmpa_dim \pgf@y - \pgfusepathqfill \@@_qpoint:n { row - \@@_succ:n \c@iRow } \dim_sub:Nn \l_tmpa_dim \pgf@y - \pgfusepathqfill % \end{macrocode} % We translate vertically to take into account the potential ``last row''. % \begin{macrocode} @@ -8516,7 +9029,7 @@ version 2005/12/01 or later. % We adjust the value of |\l_tmpa_dim| by the width of the horizontal rule just % before the ``last row''. % \begin{macrocode} - \@@_qpoint:n { row - \@@_succ:n\c@iRow } + \@@_qpoint:n { row - \@@_succ:n \c@iRow } \dim_add:Nn \l_tmpa_dim \pgf@y \@@_qpoint:n { row - \@@_succ:n \g_@@_row_total_int } \dim_sub:Nn \l_tmpa_dim \pgf@y @@ -8546,6 +9059,223 @@ version 2005/12/01 or later. } % \end{macrocode} % +%% +% \subsection*{The key hvlines} +% +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_draw_hlines: + { + \pgfpicture + \CT@arc@ + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \pgfsetlinewidth \arrayrulewidth + \int_step_inline:nnn + { \bool_if:NTF \l_@@_NiceArray_bool 1 2 } + { \bool_if:NTF \l_@@_NiceArray_bool { \@@_succ:n \c@iRow } \c@iRow } + { + \@@_qpoint:n { row - ##1 } + \dim_set_eq:NN \l_tmpa_dim \pgf@y + \pgfpathmoveto { \pgfpoint \pgf@x \pgf@y } + \@@_qpoint:n { col - \@@_succ:n { \c@jCol } } + \dim_set:Nn \l_tmpb_dim { \pgf@x + 0.5 \arrayrulewidth } + \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpa_dim } + } + \pgfusepathqstroke + \endpgfpicture + } +% \end{macrocode} +% +% \bigskip +% Since version 4.1, the key |hvlines| is no longer a mere alias for +% the conjonction of |hlines| and |vlines|. Indeed, with |hvlines|, the vertical +% and horizontal rules are \emph{not} drawn within the blocks (created by +% |\Block|) nor within the ``virtual blocks'' (corresponding to the dotted lines +% drawn by |\Cdots|, |\Vdots|, etc.). +% \begin{macrocode} +\cs_new_protected:Npn \@@_draw_hvlines: + { + \bool_lazy_and:nnTF + { \seq_if_empty_p:N \g_@@_pos_of_blocks_seq } + { \seq_if_empty_p:N \g_@@_pos_of_xdots_seq } + \@@_draw_hvlines_i: + \@@_draw_hvlines_ii: + } +% \end{macrocode} +% +% \bigskip +% This version is only for efficiency. The general case (in +% |\@@_draw_hvlines_ii:|) does the job in all case (but slower). +% \begin{macrocode} +\cs_new_protected:Npn \@@_draw_hvlines_i: + { + \@@_draw_hlines: + \@@_draw_vlines: + } +% \end{macrocode} +% +% \bigskip +% Now, the general case, where there are blocks or dots in the array. +% \begin{macrocode} +\cs_new_protected:Npn \@@_draw_hvlines_ii: + { + \group_begin: + \CT@arc@ +% \end{macrocode} +% +% First, the exterior rectangle of the array (only in |{NiceArray}| and +% |{NiceTabular}|). +% \begin{macrocode} + \bool_if:NT \l_@@_NiceArray_bool + { + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \pgfsetlinewidth \arrayrulewidth + \pgfsetrectcap + \@@_qpoint:n { col - 1 } + \dim_set_eq:NN \l_tmpa_dim \pgf@x + \@@_qpoint:n { row -1 } + \dim_set_eq:NN \l_tmpb_dim \pgf@y + \@@_qpoint:n { col - \@@_succ:n \c@jCol } + \dim_set_eq:NN \l_tmpc_dim \pgf@x + \@@_qpoint:n { row - \@@_succ:n \c@iRow } + \pgfpathrectanglecorners + { \pgfpoint \l_tmpa_dim \l_tmpb_dim } + { \pgfpoint \l_tmpc_dim \pgf@y } + \pgfusepathqstroke + \endpgfpicture + } +% \end{macrocode} +% +% First, the horizontal rules in the interior of the array. +% \begin{macrocode} + \int_step_variable:nnNn 2 \c@iRow \l_tmpa_tl + { + \int_step_variable:nNn \c@jCol \l_tmpb_tl + { +% \end{macrocode} +% The boolean |\g_tmpa_bool| indicates whether the small horizontal rule will be +% drawn. If we find that it is in a block (a real block, created by |\Block| or +% a virtual block corresponding to a dotted line, created by |\Cdots|, |\Vdots|, +% etc.), we will set |\g_tmpa_bool| to |false| and the small horizontal rule +% won't be drawn. +% \begin{macrocode} + \bool_gset_true:N \g_tmpa_bool + \seq_map_inline:Nn \g_@@_pos_of_blocks_seq + { \@@_test_if_hline_in_block:nnnn ##1 } + \seq_map_inline:Nn \g_@@_pos_of_xdots_seq + { \@@_test_if_hline_in_block:nnnn ##1 } + \bool_if:NT \g_tmpa_bool + { + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \pgfsetlinewidth \arrayrulewidth + \pgfsetrectcap + \@@_qpoint:n { row - \l_tmpa_tl } + \dim_set_eq:NN \l_tmpb_dim \pgf@y + \@@_qpoint:n { col - \l_tmpb_tl } + \dim_set_eq:NN \l_tmpa_dim \pgf@x + \@@_qpoint:n { col - \@@_succ:n \l_tmpb_tl } + \dim_set_eq:NN \l_tmpc_dim \pgf@x + \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim } + \pgfpathlineto { \pgfpoint \l_tmpc_dim \l_tmpb_dim } + \pgfusepathqstroke + \endpgfpicture + } + } + } +% \end{macrocode} +% Now, the vertical rules in the interior of the array. +% \begin{macrocode} + \int_step_variable:nNn \c@iRow \l_tmpa_tl + { + \int_step_variable:nnNn 2 \c@jCol \l_tmpb_tl + { +% \end{macrocode} +% The boolean |\g_tmpa_bool| indicates whether the small vertial rule will be +% drawn. If we find that it is in a block (a real block, created by |\Block| or +% a virtual block corresponding to a dotted line, created by |\Cdots|, |\Vdots|, +% etc.), we will set |\g_tmpa_bool| to |false| and the small vertial rule won't +% be drawn. +% \begin{macrocode} + \bool_gset_true:N \g_tmpa_bool + \seq_map_inline:Nn \g_@@_pos_of_blocks_seq + { \@@_test_if_vline_in_block:nnnn ##1 } + \seq_map_inline:Nn \g_@@_pos_of_xdots_seq + { \@@_test_if_vline_in_block:nnnn ##1 } + \bool_if:NT \g_tmpa_bool + { + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \pgfsetlinewidth \arrayrulewidth + \pgfsetrectcap + \@@_qpoint:n { row - \l_tmpa_tl } + \dim_set_eq:NN \l_tmpb_dim \pgf@y + \@@_qpoint:n { col - \l_tmpb_tl } + \dim_set_eq:NN \l_tmpa_dim \pgf@x + \@@_qpoint:n { row - \@@_succ:n \l_tmpa_tl } + \dim_set_eq:NN \l_tmpc_dim \pgf@y + \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim } + \pgfpathlineto { \pgfpoint \l_tmpa_dim \l_tmpc_dim } + \pgfusepathqstroke + \endpgfpicture + } + } + } +% \end{macrocode} +% The group was for the color of the rules. +% \begin{macrocode} + \group_end: + \seq_gclear:N \g_@@_pos_of_xdots_seq + } +% \end{macrocode} +% +% The following command tests wether the current position in the array (given by +% |\l_tmpa_tl| for the row and |\l_tmpb_tl| for the col) would provide an +% horizontal rule towards the right in the block delimited by the four arguments +% |#1|, |#2|, |#3| and |#4|. If this rule would be in the block (it must not be +% drawn), the boolean |\l_tmpa_bool| is set to |false|. +% \begin{macrocode} +\cs_set_protected:Npn \@@_test_if_hline_in_block:nnnn #1 #2 #3 #4 + { + \int_compare:nNnT \l_tmpa_tl > { #1 } + { + \int_compare:nNnT \l_tmpa_tl < { #3 + 1 } + { + \int_compare:nNnT \l_tmpb_tl > { #2 - 1 } + { + \int_compare:nNnT \l_tmpb_tl < { #4 + 1 } + { \bool_gset_false:N \g_tmpa_bool } + } + } + } + } +% \end{macrocode} +% +% The same for vertical rules. +% \begin{macrocode} +\cs_set_protected:Npn \@@_test_if_vline_in_block:nnnn #1 #2 #3 #4 + { + \int_compare:nNnT \l_tmpa_tl > { #1 - 1 } + { + \int_compare:nNnT \l_tmpa_tl < { #3 + 1 } + { + \int_compare:nNnT \l_tmpb_tl > { #2 } + { + \int_compare:nNnT \l_tmpb_tl < { #4 + 1 } + { \bool_gset_false:N \g_tmpa_bool } + } + } + } + } +% \end{macrocode} +% +% +% % % \bigskip % \subsection*{The commands to draw dotted lines to separate columns and rows} @@ -9211,54 +9941,63 @@ version 2005/12/01 or later. \cs_new_protected:Npn \@@_Block_ii:nnnnn #1 #2 #3 #4 #5 { % \end{macrocode} -% We write an instruction in the |code-after|. We write the instruction in the -% beginning of the |code-after| (the |left| in |\tl_gput_left:Nx|) because we -% want the Tikz nodes corresponding of the block created \emph{before} potential -% instructions written by the user in the |code-after| (these instructions may -% use the Tikz node of the created block). +% +% \medskip % \begin{macrocode} - \tl_gput_left:Nx \g_@@_internal_code_after_tl + \tl_set:Nx \l_tmpa_tl { - \@@_Block_iii:nnnnnn { \int_use:N \c@iRow } { \int_use:N \c@jCol } { \int_eval:n { \c@iRow + #1 - 1 } } { \int_eval:n { \c@jCol + #2 - 1 } } - { #3 } - \exp_not:n { { #4 $ #5 $ } } - } + } % \end{macrocode} -% It's not allowed to use the command |\Block| twice in the same cell of the -% array. That's why, at the first use, we link the command |\Block| -% to a special version. The scope of this link is the cell of the array. +% Now, |\l_tmpa_tl| constains a ``object'' corresponding to the position of the +% block whith four components surrounded by brackets: +% +% |{|\textsl{imin}|}{|\textsl{jmin}|}{|\textsl{imax}|}{|\textsl{jmax}|}|. +% +% We store this information in the sequence |\g_@@_pos_of_blocks_seq|. % \begin{macrocode} - \cs_set_eq:NN \Block \@@_Block_error:nn - } + \seq_gput_left:NV \g_@@_pos_of_blocks_seq \l_tmpa_tl % \end{macrocode} +% We also store a complete description of the block in the sequence +% |\g_@@_blocks_seq|. Of course, the sequences |\g_@@_pos_of_blocks_seq| and +% |\g_@@_blocks_seq| are redundant, but it's for efficiency. In +% |\g_@@_blocks_seq|, each block is represented by an ``objet'' with six +% components: % +% |{|\textsl{imin}|}{|\textsl{jmin}|}{|\textsl{imax}|}{|\textsl{jmax}|}{|\textsl{options}|}{|\textsl{contents}|}|. % \begin{macrocode} -\cs_new:Npn \@@_Block_error:nn #1 #2 - { - \@@_error:n { Second~Block } - \cs_set_eq:NN \Block \use:nn + \seq_gput_left:Nx \g_@@_blocks_seq + { + \l_tmpa_tl + { #3 } + \exp_not:n { { #4 \@@_math_toggle_token: #5 \@@_math_toggle_token: } } + } } % \end{macrocode} +% % -% \medskip +% \bigskip +% The key |tikz| is for Tikz options used when the \textsc{pgf} node of the +% block is created. % \begin{macrocode} \keys_define:nn { NiceMatrix / Block } { tikz .tl_set:N = \l_@@_tikz_tl , tikz .value_required:n = true , - white .bool_set:N = \l_@@_white_bool , - white .default:n = true , - white .value_forbidden:n = true , } % \end{macrocode} % +% \bigskip +% The command |\@@_draw_blocks:| will draw all the blocks. This command is used +% after the construction of the array. +% \begin{macrocode} +\cs_new_protected:Npn \@@_draw_blocks: + { \seq_map_inline:Nn \g_@@_blocks_seq { \@@_Block_iii:nnnnnn ##1 } } +% \end{macrocode} % -% \medskip -% The following command |\@@_Block_iii:nnnnnn| will be used in the |code-after|. % \begin{macrocode} \cs_new_protected:Npn \@@_Block_iii:nnnnnn #1 #2 #3 #4 #5 #6 { @@ -9270,11 +10009,9 @@ version 2005/12/01 or later. % \end{macrocode} % % \begin{macrocode} - \bool_if:nTF - { - \int_compare_p:nNn { #3 } > \c@iRow - || \int_compare_p:nNn { #4 } > \c@jCol - } + \bool_lazy_or:nnTF + { \int_compare_p:nNn { #3 } > \c@iRow } + { \int_compare_p:nNn { #4 } > \c@jCol } { \msg_error:nnnn { nicematrix } { Block~too~large } { #1 } { #2 } } { % \end{macrocode} @@ -9299,33 +10036,6 @@ version 2005/12/01 or later. \@@_qpoint:n { col - \@@_succ:n { #4 } } \dim_set_eq:NN \l_tmpd_dim \pgf@x % \end{macrocode} -% -% \medskip -% The following code doesn't work for the first vertical rule. You should allow -% the option |white| if and only if the option |vlines| and |hlines| has been used. -% \begin{macrocode} - \bool_if:NT \l_@@_white_bool - { - \begin { pgfscope } - \pgfsetfillcolor { white } -% \end{macrocode} -% -% \begin{macrocode} - \pgfpathrectanglecorners - { - \pgfpoint - { \l_tmpb_dim + 0.5 \arrayrulewidth } - { \l_tmpa_dim - 0.5 \arrayrulewidth } - } - { - \pgfpoint - { \l_tmpd_dim - 0.5 \arrayrulewidth } - { \l_tmpc_dim + 0.5 \arrayrulewidth } - } - \pgfusepathqfill - \end { pgfscope } - } -% \end{macrocode} % % We construct the node for the block with the name |(#1-#2-block)|. % @@ -9510,7 +10220,9 @@ version 2005/12/01 or later. % case of use of |\dotfill| ``internally'' in the cell (e.g. |\hbox to 1cm {\dotfill}|). % \begin{macrocode} \@@_dotfill - \group_insert_after:N \@@_dotfill_i: + \bool_if:NT \l_@@_NiceTabular_bool + { \group_insert_after:N \@@_dotfill_ii: } + { \group_insert_after:N \@@_dotfill_i: } } \cs_new_protected:Npn \@@_dotfill_i: { \group_insert_after:N \@@_dotfill_ii: } \cs_new_protected:Npn \@@_dotfill_ii: { \group_insert_after:N \@@_dotfill_iii: } @@ -9518,32 +10230,32 @@ version 2005/12/01 or later. % Now, if the box if not empty (unfornately, we can't actually test whether the % box is empty and that's why we only consider it's width), we insert % |\@@_dotfill| (which is the saved version of |\dotfill|) in the cell of the -% array, and it will extends, since it's no longer in |\l_@@_cell_box|. +% array, and it will extend, since it is no longer in |\l_@@_cell_box|. % \begin{macrocode} \cs_new_protected:Npn \@@_dotfill_iii: { \dim_compare:nNnT { \box_wd:N \l_@@_cell_box } = \c_zero_dim \@@_dotfill } % \end{macrocode} % -% \subsection*{The command \textbackslash slashbox} +% \subsection*{The command \textbackslash diagbox} % % % \begin{macrocode} -\cs_new_protected:Npn \@@_slashbox:nn #1 #2 +\cs_new_protected:Npn \@@_diagbox:nn #1 #2 { \tl_gput_right:Nx \g_@@_internal_code_after_tl { - \@@_actually_slashbox:nnnn + \@@_actually_diagbox:nnnn { \int_use:N \c@iRow } { \int_use:N \c@jCol } { #1 } { #2 } } } % \end{macrocode} % % \medskip -% The two arguments of |\@@_actually_slashbox:nn| are the number of row and the +% The two arguments of |\@@_actually_diagbox:nn| are the number of row and the % number of column of the cell to slash. The two other are the elements to draw % below and above the diagonal line. % \begin{macrocode} -\cs_new_protected:Npn \@@_actually_slashbox:nnnn #1 #2 #3 #4 +\cs_new_protected:Npn \@@_actually_diagbox:nnnn #1 #2 #3 #4 { \pgfpicture \pgf@relevantforpicturesizefalse @@ -9571,10 +10283,12 @@ version 2005/12/01 or later. \pgfset { inner~sep = 1 pt } \pgfscope \pgftransformshift { \pgfpoint \l_tmpb_dim \l_tmpc_dim } - \pgfnode { rectangle } { south~west } { $ #3 $ } { } { } + \pgfnode { rectangle } { south~west } + { \@@_math_toggle_token: #3 \@@_math_toggle_token: } { } { } \endpgfscope \pgftransformshift { \pgfpoint \l_tmpd_dim \l_tmpa_dim } - \pgfnode { rectangle } { north~east } { $ #4 $ } { } { } + \pgfnode { rectangle } { north~east } + { \@@_math_toggle_token: #4 \@@_math_toggle_token: } { } { } \endpgfpicture } % \end{macrocode} @@ -9621,21 +10335,12 @@ version 2005/12/01 or later. } % \end{macrocode} % +% % % \bigskip -% \subsection*{We process the options} +% \subsection*{We process the options at package loading} % % -% \begin{macrocode} -\@@_msg_new:nn { obsolete~environments } - { - The~obsolete~environments~(eg.~{pNiceArrayC})~have~been~deleted~ - from~the~package~nicematrix.\\ - However,~if~you~still~want~to~use~them,~you~will~find~the~code~for~ - those~environments~at~the~end~of~the~file~'nicematrix.sty',~after~ - a~command~'\token_to_str:N\file_input_stop:'. - } -% \end{macrocode} % % We process the options when the package is loaded (with |\usepackage|) but we % recommend to use |\NiceMatrixOptions| instead. @@ -9655,11 +10360,6 @@ version 2005/12/01 or later. renew-matrix .value_forbidden:n = true , transparent .meta:n = { renew-dots , renew-matrix } , transparent .value_forbidden:n = true, - obsolete-environments .code:n = \@@_fatal:n { obsolete~environments }, - starred-commands .code:n = - \@@_msg_redirect_name:nn { starred~commands } { none } , - starred-commands .value_forbidden:n = true , - } \ProcessKeysOptions { NiceMatrix / Package } % \end{macrocode} @@ -9798,6 +10498,7 @@ version 2005/12/01 or later. } % \end{macrocode} % +% % \begin{macrocode} \@@_msg_new:nn { option~S~without~siunitx } { @@ -9841,16 +10542,14 @@ version 2005/12/01 or later. } % \end{macrocode} % -% \begin{macrocode} -\@@_msg_new:nn { starred~commands } +% \begin{macrocode} +\@@_msg_new:nn { standard-cline~in~document } { - The~starred~versions~of~\token_to_str:N \Cdots,~\token_to_str:N \Ldots,~ - \token_to_str:N \Vdots,~\token_to_str:N\Ddots\ and~\token_to_str:N\Iddots\ - are~deprecated.~However,~you~can~go~on~for~this~time.~If~you~don't~want~to~ - see~this~error~we~should~load~'nicematrix'~with~the~option~ - 'starred-commands'. + The~key~'standard-cline'~is~available~only~in~the~preamble.\\ + If~you~go~on~this~command~will~be~ignored. } % \end{macrocode} +% % % \begin{macrocode} \@@_msg_new:nn { bad~value~for~baseline } @@ -9862,14 +10561,6 @@ version 2005/12/01 or later. } % \end{macrocode} % -% -% \begin{macrocode} -\@@_msg_new:nn { Second~Block } - { - You~can't~use~\token_to_str:N \Block\ twice~in~the~same~cell~of~the~array.\\ - If~you~go~on,~this~command~(and~the~other)~will~be~ignored. - } -% \end{macrocode} % % \begin{macrocode} \@@_msg_new:nn { empty~environment } @@ -9896,6 +10587,7 @@ version 2005/12/01 or later. } % \end{macrocode} % +% % \begin{macrocode} \@@_msg_new:nn { last-col~non~empty~for~NiceMatrixOptions } { @@ -9961,7 +10653,7 @@ version 2005/12/01 or later. The~key~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~command~ \token_to_str:N \NiceMatrixOptions. \\ If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~keys,~type~H~. + For~a~list~of~the~*principal*~available~keys,~type~H~. } { The~available~options~are~(in~alphabetic~order):~ @@ -9976,7 +10668,6 @@ version 2005/12/01 or later. create-medium-nodes,~ create-large-nodes,~ end-of-row,~ - exterior-arraycolsep,~ first-col,~ first-row,~ hlines,~ @@ -9987,7 +10678,6 @@ version 2005/12/01 or later. letter-for-dotted-lines,~ light-syntax,~ nullify-dots,~ - parallelize-diags,~ renew-dots,~ renew-matrix,~ right-margin,~ @@ -10006,7 +10696,7 @@ version 2005/12/01 or later. The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~environment~ \{NiceArray\}. \\ If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~. + For~a~list~of~the~*principal*~available~options,~type~H~. } { The~available~options~are~(in~alphabetic~order):~ @@ -10024,7 +10714,6 @@ version 2005/12/01 or later. create-extra-nodes,~ create-medium-nodes,~ create-large-nodes,~ - end-of-row,~ extra-left-margin,~ extra-right-margin,~ first-col,~ @@ -10037,9 +10726,10 @@ version 2005/12/01 or later. light-syntax,~ name,~ nullify-dots,~ - parallelize-diags,~ renew-dots,~ right-margin,~ + rules/color,~ + rules/width,~ small,~ t,~ vlines,~ @@ -10059,7 +10749,7 @@ version 2005/12/01 or later. The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~ \@@_full_name_env:. \\ If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~. + For~a~list~of~the~*principal*~available~options,~type~H~. } { The~available~options~are~(in~alphabetic~order):~ @@ -10077,7 +10767,6 @@ version 2005/12/01 or later. create-extra-nodes,~ create-medium-nodes,~ create-large-nodes,~ - end-of-row,~ extra-left-margin,~ extra-right-margin,~ first-col,~ @@ -10091,10 +10780,11 @@ version 2005/12/01 or later. light-syntax,~ name,~ nullify-dots,~ - parallelize-diags,~ r~(=R),~ renew-dots,~ right-margin,~ + rules/color,~ + rules/width,~ S,~ small,~ t,~ @@ -10111,7 +10801,7 @@ version 2005/12/01 or later. The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~environment~ \{NiceTabular\}. \\ If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~. + For~a~list~of~the~*principal*~available~options,~type~H~. } { The~available~options~are~(in~alphabetic~order):~ @@ -10129,7 +10819,6 @@ version 2005/12/01 or later. create-extra-nodes,~ create-medium-nodes,~ create-large-nodes,~ - end-of-row,~ extra-left-margin,~ extra-right-margin,~ first-col,~ @@ -10142,9 +10831,10 @@ version 2005/12/01 or later. light-syntax,~ name,~ nullify-dots,~ - parallelize-diags,~ renew-dots,~ right-margin,~ + rules/color,~ + rules/width,~ t,~ vlines,~ xdots/color,~ @@ -10187,97 +10877,6 @@ version 2005/12/01 or later. } % \end{macrocode} % -% -% \bigskip -% \subsection*{Obsolete environments} -% -% The following environments are loaded only when the package \pkg{nicematrix} -% has been loaded with the option |obsolete-environments|. However, they will be -% completly deleted in a future version. -% -% \begin{macrocode} -\file_input_stop: -\NewDocumentEnvironment { pNiceArrayC } { } - { - \int_zero:N \l_@@_last_col_int - \pNiceArray - } - { \endpNiceArray } - \NewDocumentEnvironment { bNiceArrayC } { } - { - \int_zero:N \l_@@_last_col_int - \bNiceArray - } - { \endbNiceArray } -\NewDocumentEnvironment { BNiceArrayC } { } - { - \int_zero:N \l_@@_last_col_int - \BNiceArray - } - { \endBNiceArray } -\NewDocumentEnvironment { vNiceArrayC } { } - { - \int_zero:N \l_@@_last_col_int - \vNiceArray - } - { \endvNiceArray } -\NewDocumentEnvironment { VNiceArrayC } { } - { - \int_zero:N \l_@@_last_col_int - \VNiceArray - } - { \endVNiceArray } -\NewDocumentEnvironment { pNiceArrayRC } { } - { - \int_zero:N \l_@@_last_col_int - \int_zero:N \l_@@_first_row_int - \pNiceArray - } - { \endpNiceArray } -\NewDocumentEnvironment { bNiceArrayRC } { } - { - \int_zero:N \l_@@_last_col_int - \int_zero:N \l_@@_first_row_int - \bNiceArray - } - { \endbNiceArray } -\NewDocumentEnvironment { BNiceArrayRC } { } - { - \int_zero:N \l_@@_last_col_int - \int_zero:N \l_@@_first_row_int - \BNiceArray - } - { \endBNiceArray } -\NewDocumentEnvironment { vNiceArrayRC } { } - { - \int_zero:N \l_@@_last_col_int - \int_zero:N \l_@@_first_row_int - \vNiceArray - } - { \endvNiceArray } -\NewDocumentEnvironment { VNiceArrayRC } { } - { - \int_zero:N \l_@@_last_col_int - \int_zero:N \l_@@_first_row_int - \VNiceArray - } - { \endVNiceArray } -\NewDocumentEnvironment { NiceArrayCwithDelims } { } - { - \int_zero:N \l_@@_last_col_int - \NiceArrayWithDelims - } - { \endNiceArrayWithDelims } -\NewDocumentEnvironment { NiceArrayRCwithDelims } { } - { - \int_zero:N \l_@@_last_col_int - \int_zero:N \l_@@_first_row_int - \NiceArrayWithDelims - } - { \endNiceArrayWithDelims } -% \end{macrocode} -% -% % % \vspace{1cm} % \section{History} @@ -10576,6 +11175,14 @@ version 2005/12/01 or later. % % Commands to color cells, row and columns with a perfect result in the \textsc{pdf}. % +% \subsection*{Changes between versions 4.0 and 4.1} +% +% New keys |cell-space-top-limit| and |cell-space-bottom-limit| +% +% New command |\diagbox| +% +% The key |hvline| don't draw rules in the blocks (commands |\Block|) and in the +% virtual blocks corresponding to the dotted lines. % % \PrintIndex % diff --git a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty index 06c3fa98690..dde56d6fc32 100644 --- a/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty +++ b/Master/texmf-dist/tex/latex/nicematrix/nicematrix.sty @@ -18,8 +18,8 @@ %% and version 1.3 or later is part of all distributions of %% LaTeX version 2005/12/01 or later. %% -\def\myfileversion{4.0} -\def\myfiledate{2020/05/08} +\def\myfileversion{4.1} +\def\myfiledate{2020/05/27} \RequirePackage{pgfcore} \usepgfmodule{shapes} \RequirePackage{l3keys2e} @@ -110,22 +110,59 @@ { \bool_set_true:N \c__nicematrix_colortbl_loaded_bool } { \cs_set_protected:Npn \CT@arc@ { } - \NewDocumentCommand { \arrayrulecolor } { m } - { \tl_gset:Nn \CT@arc@ { \color { #1 } } } + \cs_set:Npn \arrayrulecolor #1 # { \CT@arc { #1 } } + \cs_set:Npn \CT@arc #1 #2 + { + \dim_compare:nNnT \baselineskip = \c_zero_dim \noalign + { \cs_gset:Npn \CT@arc@ { \color #1 { #2 } } } + } \cs_set:Npn \hline { \noalign { \ifnum 0 = `} \fi - \let \hskip \vskip - \let \vrule \hrule - \let \@width \@height + \cs_set_eq:NN \hskip \vskip + \cs_set_eq:NN \vrule \hrule + \cs_set_eq:NN \@width \@height { \CT@arc@ \vline } \futurelet \reserved@a \@xhline } } } +\cs_set:Npn \__nicematrix_standard_cline #1 { \__nicematrix_standard_cline:w #1 \q_stop } +\cs_set:Npn \__nicematrix_standard_cline:w #1-#2 \q_stop + { + \int_compare:nNnT \l__nicematrix_first_col_int = 0 { \omit & } + \int_compare:nNnT { #1 } > 1 { \multispan { \__nicematrix_pred:n { #1 } } & } + \multispan { \int_eval:n { #2 - #1 + 1 } } + { \CT@arc@ \leaders \hrule \@height \arrayrulewidth \hfill } + \everycr { } + \cr + \noalign { \skip_vertical:N -\arrayrulewidth } + } +\cs_set:Npn \__nicematrix_cline + { \exp_args:Ne \__nicematrix_cline_i:nn \l__nicematrix_first_col_int } +\cs_set:Npn \__nicematrix_cline_i:nn #1 #2 { \__nicematrix_cline_i:w #1-#2 \q_stop } +\cs_set:Npn \__nicematrix_cline_i:w #1-#2-#3 \q_stop + { + \int_compare:nNnT { #1 } < { #2 } + { \multispan { \int_eval:n { #2 - #1 } } & } + \multispan { \int_eval:n { #3 - #2 + 1 } } + { \CT@arc@ \leaders \hrule \@height \arrayrulewidth \hfill } + \peek_meaning_remove_ignore_spaces:NTF \cline + { & \exp_args:Ne \__nicematrix_cline_i:nn { \__nicematrix_succ:n { #3 } } } + { \everycr { } \cr } + } + \cs_new:Npn \__nicematrix_succ:n #1 { \the \numexpr #1 + 1 \relax } \cs_new:Npn \__nicematrix_pred:n #1 { \the \numexpr #1 - 1 \relax } +\cs_new:Npn \__nicematrix_math_toggle_token: + { \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token } +\cs_new_protected:Npn \__nicematrix_set_CT@arc@: + { \peek_meaning:NTF [ \__nicematrix_set_CT@arc@_i: \__nicematrix_set_CT@arc@_ii: } +\cs_new_protected:Npn \__nicematrix_set_CT@arc@_i: [ #1 ] #2 \q_stop + { \cs_set:Npn \CT@arc@ { \color [ #1 ] { #2 } } } +\cs_new_protected:Npn \__nicematrix_set_CT@arc@_ii: #1 \q_stop + { \cs_set:Npn \CT@arc@ { \color { #1 } } } \bool_new:N \c__nicematrix_siunitx_loaded_bool \AtBeginDocument { @@ -167,6 +204,8 @@ } \int_new:N \g__nicematrix_env_int \cs_new:Npn \__nicematrix_env: { nm - \int_use:N \g__nicematrix_env_int } +\NewExpandableDocumentCommand \NiceMatrixLastEnv { } + { \int_use:N \g__nicematrix_env_int } \cs_new_protected:Npn \__nicematrix_qpoint:n #1 { \pgfpointanchor { \__nicematrix_env: - #1 } { center } } \int_new:N \g__nicematrix_NiceMatrixBlock_int @@ -196,6 +235,7 @@ \tl_new:N \g__nicematrix_internal_code_after_tl \int_new:N \l__nicematrix_old_iRow_int \int_new:N \l__nicematrix_old_jCol_int +\tl_new:N \l__nicematrix_rules_color_tl \bool_new:N \g__nicematrix_row_of_col_done_bool \bool_new:N \l__nicematrix_code_before_bool \dim_new:N \l__nicematrix_x_initial_dim @@ -208,6 +248,9 @@ \dim_new:N \__nicematrix_old_arraycolsep_dim \dim_new:N \g__nicematrix_width_last_col_dim \dim_new:N \g__nicematrix_width_first_col_dim +\seq_new:N \g__nicematrix_blocks_seq +\seq_new:N \g__nicematrix_pos_of_blocks_seq +\seq_new:N \g__nicematrix_pos_of_xdots_seq \int_new:N \l__nicematrix_first_row_int \int_set:Nn \l__nicematrix_first_row_int 1 \int_new:N \l__nicematrix_first_col_int @@ -268,6 +311,7 @@ { } \end { pgfscope } } +\bool_new:N \l__nicematrix_standard_cline_bool \dim_new:N \l__nicematrix_cell_space_top_limit_dim \dim_new:N \l__nicematrix_cell_space_bottom_limit_dim \dim_new:N \l__nicematrix_inter_dots_dim @@ -287,6 +331,7 @@ \bool_set_true:N \l__nicematrix_parallelize_diags_bool \bool_new:N \l__nicematrix_hlines_bool \bool_new:N \l__nicematrix_vlines_bool +\bool_new:N \l__nicematrix_hvlines_bool \bool_new:N \l__nicematrix_nullify_dots_bool \bool_new:N \l__nicematrix_auto_columns_width_bool \str_new:N \l__nicematrix_name_str @@ -319,8 +364,17 @@ up .tl_set:N = \l__nicematrix_xdots_up_tl , unknown .code:n = \__nicematrix_error:n { Unknown~option~for~xdots } } +\keys_define:nn { NiceMatrix / rules } + { + color .tl_set:N = \l__nicematrix_rules_color_tl , + color .value_required:n = true , + width .dim_set:N = \arrayrulewidth , + width .value_required:n = true + } \keys_define:nn { NiceMatrix / Global } { + standard-cline .bool_set:N = \l__nicematrix_standard_cline_bool , + standard-cline .default:n = true , cell-space-top-limit .dim_set:N = \l__nicematrix_cell_space_top_limit_dim , cell-space-top-limit .value_required:n = true , cell-space-bottom-limit .dim_set:N = \l__nicematrix_cell_space_bottom_limit_dim , @@ -345,7 +399,12 @@ code-for-last-row .value_required:n = true , hlines .bool_set:N = \l__nicematrix_hlines_bool , vlines .bool_set:N = \l__nicematrix_vlines_bool , - hvlines .meta:n = { hlines , vlines } , + hvlines .code:n = + { + \bool_set_true:N \l__nicematrix_hvlines_bool + \bool_set_true:N \l__nicematrix_vlines_bool + \bool_set_true:N \l__nicematrix_hlines_bool + } , parallelize-diags .bool_set:N = \l__nicematrix_parallelize_diags_bool , renew-dots .bool_set:N = \l__nicematrix_renew_dots_bool , renew-dots .value_forbidden:n = true , @@ -412,24 +471,28 @@ NiceMatrix / Env , } , NiceMatrix / xdots .inherit:n = NiceMatrix / xdots , + NiceMatrix / rules .inherit:n = NiceMatrix / rules , NiceTabular .inherit:n = { NiceMatrix / Global , NiceMatrix / Env } , NiceTabular / xdots .inherit:n = NiceMatrix / xdots , + NiceTabular / rules .inherit:n = NiceMatrix / rules , NiceArray .inherit:n = { NiceMatrix / Global , NiceMatrix / Env , } , NiceArray / xdots .inherit:n = NiceMatrix / xdots , + NiceArray / rules .inherit:n = NiceMatrix / rules , pNiceArray .inherit:n = { NiceMatrix / Global , NiceMatrix / Env , } , - pNiceArray / xdots .inherit:n = NiceMatrix / xdots + pNiceArray / xdots .inherit:n = NiceMatrix / xdots , + pNiceArray / rules .inherit:n = NiceMatrix / rules , } \keys_define:nn { NiceMatrix / NiceMatrixOptions } { @@ -504,6 +567,9 @@ } \keys_define:nn { NiceMatrix / NiceTabular } { + last-col .code:n = \tl_if_empty:nF {#1} + { \__nicematrix_error:n { last-col~non~empty~for~NiceArray } } + \int_zero:N \l__nicematrix_last_col_int , unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceTabular } } \cs_new_protected:Npn \__nicematrix_Cell: @@ -572,7 +638,7 @@ } \cs_new_protected:Npn \__nicematrix_end_Cell: { - \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token + \__nicematrix_math_toggle_token: \hbox_set_end: \box_set_ht:Nn \l__nicematrix_cell_box { \box_ht:N \l__nicematrix_cell_box + \l__nicematrix_cell_space_top_limit_dim } @@ -677,7 +743,7 @@ \int_compare:nNnT \c@iRow > { -1 } { \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int - { { \CT@arc@ \hrule height \arrayrulewidth } } + { \hrule height \arrayrulewidth width \c_zero_dim } } } } @@ -756,6 +822,9 @@ \cs_set_eq:NN \__nicematrix_old_iddots \iddots \cs_set_eq:NN \firsthline \hline \cs_set_eq:NN \lasthline \hline + \bool_if:NTF \l__nicematrix_standard_cline_bool + { \cs_set_eq:NN \cline \__nicematrix_standard_cline } + { \cs_set_eq:NN \cline \__nicematrix_cline } \cs_set_eq:NN \Ldots \__nicematrix_Ldots \cs_set_eq:NN \Cdots \__nicematrix_Cdots \cs_set_eq:NN \Vdots \__nicematrix_Vdots @@ -771,7 +840,7 @@ \cs_set_eq:NN \OnlyMainNiceMatrix \__nicematrix_OnlyMainNiceMatrix:n \cs_set_eq:NN \dotfill \__nicematrix_dotfill: \cs_set_eq:NN \CodeAfter \__nicematrix_CodeAfter:n - \cs_set_eq:NN \slashbox \__nicematrix_slashbox:nn + \cs_set_eq:NN \diagbox \__nicematrix_diagbox:nn \bool_if:NT \l__nicematrix_renew_dots_bool { \cs_set_eq:NN \ldots \__nicematrix_Ldots @@ -866,6 +935,7 @@ \__nicematrix_test_if_math_mode: \bool_if:NT \l__nicematrix_in_env_bool { \__nicematrix_fatal:n { Yet~in~env } } \bool_set_true:N \l__nicematrix_in_env_bool + \cs_gset_eq:NN \__nicematrix_old_CT@arc@ \CT@arc@ \cs_if_exist:NT \tikz@library@external@loaded { \tikzset { external / export = false } @@ -876,10 +946,14 @@ \bool_if:NF \l__nicematrix_block_auto_columns_width_bool { \dim_gzero_new:N \g__nicematrix_max_cell_width_dim } \cs_set_protected:Npn \@arrayrule { \@addtopreamble \__nicematrix_vline: } + \seq_clear:N \g__nicematrix_blocks_seq + \seq_clear:N \g__nicematrix_pos_of_blocks_seq \bool_if:NTF \l__nicematrix_NiceArray_bool { \keys_set:nn { NiceMatrix / NiceArray } } { \keys_set:nn { NiceMatrix / pNiceArray } } { #3 , #5 } + \tl_if_empty:NF \l__nicematrix_rules_color_tl + { \exp_after:wN \__nicematrix_set_CT@arc@: \l__nicematrix_rules_color_tl \q_stop } \bool_if:NT \l__nicematrix_code_before_bool { \seq_if_exist:cT { __nicematrix_size_ \int_use:N \g__nicematrix_env_int _ seq } @@ -917,18 +991,18 @@ \group_begin: \bool_if:NT \c__nicematrix_tikz_loaded_bool { - \pgfset + \tikzset { every~picture / .style = - { overlay , name~prefix = \__nicematrix_env: - } + { overlay , name~prefix = \__nicematrix_env: - } } } - \cs_set_eq:NN \cellcolor \__nicematrix_cellcolor:nn - \cs_set_eq:NN \rectanglecolor \__nicematrix_rectanglecolor:nnn - \cs_set_eq:NN \rowcolor \__nicematrix_rowcolor:nn - \cs_set_eq:NN \rowcolors \__nicematrix_rowcolors:nnn - \cs_set_eq:NN \columncolor \__nicematrix_columncolor:nn - \cs_set_eq:NN \chessboardcolors \__nicematrix_chessboardcolors:nn + \cs_set_eq:NN \cellcolor \__nicematrix_cellcolor + \cs_set_eq:NN \rectanglecolor \__nicematrix_rectanglecolor + \cs_set_eq:NN \rowcolor \__nicematrix_rowcolor + \cs_set_eq:NN \rowcolors \__nicematrix_rowcolors + \cs_set_eq:NN \columncolor \__nicematrix_columncolor + \cs_set_eq:NN \chessboardcolors \__nicematrix_chessboardcolors \bool_if:NT \l__nicematrix_NiceTabular_bool \c_math_toggle_token \l__nicematrix_code_before_tl \bool_if:NT \l__nicematrix_NiceTabular_bool \c_math_toggle_token @@ -1217,7 +1291,7 @@ { \box_ht:N \l_tmpa_box + \box_dp:N \l_tmpa_box } { } } - \right . + \right . \c_math_toggle_token } \dim_set:Nn \l__nicematrix_real_left_delim_dim @@ -1440,7 +1514,7 @@ { \__nicematrix_begin_of_row: \hbox_set:Nw \l__nicematrix_cell_box - \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token + \__nicematrix_math_toggle_token: \bool_if:NT \l__nicematrix_small_bool \scriptstyle \bool_lazy_and:nnT { \int_compare_p:nNn \c@iRow > 0 } @@ -1457,7 +1531,7 @@ l < { - \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token + \__nicematrix_math_toggle_token: \hbox_set_end: \__nicematrix_update_for_first_and_last_row: \dim_gset:Nn \g__nicematrix_width_first_col_dim @@ -1482,7 +1556,7 @@ \int_gincr:N \c@jCol \int_gset_eq:NN \g__nicematrix_col_total_int \c@jCol \hbox_set:Nw \l__nicematrix_cell_box - \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token + \__nicematrix_math_toggle_token: \bool_if:NT \l__nicematrix_small_bool \scriptstyle \int_compare:nNnT \c@iRow > 0 { @@ -1498,7 +1572,7 @@ l < { - \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token + \__nicematrix_math_toggle_token: \hbox_set_end: \__nicematrix_update_for_first_and_last_row: \dim_gset:Nn \g__nicematrix_width_last_col_dim @@ -1596,6 +1670,7 @@ \__nicematrix_define_env:n V \NewDocumentEnvironment { NiceTabular } { O { } m ! O { } } { + \str_gset:Nn \g__nicematrix_name_env_str { NiceTabular } \keys_set:nn { NiceMatrix / NiceTabular } { #1 , #3 } \bool_set_true:N \l__nicematrix_NiceTabular_bool \NiceArray { #2 } @@ -1698,7 +1773,14 @@ \dim_set:Nn \l__nicematrix_xdots_shorten_dim { 0.6 \l__nicematrix_xdots_shorten_dim } } \__nicematrix_draw_dotted_lines: - \bool_if:NT \l__nicematrix_vlines_bool \__nicematrix_draw_vlines: + \bool_if:NTF \l__nicematrix_hvlines_bool + \__nicematrix_draw_hvlines: + { + \bool_if:NT \l__nicematrix_hlines_bool \__nicematrix_draw_hlines: + \bool_if:NT \l__nicematrix_vlines_bool \__nicematrix_draw_vlines: + } + \cs_set_eq:NN \ialign \__nicematrix_old_ialign: + \seq_if_empty:NF \g__nicematrix_blocks_seq \__nicematrix_draw_blocks: \g__nicematrix_internal_code_after_tl \tl_gclear:N \g__nicematrix_internal_code_after_tl \bool_if:NT \c__nicematrix_tikz_loaded_bool @@ -1720,6 +1802,7 @@ \group_end: \str_gclear:N \g__nicematrix_name_env_str \__nicematrix_restore_iRow_jCol: + \cs_gset_eq:NN \CT@arc@ \__nicematrix_old_CT@arc@ } \AtBeginDocument { @@ -1889,6 +1972,16 @@ } } } + \bool_if:NT \l__nicematrix_hvlines_bool + { + \seq_gput_right:Nx \g__nicematrix_pos_of_xdots_seq + { + { \int_use:N \l__nicematrix_initial_i_int } + { \int_use:N \l__nicematrix_initial_j_int } + { \int_use:N \l__nicematrix_final_i_int } + { \int_use:N \l__nicematrix_final_j_int } + } + } } \cs_new_protected:Npn \__nicematrix_set_initial_coords: { @@ -2201,8 +2294,6 @@ } \__nicematrix_draw_line: } -\NewExpandableDocumentCommand \NiceMatrixLastEnv { } - { \int_use:N \g__nicematrix_env_int } \cs_new_protected:Npn \__nicematrix_draw_line: { \pgfrememberpicturepositiononpagetrue @@ -2388,22 +2479,18 @@ } \AtBeginDocument { - \tl_set:Nn \l__nicematrix_argspec_tl { s O { } E { _ ^ } { { } { } } } + \tl_set:Nn \l__nicematrix_argspec_tl { O { } E { _ ^ } { { } { } } } \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl \exp_args:NNV \NewDocumentCommand \__nicematrix_Ldots \l__nicematrix_argspec_tl { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } + \int_compare:nNnTF \c@jCol = 0 + { \__nicematrix_error:nn { in~first~col } \Ldots } { - \int_compare:nNnTF \c@jCol = 0 - { \__nicematrix_error:nn { in~first~col } \Ldots } + \int_compare:nNnTF \c@jCol = \l__nicematrix_last_col_int + { \__nicematrix_error:nn { in~last~col } \Ldots } { - \int_compare:nNnTF \c@jCol = \l__nicematrix_last_col_int - { \__nicematrix_error:nn { in~last~col } \Ldots } - { - \__nicematrix_instruction_of_type:nn { Ldots } - { #2 , down = #3 , up = #4 } - } + \__nicematrix_instruction_of_type:nn { Ldots } + { #1 , down = #2 , up = #3 } } } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_ldots } @@ -2411,18 +2498,14 @@ } \exp_args:NNV \NewDocumentCommand \__nicematrix_Cdots \l__nicematrix_argspec_tl { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } + \int_compare:nNnTF \c@jCol = 0 + { \__nicematrix_error:nn { in~first~col } \Cdots } { - \int_compare:nNnTF \c@jCol = 0 - { \__nicematrix_error:nn { in~first~col } \Cdots } + \int_compare:nNnTF \c@jCol = \l__nicematrix_last_col_int + { \__nicematrix_error:nn { in~last~col } \Cdots } { - \int_compare:nNnTF \c@jCol = \l__nicematrix_last_col_int - { \__nicematrix_error:nn { in~last~col } \Cdots } - { - \__nicematrix_instruction_of_type:nn { Cdots } - { #2 , down = #3 , up = #4 } - } + \__nicematrix_instruction_of_type:nn { Cdots } + { #1 , down = #2 , up = #3 } } } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_cdots } @@ -2430,69 +2513,59 @@ } \exp_args:NNV \NewDocumentCommand \__nicematrix_Vdots \l__nicematrix_argspec_tl { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } - \int_compare:nNnTF \c@iRow = 0 - { \__nicematrix_error:nn { in~first~row } \Vdots } + \int_compare:nNnTF \c@iRow = 0 + { \__nicematrix_error:nn { in~first~row } \Vdots } + { + \int_compare:nNnTF \c@iRow = \l__nicematrix_last_row_int + { \__nicematrix_error:nn { in~last~row } \Vdots } { - \int_compare:nNnTF \c@iRow = \l__nicematrix_last_row_int - { \__nicematrix_error:nn { in~last~row } \Vdots } - { - \__nicematrix_instruction_of_type:nn { Vdots } - { #2 , down = #3 , up = #4 } - } + \__nicematrix_instruction_of_type:nn { Vdots } + { #1 , down = #2 , up = #3 } } + } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_vdots } \bool_gset_true:N \g__nicematrix_empty_cell_bool } \exp_args:NNV \NewDocumentCommand \__nicematrix_Ddots \l__nicematrix_argspec_tl { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } + \int_case:nnF \c@iRow + { + 0 { \__nicematrix_error:nn { in~first~row } \Ddots } + \l__nicematrix_last_row_int { \__nicematrix_error:nn { in~last~row } \Ddots } + } { - \int_case:nnF \c@iRow + \int_case:nnF \c@jCol { - 0 { \__nicematrix_error:nn { in~first~row } \Ddots } - \l__nicematrix_last_row_int { \__nicematrix_error:nn { in~last~row } \Ddots } + 0 { \__nicematrix_error:nn { in~first~col } \Ddots } + \l__nicematrix_last_col_int { \__nicematrix_error:nn { in~last~col } \Ddots } } { - \int_case:nnF \c@jCol - { - 0 { \__nicematrix_error:nn { in~first~col } \Ddots } - \l__nicematrix_last_col_int { \__nicematrix_error:nn { in~last~col } \Ddots } - } - { - \__nicematrix_instruction_of_type:nn { Ddots } - { #2 , down = #3 , up = #4 } - } - + \__nicematrix_instruction_of_type:nn { Ddots } + { #1 , down = #2 , up = #3 } } + } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_ddots } \bool_gset_true:N \g__nicematrix_empty_cell_bool } \exp_args:NNV \NewDocumentCommand \__nicematrix_Iddots \l__nicematrix_argspec_tl { - \bool_if:nTF { #1 } - { \__nicematrix_error:n { starred~commands } } + \int_case:nnF \c@iRow + { + 0 { \__nicematrix_error:nn { in~first~row } \Iddots } + \l__nicematrix_last_row_int { \__nicematrix_error:nn { in~last~row } \Iddots } + } { - \int_case:nnF \c@iRow + \int_case:nnF \c@jCol { - 0 { \__nicematrix_error:nn { in~first~row } \Iddots } - \l__nicematrix_last_row_int { \__nicematrix_error:nn { in~last~row } \Iddots } + 0 { \__nicematrix_error:nn { in~first~col } \Iddots } + \l__nicematrix_last_col_int { \__nicematrix_error:nn { in~last~col } \Iddots } } { - \int_case:nnF \c@jCol - { - 0 { \__nicematrix_error:nn { in~first~col } \Iddots } - \l__nicematrix_last_col_int { \__nicematrix_error:nn { in~last~col } \Iddots } - } - { - \__nicematrix_instruction_of_type:nn { Iddots } - { #2 , down = #3 , up = #4 } - } - + \__nicematrix_instruction_of_type:nn { Iddots } + { #1 , down = #2 , up = #3 } } + } \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_iddots } \bool_gset_true:N \g__nicematrix_empty_cell_bool @@ -2507,13 +2580,23 @@ \cs_new:Npn \__nicematrix_multicolumn:nnn #1 #2 #3 { \__nicematrix_old_multicolumn { #1 } { #2 } { #3 } - \int_compare:nNnT #1 > 1 + \peek_remove_spaces:n { - \seq_gput_left:Nx \g__nicematrix_multicolumn_cells_seq - { \int_use:N \c@iRow - \int_use:N \c@jCol } - \seq_gput_left:Nn \g__nicematrix_multicolumn_sizes_seq { #1 } - } - \int_gadd:Nn \c@jCol { #1 - 1 } + \int_compare:nNnT #1 > 1 + { + \seq_gput_left:Nx \g__nicematrix_multicolumn_cells_seq + { \int_use:N \c@iRow - \int_use:N \c@jCol } + \seq_gput_left:Nn \g__nicematrix_multicolumn_sizes_seq { #1 } + \seq_gput_right:Nx \g__nicematrix_pos_of_blocks_seq + { + { \int_use:N \c@iRow } + { \int_use:N \c@jCol } + { \int_use:N \c@iRow } + { \int_eval:n { \c@jCol + #1 - 1 } } + } + } + \int_gadd:Nn \c@jCol { #1 - 1 } + } } \cs_new:Npn \__nicematrix_Hdotsfor: { @@ -2671,7 +2754,12 @@ \int_step_inline:nnn { #1 } { #1 + #3 - 1 } { \cs_set:cpn { __nicematrix _ dotted _ ##1 - #2 } { } } } -\cs_new_protected:Npn \__nicematrix_rotate: { \group_insert_after:N \__nicematrix_rotate_i: } +\cs_new_protected:Npn \__nicematrix_rotate: + { + \bool_if:NTF \l__nicematrix_NiceTabular_bool + { \group_insert_after:N \__nicematrix_rotate_ii: } + { \group_insert_after:N \__nicematrix_rotate_i: } + } \cs_new_protected:Npn \__nicematrix_rotate_i: { \group_insert_after:N \__nicematrix_rotate_ii: } \cs_new_protected:Npn \__nicematrix_rotate_ii: { \group_insert_after:N \__nicematrix_rotate_iii: } \cs_new_protected:Npn \__nicematrix_rotate_iii: @@ -2747,16 +2835,20 @@ \tl_set:Nn \l_tmpa_tl { #1 } \tl_set:Nn \l_tmpb_tl { #2 } } -\cs_new_protected:Npn \__nicematrix_rowcolor:nn #1 #2 +\NewDocumentCommand \__nicematrix_rowcolor { O { } m m } { - \tl_if_blank:nF { #1 } + \tl_if_blank:nF { #2 } { \pgfpicture \pgf@relevantforpicturesizefalse - \pgfsetfillcolor { #1 } + \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 } + \__nicematrix_qpoint:n { col - 1} + \int_compare:nNnTF \l__nicematrix_first_col_int = 0 + { \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth } } + { \dim_set:Nn \l_tmpc_dim { \pgf@x - 0.5 \arrayrulewidth } } \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \c@jCol } - \dim_set_eq:NN \l_tmpa_dim \pgf@x - \clist_map_inline:nn { #2 } + \dim_set:Nn \l_tmpa_dim { \pgf@x + 0.5 \arrayrulewidth } + \clist_map_inline:nn { #3 } { \tl_set:Nn \l_tmpa_tl { ##1 } \tl_if_in:NnTF \l_tmpa_tl { - } @@ -2768,26 +2860,29 @@ \int_compare:nNnT \l_tmpb_tl > \c@iRow { \tl_set:Nx \l_tmpb_tl { \int_use:N \c@iRow } } \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l_tmpb_tl } + \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth } + \__nicematrix_qpoint:n { row - \l_tmpa_tl } + \dim_set:Nn \l_tmpd_dim { \pgf@y + 0.5 \arrayrulewidth } \pgfpathrectanglecorners - { \__nicematrix_qpoint:n { row - \l_tmpa_tl } } - { \pgfpoint \l_tmpa_dim \pgf@y } + { \pgfpoint \l_tmpc_dim \l_tmpd_dim } + { \pgfpoint \l_tmpa_dim \l_tmpb_dim } } \pgfusepathqfill \endpgfpicture } } -\cs_new_protected:Npn \__nicematrix_columncolor:nn #1 #2 +\NewDocumentCommand \__nicematrix_columncolor { O { } m m } { - \tl_if_blank:nF { #1 } + \tl_if_blank:nF { #2 } { \pgfpicture \pgf@relevantforpicturesizefalse - \pgfsetfillcolor { #1 } + \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 } \__nicematrix_qpoint:n { row - 1 } - \dim_set_eq:NN \l_tmpa_dim \pgf@y + \dim_set:Nn \l_tmpa_dim {\pgf@y + 0.5 \arrayrulewidth } \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c@iRow } - \dim_set_eq:NN \l_tmpb_dim \pgf@y - \clist_map_inline:nn { #2 } + \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth } + \clist_map_inline:nn { #3 } { \tl_set:Nn \l_tmpa_tl { ##1 } \tl_if_in:NnTF \l_tmpa_tl { - } @@ -2799,24 +2894,27 @@ \int_compare:nNnT \l_tmpb_tl > \c@jCol { \tl_set:Nx \l_tmpb_tl { \int_use:N \c@jCol } } \__nicematrix_qpoint:n { col - \l_tmpa_tl } - \dim_set_eq:NN \l_tmpc_dim \pgf@x + \int_compare:nNnTF \l__nicematrix_first_col_int = \l_tmpa_tl + { \dim_set:Nn \l_tmpc_dim { \pgf@x - 0.5 \arrayrulewidth } } + { \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth } } \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l_tmpb_tl } + \dim_set:Nn \l_tmpd_dim { \pgf@x + 0.5 \arrayrulewidth } \pgfpathrectanglecorners { \pgfpoint \l_tmpc_dim \l_tmpa_dim } - { \pgfpoint \pgf@x \l_tmpb_dim } + { \pgfpoint \l_tmpd_dim \l_tmpb_dim } } \pgfusepathqfill \endpgfpicture } } -\cs_new_protected:Npn \__nicematrix_cellcolor:nn #1 #2 +\NewDocumentCommand \__nicematrix_cellcolor { O { } m m } { - \tl_if_blank:nF { #1 } + \tl_if_blank:nF { #2 } { \pgfpicture \pgf@relevantforpicturesizefalse - \pgfsetfillcolor { #1 } - \clist_map_inline:nn { #2 } + \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 } + \clist_map_inline:nn { #3 } { \__nicematrix_cut_on_hyphen:w ##1 \q_stop \__nicematrix_qpoint:n { row - \l_tmpa_tl } @@ -2824,13 +2922,15 @@ { \int_compare_p:n { \l_tmpa_tl <= \c@iRow } } { \int_compare_p:n { \l_tmpb_tl <= \c@jCol } } { - \dim_set_eq:NN \l_tmpb_dim \pgf@y + \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth } \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l_tmpa_tl } - \dim_set_eq:NN \l_tmpa_dim \pgf@y + \dim_set:Nn \l_tmpa_dim { \pgf@y + 0.5 \arrayrulewidth } \__nicematrix_qpoint:n { col - \l_tmpb_tl } - \dim_set_eq:NN \l_tmpc_dim \pgf@x + \int_compare:nNnTF \l__nicematrix_first_col_int = \l_tmpb_tl + { \dim_set:Nn \l_tmpc_dim { \pgf@x - 0.5 \arrayrulewidth } } + { \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth } } \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l_tmpb_tl } - \dim_set_eq:NN \l_tmpd_dim \pgf@x + \dim_set:Nn \l_tmpd_dim { \pgf@x + 0.5 \arrayrulewidth } \pgfpathrectanglecorners { \pgfpoint \l_tmpc_dim \l_tmpb_dim } { \pgfpoint \l_tmpd_dim \l_tmpa_dim } @@ -2838,33 +2938,35 @@ } \pgfusepathqfill \endpgfpicture - } + } } -\cs_new_protected:Npn \__nicematrix_rectanglecolor:nnn #1 #2 #3 +\NewDocumentCommand \__nicematrix_rectanglecolor { O { } m m m } { - \tl_if_blank:nF { #1 } + \tl_if_blank:nF { #2 } { \pgfpicture \pgf@relevantforpicturesizefalse - \pgfsetfillcolor { #1 } - \__nicematrix_cut_on_hyphen:w #2 \q_stop + \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 } + \__nicematrix_cut_on_hyphen:w #3 \q_stop \bool_lazy_and:nnT { \int_compare_p:n { \l_tmpa_tl <= \c@iRow } } { \int_compare_p:n { \l_tmpb_tl <= \c@jCol } } { \__nicematrix_qpoint:n { row - \l_tmpa_tl } - \dim_set_eq:NN \l_tmpb_dim \pgf@y + \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth } \__nicematrix_qpoint:n { col - \l_tmpb_tl } - \__nicematrix_cut_on_hyphen:w #3 \q_stop + \int_compare:nNnTF \l__nicematrix_first_col_int = \l_tmpb_tl + { \dim_set:Nn \l_tmpc_dim { \pgf@x - 0.5 \arrayrulewidth } } + { \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth } } + \__nicematrix_cut_on_hyphen:w #4 \q_stop \int_compare:nNnT \l_tmpa_tl > \c@iRow { \tl_set:Nx \l_tmpa_tl { \int_use:N \c@iRow } } \int_compare:nNnT \l_tmpb_tl > \c@jCol { \tl_set:Nx \l_tmpb_tl { \int_use:N \c@jCol } } - \dim_set_eq:NN \l_tmpc_dim \pgf@x \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l_tmpa_tl } - \dim_set_eq:NN \l_tmpa_dim \pgf@y + \dim_set:Nn \l_tmpa_dim { \pgf@y + 0.5 \arrayrulewidth } \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l_tmpb_tl } - \dim_set_eq:NN \l_tmpd_dim \pgf@x + \dim_set:Nn \l_tmpd_dim { \pgf@x + 0.5 \arrayrulewidth } \pgfpathrectanglecorners { \pgfpoint \l_tmpc_dim \l_tmpb_dim } { \pgfpoint \l_tmpd_dim \l_tmpa_dim } @@ -2873,24 +2975,26 @@ \endpgfpicture } } -\cs_new_protected:Npn \__nicematrix_rowcolors:nnn #1 #2 #3 +\NewDocumentCommand \__nicematrix_rowcolors { O { } m m m } { - \int_step_inline:nnn { #1 } { \int_use:N \c@iRow } + \int_step_inline:nnn { #2 } { \int_use:N \c@iRow } { \int_if_odd:nTF { ##1 } - { \__nicematrix_rowcolor:nn { #2 } { ##1 } } - { \__nicematrix_rowcolor:nn { #3 } { ##1 } } + { \__nicematrix_rowcolor [ #1 ] { #3 } } + { \__nicematrix_rowcolor [ #1 ] { #4 } } + { ##1 } } } -\cs_new_protected:Npn \__nicematrix_chessboardcolors:nn #1 #2 +\NewDocumentCommand \__nicematrix_chessboardcolors { O { } m m } { \int_step_inline:nn { \int_use:N \c@iRow } { \int_step_inline:nn { \int_use:N \c@jCol } { \int_if_even:nTF { ####1 + ##1 } - { \__nicematrix_cellcolor:nn { #1 } { ####1 - ##1 } } - { \__nicematrix_cellcolor:nn { #2 } { ####1 - ##1 } } + { \__nicematrix_cellcolor [ #1 ] { #2 } } + { \__nicematrix_cellcolor [ #1 ] { #3 } } + { ##1 - ####1 } } } } @@ -2925,16 +3029,14 @@ \pgfsetlinewidth \arrayrulewidth \__nicematrix_qpoint:n { row - 1 } \dim_set_eq:NN \l_tmpa_dim \pgf@y - \pgfusepathqfill \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c@iRow } \dim_sub:Nn \l_tmpa_dim \pgf@y - \pgfusepathqfill \dim_zero:N \l_tmpb_dim \int_compare:nNnT \l__nicematrix_last_row_int > { -1 } { \dim_set_eq:NN \l_tmpb_dim \g__nicematrix_dp_last_row_dim \dim_add:Nn \l_tmpb_dim \g__nicematrix_ht_last_row_dim - \__nicematrix_qpoint:n { row - \__nicematrix_succ:n\c@iRow } + \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c@iRow } \dim_add:Nn \l_tmpa_dim \pgf@y \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \g__nicematrix_row_total_int } \dim_sub:Nn \l_tmpa_dim \pgf@y @@ -2957,6 +3059,154 @@ \endpgfpicture \group_end: } +%% +\cs_new_protected:Npn \__nicematrix_draw_hlines: + { + \pgfpicture + \CT@arc@ + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \pgfsetlinewidth \arrayrulewidth + \int_step_inline:nnn + { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 } + { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:n \c@iRow } \c@iRow } + { + \__nicematrix_qpoint:n { row - ##1 } + \dim_set_eq:NN \l_tmpa_dim \pgf@y + \pgfpathmoveto { \pgfpoint \pgf@x \pgf@y } + \__nicematrix_qpoint:n { col - \__nicematrix_succ:n { \c@jCol } } + \dim_set:Nn \l_tmpb_dim { \pgf@x + 0.5 \arrayrulewidth } + \pgfpathlineto { \pgfpoint \l_tmpb_dim \l_tmpa_dim } + } + \pgfusepathqstroke + \endpgfpicture + } +\cs_new_protected:Npn \__nicematrix_draw_hvlines: + { + \bool_lazy_and:nnTF + { \seq_if_empty_p:N \g__nicematrix_pos_of_blocks_seq } + { \seq_if_empty_p:N \g__nicematrix_pos_of_xdots_seq } + \__nicematrix_draw_hvlines_i: + \__nicematrix_draw_hvlines_ii: + } +\cs_new_protected:Npn \__nicematrix_draw_hvlines_i: + { + \__nicematrix_draw_hlines: + \__nicematrix_draw_vlines: + } +\cs_new_protected:Npn \__nicematrix_draw_hvlines_ii: + { + \group_begin: + \CT@arc@ + \bool_if:NT \l__nicematrix_NiceArray_bool + { + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \pgfsetlinewidth \arrayrulewidth + \pgfsetrectcap + \__nicematrix_qpoint:n { col - 1 } + \dim_set_eq:NN \l_tmpa_dim \pgf@x + \__nicematrix_qpoint:n { row -1 } + \dim_set_eq:NN \l_tmpb_dim \pgf@y + \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \c@jCol } + \dim_set_eq:NN \l_tmpc_dim \pgf@x + \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c@iRow } + \pgfpathrectanglecorners + { \pgfpoint \l_tmpa_dim \l_tmpb_dim } + { \pgfpoint \l_tmpc_dim \pgf@y } + \pgfusepathqstroke + \endpgfpicture + } + \int_step_variable:nnNn 2 \c@iRow \l_tmpa_tl + { + \int_step_variable:nNn \c@jCol \l_tmpb_tl + { + \bool_gset_true:N \g_tmpa_bool + \seq_map_inline:Nn \g__nicematrix_pos_of_blocks_seq + { \__nicematrix_test_if_hline_in_block:nnnn ##1 } + \seq_map_inline:Nn \g__nicematrix_pos_of_xdots_seq + { \__nicematrix_test_if_hline_in_block:nnnn ##1 } + \bool_if:NT \g_tmpa_bool + { + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \pgfsetlinewidth \arrayrulewidth + \pgfsetrectcap + \__nicematrix_qpoint:n { row - \l_tmpa_tl } + \dim_set_eq:NN \l_tmpb_dim \pgf@y + \__nicematrix_qpoint:n { col - \l_tmpb_tl } + \dim_set_eq:NN \l_tmpa_dim \pgf@x + \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l_tmpb_tl } + \dim_set_eq:NN \l_tmpc_dim \pgf@x + \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim } + \pgfpathlineto { \pgfpoint \l_tmpc_dim \l_tmpb_dim } + \pgfusepathqstroke + \endpgfpicture + } + } + } + \int_step_variable:nNn \c@iRow \l_tmpa_tl + { + \int_step_variable:nnNn 2 \c@jCol \l_tmpb_tl + { + \bool_gset_true:N \g_tmpa_bool + \seq_map_inline:Nn \g__nicematrix_pos_of_blocks_seq + { \__nicematrix_test_if_vline_in_block:nnnn ##1 } + \seq_map_inline:Nn \g__nicematrix_pos_of_xdots_seq + { \__nicematrix_test_if_vline_in_block:nnnn ##1 } + \bool_if:NT \g_tmpa_bool + { + \pgfpicture + \pgfrememberpicturepositiononpagetrue + \pgf@relevantforpicturesizefalse + \pgfsetlinewidth \arrayrulewidth + \pgfsetrectcap + \__nicematrix_qpoint:n { row - \l_tmpa_tl } + \dim_set_eq:NN \l_tmpb_dim \pgf@y + \__nicematrix_qpoint:n { col - \l_tmpb_tl } + \dim_set_eq:NN \l_tmpa_dim \pgf@x + \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l_tmpa_tl } + \dim_set_eq:NN \l_tmpc_dim \pgf@y + \pgfpathmoveto { \pgfpoint \l_tmpa_dim \l_tmpb_dim } + \pgfpathlineto { \pgfpoint \l_tmpa_dim \l_tmpc_dim } + \pgfusepathqstroke + \endpgfpicture + } + } + } + \group_end: + \seq_gclear:N \g__nicematrix_pos_of_xdots_seq + } +\cs_set_protected:Npn \__nicematrix_test_if_hline_in_block:nnnn #1 #2 #3 #4 + { + \int_compare:nNnT \l_tmpa_tl > { #1 } + { + \int_compare:nNnT \l_tmpa_tl < { #3 + 1 } + { + \int_compare:nNnT \l_tmpb_tl > { #2 - 1 } + { + \int_compare:nNnT \l_tmpb_tl < { #4 + 1 } + { \bool_gset_false:N \g_tmpa_bool } + } + } + } + } +\cs_set_protected:Npn \__nicematrix_test_if_vline_in_block:nnnn #1 #2 #3 #4 + { + \int_compare:nNnT \l_tmpa_tl > { #1 - 1 } + { + \int_compare:nNnT \l_tmpa_tl < { #3 + 1 } + { + \int_compare:nNnT \l_tmpb_tl > { #2 } + { + \int_compare:nNnT \l_tmpb_tl < { #4 + 1 } + { \bool_gset_false:N \g_tmpa_bool } + } + } + } + } \cs_new:Npn \__nicematrix_hdottedline: { \noalign { \skip_vertical:N 2\l__nicematrix_radius_dim } @@ -3264,40 +3514,35 @@ \cs_new:Npn \__nicematrix_Block_i #1-#2 \q_stop { \__nicematrix_Block_ii:nnnnn { #1 } { #2 } } \cs_new_protected:Npn \__nicematrix_Block_ii:nnnnn #1 #2 #3 #4 #5 { - \tl_gput_left:Nx \g__nicematrix_internal_code_after_tl + \tl_set:Nx \l_tmpa_tl { - \__nicematrix_Block_iii:nnnnnn { \int_use:N \c@iRow } { \int_use:N \c@jCol } { \int_eval:n { \c@iRow + #1 - 1 } } { \int_eval:n { \c@jCol + #2 - 1 } } - { #3 } - \exp_not:n { { #4 $ #5 $ } } } - \cs_set_eq:NN \Block \__nicematrix_Block_error:nn - } -\cs_new:Npn \__nicematrix_Block_error:nn #1 #2 - { - \__nicematrix_error:n { Second~Block } - \cs_set_eq:NN \Block \use:nn + \seq_gput_left:NV \g__nicematrix_pos_of_blocks_seq \l_tmpa_tl + \seq_gput_left:Nx \g__nicematrix_blocks_seq + { + \l_tmpa_tl + { #3 } + \exp_not:n { { #4 \__nicematrix_math_toggle_token: #5 \__nicematrix_math_toggle_token: } } + } } \keys_define:nn { NiceMatrix / Block } { tikz .tl_set:N = \l__nicematrix_tikz_tl , tikz .value_required:n = true , - white .bool_set:N = \l__nicematrix_white_bool , - white .default:n = true , - white .value_forbidden:n = true , } +\cs_new_protected:Npn \__nicematrix_draw_blocks: + { \seq_map_inline:Nn \g__nicematrix_blocks_seq { \__nicematrix_Block_iii:nnnnnn ##1 } } \cs_new_protected:Npn \__nicematrix_Block_iii:nnnnnn #1 #2 #3 #4 #5 #6 { \group_begin: \keys_set:nn { NiceMatrix / Block } { #5 } - \bool_if:nTF - { - \int_compare_p:nNn { #3 } > \c@iRow - || \int_compare_p:nNn { #4 } > \c@jCol - } + \bool_lazy_or:nnTF + { \int_compare_p:nNn { #3 } > \c@iRow } + { \int_compare_p:nNn { #4 } > \c@jCol } { \msg_error:nnnn { nicematrix } { Block~too~large } { #1 } { #2 } } { \hbox_set:Nn \l__nicematrix_cell_box { #6 } @@ -3312,24 +3557,6 @@ \dim_set_eq:NN \l_tmpc_dim \pgf@y \__nicematrix_qpoint:n { col - \__nicematrix_succ:n { #4 } } \dim_set_eq:NN \l_tmpd_dim \pgf@x - \bool_if:NT \l__nicematrix_white_bool - { - \begin { pgfscope } - \pgfsetfillcolor { white } - \pgfpathrectanglecorners - { - \pgfpoint - { \l_tmpb_dim + 0.5 \arrayrulewidth } - { \l_tmpa_dim - 0.5 \arrayrulewidth } - } - { - \pgfpoint - { \l_tmpd_dim - 0.5 \arrayrulewidth } - { \l_tmpc_dim + 0.5 \arrayrulewidth } - } - \pgfusepathqfill - \end { pgfscope } - } \begin { pgfscope } \exp_args:Nx \pgfset { \l__nicematrix_tikz_tl } \__nicematrix_pgf_rect_node:nnnnn @@ -3434,21 +3661,23 @@ \cs_new_protected:Npn \__nicematrix_dotfill: { \__nicematrix_dotfill - \group_insert_after:N \__nicematrix_dotfill_i: + \bool_if:NT \l__nicematrix_NiceTabular_bool + { \group_insert_after:N \__nicematrix_dotfill_ii: } + { \group_insert_after:N \__nicematrix_dotfill_i: } } \cs_new_protected:Npn \__nicematrix_dotfill_i: { \group_insert_after:N \__nicematrix_dotfill_ii: } \cs_new_protected:Npn \__nicematrix_dotfill_ii: { \group_insert_after:N \__nicematrix_dotfill_iii: } \cs_new_protected:Npn \__nicematrix_dotfill_iii: { \dim_compare:nNnT { \box_wd:N \l__nicematrix_cell_box } = \c_zero_dim \__nicematrix_dotfill } -\cs_new_protected:Npn \__nicematrix_slashbox:nn #1 #2 +\cs_new_protected:Npn \__nicematrix_diagbox:nn #1 #2 { \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl { - \__nicematrix_actually_slashbox:nnnn + \__nicematrix_actually_diagbox:nnnn { \int_use:N \c@iRow } { \int_use:N \c@jCol } { #1 } { #2 } } } -\cs_new_protected:Npn \__nicematrix_actually_slashbox:nnnn #1 #2 #3 #4 +\cs_new_protected:Npn \__nicematrix_actually_diagbox:nnnn #1 #2 #3 #4 { \pgfpicture \pgf@relevantforpicturesizefalse @@ -3471,10 +3700,12 @@ \pgfset { inner~sep = 1 pt } \pgfscope \pgftransformshift { \pgfpoint \l_tmpb_dim \l_tmpc_dim } - \pgfnode { rectangle } { south~west } { $ #3 $ } { } { } + \pgfnode { rectangle } { south~west } + { \__nicematrix_math_toggle_token: #3 \__nicematrix_math_toggle_token: } { } { } \endpgfscope \pgftransformshift { \pgfpoint \l_tmpd_dim \l_tmpa_dim } - \pgfnode { rectangle } { north~east } { $ #4 $ } { } { } + \pgfnode { rectangle } { north~east } + { \__nicematrix_math_toggle_token: #4 \__nicematrix_math_toggle_token: } { } { } \endpgfpicture } \cs_new_protected:Npn \__nicematrix_CodeAfter:n #1 \end @@ -3492,14 +3723,6 @@ \__nicematrix_CodeAfter:n } } -\__nicematrix_msg_new:nn { obsolete~environments } - { - The~obsolete~environments~(eg.~{pNiceArrayC})~have~been~deleted~ - from~the~package~nicematrix.\\ - However,~if~you~still~want~to~use~them,~you~will~find~the~code~for~ - those~environments~at~the~end~of~the~file~'nicematrix.sty',~after~ - a~command~'\token_to_str:N\file_input_stop:'. - } \keys_define:nn { NiceMatrix / Package } { renew-dots .bool_set:N = \l__nicematrix_renew_dots_bool , @@ -3508,11 +3731,6 @@ renew-matrix .value_forbidden:n = true , transparent .meta:n = { renew-dots , renew-matrix } , transparent .value_forbidden:n = true, - obsolete-environments .code:n = \__nicematrix_fatal:n { obsolete~environments }, - starred-commands .code:n = - \__nicematrix_msg_redirect_name:nn { starred~commands } { none } , - starred-commands .value_forbidden:n = true , - } \ProcessKeysOptions { NiceMatrix / Package } \cs_new_protected:Npn \__nicematrix_convert_to_str_seq:N #1 @@ -3622,13 +3840,10 @@ the~option~'light-syntax'.~You~must~use~the~character~'\l__nicematrix_end_of_row_tl'~ (set~by~the~option~'end-of-row').~This~error~is~fatal. } -\__nicematrix_msg_new:nn { starred~commands } +\__nicematrix_msg_new:nn { standard-cline~in~document } { - The~starred~versions~of~\token_to_str:N \Cdots,~\token_to_str:N \Ldots,~ - \token_to_str:N \Vdots,~\token_to_str:N\Ddots\ and~\token_to_str:N\Iddots\ - are~deprecated.~However,~you~can~go~on~for~this~time.~If~you~don't~want~to~ - see~this~error~we~should~load~'nicematrix'~with~the~option~ - 'starred-commands'. + The~key~'standard-cline'~is~available~only~in~the~preamble.\\ + If~you~go~on~this~command~will~be~ignored. } \__nicematrix_msg_new:nn { bad~value~for~baseline } { @@ -3637,11 +3852,6 @@ \int_use:N \g__nicematrix_row_total_int\ or~equal~to~'t',~'c'~or~'b'.\\ If~you~go~on,~a~value~of~1~will~be~used. } -\__nicematrix_msg_new:nn { Second~Block } - { - You~can't~use~\token_to_str:N \Block\ twice~in~the~same~cell~of~the~array.\\ - If~you~go~on,~this~command~(and~the~other)~will~be~ignored. - } \__nicematrix_msg_new:nn { empty~environment } { Your~\__nicematrix_full_name_env:\ is~empty.~This~error~is~fatal. } \__nicematrix_msg_new:nn { unknown~cell~for~line~in~code-after } @@ -3699,7 +3909,7 @@ The~key~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~command~ \token_to_str:N \NiceMatrixOptions. \\ If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~keys,~type~H~. + For~a~list~of~the~*principal*~available~keys,~type~H~. } { The~available~options~are~(in~alphabetic~order):~ @@ -3714,7 +3924,6 @@ create-medium-nodes,~ create-large-nodes,~ end-of-row,~ - exterior-arraycolsep,~ first-col,~ first-row,~ hlines,~ @@ -3725,7 +3934,6 @@ letter-for-dotted-lines,~ light-syntax,~ nullify-dots,~ - parallelize-diags,~ renew-dots,~ renew-matrix,~ right-margin,~ @@ -3741,7 +3949,7 @@ The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~environment~ \{NiceArray\}. \\ If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~. + For~a~list~of~the~*principal*~available~options,~type~H~. } { The~available~options~are~(in~alphabetic~order):~ @@ -3759,7 +3967,6 @@ create-extra-nodes,~ create-medium-nodes,~ create-large-nodes,~ - end-of-row,~ extra-left-margin,~ extra-right-margin,~ first-col,~ @@ -3772,9 +3979,10 @@ light-syntax,~ name,~ nullify-dots,~ - parallelize-diags,~ renew-dots,~ right-margin,~ + rules/color,~ + rules/width,~ small,~ t,~ vlines,~ @@ -3787,7 +3995,7 @@ The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~ \__nicematrix_full_name_env:. \\ If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~. + For~a~list~of~the~*principal*~available~options,~type~H~. } { The~available~options~are~(in~alphabetic~order):~ @@ -3805,7 +4013,6 @@ create-extra-nodes,~ create-medium-nodes,~ create-large-nodes,~ - end-of-row,~ extra-left-margin,~ extra-right-margin,~ first-col,~ @@ -3819,10 +4026,11 @@ light-syntax,~ name,~ nullify-dots,~ - parallelize-diags,~ r~(=R),~ renew-dots,~ right-margin,~ + rules/color,~ + rules/width,~ S,~ small,~ t,~ @@ -3836,7 +4044,7 @@ The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~environment~ \{NiceTabular\}. \\ If~you~go~on,~it~will~be~ignored. \\ - For~a~list~of~the~available~options,~type~H~. + For~a~list~of~the~*principal*~available~options,~type~H~. } { The~available~options~are~(in~alphabetic~order):~ @@ -3854,7 +4062,6 @@ create-extra-nodes,~ create-medium-nodes,~ create-large-nodes,~ - end-of-row,~ extra-left-margin,~ extra-right-margin,~ first-col,~ @@ -3867,9 +4074,10 @@ light-syntax,~ name,~ nullify-dots,~ - parallelize-diags,~ renew-dots,~ right-margin,~ + rules/color,~ + rules/width,~ t,~ vlines,~ xdots/color,~ @@ -3900,85 +4108,6 @@ and~R~in~the~preamble~of~your~environment. \\ This~error~is~fatal. } -\file_input_stop: -\NewDocumentEnvironment { pNiceArrayC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \pNiceArray - } - { \endpNiceArray } - \NewDocumentEnvironment { bNiceArrayC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \bNiceArray - } - { \endbNiceArray } -\NewDocumentEnvironment { BNiceArrayC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \BNiceArray - } - { \endBNiceArray } -\NewDocumentEnvironment { vNiceArrayC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \vNiceArray - } - { \endvNiceArray } -\NewDocumentEnvironment { VNiceArrayC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \VNiceArray - } - { \endVNiceArray } -\NewDocumentEnvironment { pNiceArrayRC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \int_zero:N \l__nicematrix_first_row_int - \pNiceArray - } - { \endpNiceArray } -\NewDocumentEnvironment { bNiceArrayRC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \int_zero:N \l__nicematrix_first_row_int - \bNiceArray - } - { \endbNiceArray } -\NewDocumentEnvironment { BNiceArrayRC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \int_zero:N \l__nicematrix_first_row_int - \BNiceArray - } - { \endBNiceArray } -\NewDocumentEnvironment { vNiceArrayRC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \int_zero:N \l__nicematrix_first_row_int - \vNiceArray - } - { \endvNiceArray } -\NewDocumentEnvironment { VNiceArrayRC } { } - { - \int_zero:N \l__nicematrix_last_col_int - \int_zero:N \l__nicematrix_first_row_int - \VNiceArray - } - { \endVNiceArray } -\NewDocumentEnvironment { NiceArrayCwithDelims } { } - { - \int_zero:N \l__nicematrix_last_col_int - \NiceArrayWithDelims - } - { \endNiceArrayWithDelims } -\NewDocumentEnvironment { NiceArrayRCwithDelims } { } - { - \int_zero:N \l__nicematrix_last_col_int - \int_zero:N \l__nicematrix_first_row_int - \NiceArrayWithDelims - } - { \endNiceArrayWithDelims } \endinput %% -- cgit v1.2.3