3

I have a NiceMatrix which is right aligned, but I am looking for a way to have the first-row centered.

Here is the code :

\begin{bNiceMatrix}[r,first-row,last-col,code-for-first-row = \scriptstyle \color{blue} \arabic{jCol},code-for-last-col = \scriptstyle \color{blue} \arabic{iRow}]
    &  &  &  & \\
    -2 & 3 & -4 & 5 & \\
    3 & -4 & 5 & -6 & \\
    -4 & 5 & -6 & 7 & \\
    5 & -6 & 7 & -8 & 
\end{bNiceMatrix}

And here is the result :

enter image description here

I would like to have the blue column numbers centered.

Thanks in advance for the help.

Z

1 Answer 1

2

You should put each element of the ``first row'' in a mono-cell \Block. By default, the value of alignement of a \Block is c (centered).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$\begin{bNiceMatrix}%
  [
    r,
    first-row,
    last-col,
    code-for-first-row = \Block{}{\color{blue} \scriptstyle \arabic{jCol}},
    code-for-last-col = \scriptstyle \color{blue} \arabic{iRow}
  ]
     &   &    &   & \\
  -2 & 3 & -4 & 5 & \\
  3 & -4 & 5 & -6 & \\
  -4 & 5 & -6 & 7 & \\
  5 & -6 & 7 & -8 & \\
\end{bNiceMatrix}$

\end{document}

As usual with nicematrix, you need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .