1

I am trying to be fancy/lazy in nicematrix (version 5.19 on Overleaf TeX Live 2020) by generating a matrix using the iRow and jCol counters.

Here is an example of what I try to achieve : Ideal result

The previous result is done with the following code :

\begin{equation*}
    \begin{bNiceMatrix}%
    [
        r,
        first-row,
        last-col,
        code-for-first-row = \Block{}{\scriptstyle \color{blue} \arabic{jCol}},
        code-for-last-col = \scriptstyle \color{red} \arabic{iRow}
    ]
        & & & & \\
        (-1)^{1+1+1}(1+1) & (-1)^{1+2+1}(1+2) & (-1)^{1+3+1}(1+3) & (-1)^{1+3+1}(1+4) & \\
        (-1)^{2+1+1}(2+1) & (-1)^{2+2+1}(2+2) & (-1)^{2+3+1}(2+3) & (-1)^{2+3+1}(2+4) & \\
        (-1)^{3+1+1}(3+1) & (-1)^{3+2+1}(3+2) & (-1)^{3+3+1}(3+3) & (-1)^{3+3+1}(3+4) & \\
        (-1)^{4+1+1}(4+1) & (-1)^{4+2+1}(4+2) & (-1)^{4+3+1}(4+3) & (-1)^{4+3+1}(4+4) &
    \end{bNiceMatrix}
\end{equation*}

However, instead of defining each term on its own, I try to use iRow and jCol :

\begin{equation*}
    \begin{bNiceMatrix}%
    [
        r,
        first-row,
        last-col,
        code-for-first-row = \Block{}{\scriptstyle \color{blue} \arabic{jCol}},
        code-for-last-col = \Block{}{\scriptstyle \color{red} \arabic{iRow}}
    ]
        & & & & \\
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) & \\
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) & \\
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) & \\
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) &
        (-1)^{\arabic{iRow} + \arabic{jCol} + 1}(\arabic{iRow}+\arabic{jCol}) & \\
    \end{bNiceMatrix}
\end{equation*}

Which lead to the following result : Bad sizing

There seems to be a sizing problem when using the counters, but the problem only seems to appear when using them as exponent, since removing it also bring back the delimiters to the right place :

\begin{equation*}
    \begin{bNiceMatrix}%
    [
        r,
        first-row,
        last-col,
        code-for-first-row = \Block{}{\scriptstyle \color{blue} \arabic{jCol}},
        code-for-last-col = \Block{}{\scriptstyle \color{red} \arabic{iRow}}
    ]
        & & & & \\
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) & \\
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) & \\
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) & \\
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) &
        (\arabic{iRow} + \arabic{jCol} + \arabic{iRow} + \arabic{jCol}) & \\
    \end{bNiceMatrix}
\end{equation*}

leads to No exponent : correct sizing

Finally, nicematrix offers the AutoNiceMatrix commands, and when using them the sizing is correct :

\begin{equation*}
     \bAutoNiceMatrix{4-4}{(-1)^{\arabic{iRow} + \arabic{jCol} + 1} (\arabic{iRow}+\arabic{jCol})}
\end{equation*}

leads to AutoNiceMatrix

For this usecase, the AutoNiceMatrix would be an option, but it is not always possible to define one general term for the matrix.

Has anyone encountered this problem and could help me "generate" my matrices instead of writing them by hand?

Thanks in advance.

2
  • I get the expected result with nicematrix 2021/07/23 v5.19. And also with TeX Live 2020 and nicematrix 2021/03/23 v5.13
    – egreg
    Aug 6 '21 at 14:54
  • 2
    I think you should try to recompile after deletion of the aux file. In Overleaf: "View logs" (on the right of the PDF panel) and "Clear cache files" (red button). Sometimes, when modifying a document using nicematrix, the informations written on the aux files are out-of-date (because they were valid only for the previous version of the document). Aug 7 '21 at 17:52
2

Deleting the aux file and recompiling, as suggested by F. Pantigny in a comment, indeed solved the problem.

Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.