The nicematrix package
3 The vertical position of the arrays¶
The package nicematrix provides a option baseline for the vertical position of the arrays. This option takes in as value an integer which is the number of the row on which the array will be aligned.
$A = \begin{pNiceMatrix}[baseline=2]
\frac{1}{\sqrt{1+p^2}} & p & 1-p \\
1 & 1 & 1 \\
1 & p & 1+p
\end{pNiceMatrix}$
It’s also possible to use the option baseline with one of the special values t, c or b. These letters may also be used absolutely like the option of the environments {tabular} and {array} of array. The initial value of baseline is c.
In the following example, we use the option t (equivalent to baseline=t) immediately after an \item of list. One should remark that the presence of a \hline at the beginning of the array doesn’t prevent the alignment of the baseline with the baseline of the first row (with {tabular} or {array} of array, one must use \firsthline).
\begin{enumerate}
\item an item
\smallskip
\item \renewcommand{\arraystretch}{1.2}
$\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}
However, it’s also possible to use the tools of booktabs1: \toprule, \bottomrule, \midrule, etc.
\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}
It’s also possible to use the key baseline to align a matrix on an horizontal rule (drawn by \hline). In this aim, one should give the value line-i where i is the number of the row following the horizontal rule.
\NiceMatrixOptions{cell-space-limits=1pt}
$A=\begin{pNiceArray}{cc|cc}[baseline=line-3]
\dfrac{1}{A} & \dfrac{1}{B} & 0 & 0 \\
\dfrac{1}{C} & \dfrac{1}{D} & 0 & 0 \\
\hline
0 & 0 & A & B \\
0 & 0 & D & D \\
\end{pNiceArray}$
1 The extension booktabs is not loaded by nicematrix.