# Nested matrices with aligned columns and rows

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: 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?

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Henri Menke May 27 '14 at 11:54
• To show the output you can upload an image, as you don't have enough rep yet, remove the ! from the generated markup, which will make a link, then someone will add the ! back later. – David Carlisle May 27 '14 at 12:44
• Henri: It's not tedious, but it's hard to understand why such important details aren't written in a place easy to find, such as the detailed guide in the post editor. I don't understand to which standard should I make my code compatible, but I edited as you asked. David: I remember clearly I discovered MathJax on StackExchange a few years ago, but it doesn't seem to work now. Was it removed? – GRB May 27 '14 at 13:22
• @MFH I uploaded the image of the result. I hope that's OK. – Gonzalo Medina May 27 '14 at 13:39

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} • This seems exactly what I was looking for. I'll have a look at it and in case ask some more questions. Thanks! – GRB May 27 '14 at 14:10
• @MFH You're welcome! Don't forget that you can accept an answer that you consider solved your problem by clicking the checkmark to its left. In case of doubt, please see How do you accept an answer?. – Gonzalo Medina May 27 '14 at 14:22