# Aligning a matrix within a matrix

I've seen a lot on this website that has helped me get started, but I have one last problem: how do I align the 0s in the first row to the matrix below them?

\documentclass{article}
\usepackage{amsmath}
\usepackage [american]{babel}
\begin{document}
\begin{equation*}
\left[
\begin{array}{cc}
\begin{matrix}
0
\end{matrix} & \begin{matrix}
0 & 0 & 0
\end{matrix} \\
\begin{matrix}
0 \\
0 \\
0 \\
\end{matrix}
& \begin{bmatrix}
n_1 & 0 & 0 \\
0 & n_2 & 0 \\
0 & 0 & n_3
\end{bmatrix}^{-1}
\end{array}\right]
\end{equation*}
\end{document}


\left[
\begin{array}{cc}
\begin{matrix}
0
\end{matrix} & \begin{matrix}
~0~~ & 0~~ & 0~~  & \\
\end{matrix} \\
\begin{matrix}
0 \\
0 \\
0 \\
\end{matrix}
& \begin{bmatrix}
n_1 & 0 & 0 \\
0 & n_2 & 0 \\
0 & 0 & n_3
\end{bmatrix}^{-1}
\end{array}\right]

• I didn't know you could do this! Thank you! Commented Dec 16, 2015 at 18:32

With {bNiceMatrix} of nicematrix (≥ 5.18 of 2021-07-15).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

$\begin{bNiceMatrix}[right-margin=1.5em] 0 & 0 & 0 & 0 \\ 0 & n_1 & 0 & 0 \\ 0 & 0 & n_2 & 0 \\ 0 & 0 & 0 & n_3 \CodeAfter \SubMatrix[{2-2}{4-4}]^{\!-1} \end{bNiceMatrix}$

\end{document}