[Tex/LaTex] Nested matrices with aligned columns and rows

arraysmath-mode

I'm trying to represent "matrices" with more than two dimensions, like the Riemann curvature tensor or Christoffel symbols, using nested matrices. I still don't know if this can help working with these objects (and that's not really relevant to this topic anyway), but before judging I'd like to see how it looks on a computer screen.
The idea is to write a vector of matrices for a 3-indices matrix, a matrix of matrices for a 4-indices matrix and so on. This is not difficult in principle:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
\Gamma^{\sigma}_{\mu \nu} = \begin{pmatrix}
    \begin{pmatrix}
        0 & 0 & 0 \\
        0 & -r & 0 \\
        0 & 0 & -r \sin^2(\vartheta)
    \end{pmatrix} \\
    \begin{pmatrix}
        0 & \frac{1}{r} & 0 \\
        \frac{1}{r} & 0 & 0 \\
        0 & 0 & - \sin(\vartheta) \cos(\vartheta)
    \end{pmatrix} \\
    \begin{pmatrix}
        0 & 0 & \frac{1}{r} \\
        0 & 0 & \frac{1}{\tan(\vartheta)} \\
        \frac{1}{r} & \frac{1}{\tan(\vartheta)} & 0
    \end{pmatrix}
\end{pmatrix}
\]

\end{document}

but the result looks really ugly:

enter image description here

That's what I wanted, but not how I wanted it. Is there a way to align columns and rows of different matrices? Or, alternatively, is there a way to insert internal parentheses that span through multiple rows in a big matrix with all the components?

Best Answer

You could use the blkarray package:

\documentclass{article}
\usepackage{amsmath}
\usepackage{blkarray}

\begin{document}

\[
\Gamma^{\sigma}_{\mu \nu} = 
\left(
\begin{blockarray}{ ccc }
\begin{block}{( ccc )}
  0 & 0 & 0 \\
  0 & -r & 0 \\
  0 & 0 & -r \sin^2(\vartheta) \\
\end{block}
\begin{block}{( ccc )}
  0 & \frac{1}{r} & 0 \\
  \frac{1}{r} & 0 & 0 \\
  0 & 0 & - \sin(\vartheta) \cos(\vartheta) \\
\end{block}
\begin{block}{( ccc )}
  0 & 0 & \frac{1}{r} \\[1ex]
  0 & 0 & \frac{1}{\tan(\vartheta)} \\[1ex]
  \frac{1}{r} & \frac{1}{\tan(\vartheta)} & 0 \\
\end{block}
\end{blockarray}
\right)
\]

\end{document}

enter image description here