# Align ddots in nicematrix

So I am using the package nicematrix to write a matrix with unlimited entries, but the ddots on the middle and lower right are not aligned with each other. Is there a way to achieve this?

This is my code:

\begin{pNiceMatrix}
C_{0m}C_{0m}&C_{0m}C_{1m} & \cdots \\
C_{1m}C_{0m}&\ddots &\\
\vdots& &\ddots\\
\end{pNiceMatrix}


\documentclass{article}
\usepackage{nicematrix}
\begin{document}
$\renewcommand{\arraystretch}{2.25} % <--- \begin{pNiceMatrix} C_{0m}C_{0m}& C_{0m}C_{1m} & \cdots \\ C_{1m}C_{0m}& \ddots & \\ \vdots & & \ddots \end{pNiceMatrix}$
\end{document}

• Sneaky but effective. The key is making the cells essentially square. One might complain that the dots in the middle are too high, not vertically aligned on the math axis, but trying to achieve that would only make the problem more difficult and the result more space-gobbling. Well done. Jul 24 '21 at 20:29
• @barbarabeeton, Good to have your comments! Jul 24 '21 at 21:26

We should use \Cdots, \Vdots, \Ddots (unless you use the option renew-dots).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$\begin{pNiceMatrix}[extra-margin=2mm] C_{0m}C_{0m} &C_{0m}C_{1m} & \Cdots \\ C_{1m}C_{0m} &\Ddots & \\ \Vdots & & \hspace*{5mm}\\ \end{pNiceMatrix}$

\end{document}


I have put \hspace*{5mm} in the last cell to have a non empty-cell (nicematrix does not like empty cells).

• Doesn’t look particularly pretty to me. I especially don’t like the position of the diagonal dots or their end position. Jul 24 '21 at 13:07
• @Gaussler: In fact, I think that such matrix is not good mathematical design. I think one should put at least the content of the four corners of the matrix. Jul 24 '21 at 13:11

To draw a nice dotted diagonal, from the bottom center of cell to the top center of the other, using nicematrix you need to do two things:

(1) Fill the cell with some content (invisible). I choose \phantom{\cdots} because you may want to show cdots after all.

(2) Use \CodeAfter to draw the dotted diagonal.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}

\begin{align*}
\begin{pNiceMatrix}
C_{0m}C_{0m}& C_{0m}C_{1m} & \cdots \\
C_{1m}C_{0m}& \phantom{\cdots}    &  \\
\vdots      &             & \phantom{\cdots}\\