# Vertical lines in matrices should be aligned

I'm trying to write matrices one below the other but I want the vertical lines (compare example below) to be aligned. Eventually, there will be several matrices in one document - in the example below there are only two.

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{align}
\begin{array}{l}
\mathrm{I} \\
\mathrm{II} \\
\mathrm{III} \\
\end{array}
\left (
\begin{array}{rrr|r}
3 & 6 & 3 & 3 \\
2 & 1 & -1 & -1 \\
-1 & 2 & 2 & 1 \\
\end{array}
\right )
\begin{array}{c}
\\
\mathrm{II} + \left (-\frac 2 3 \right ) \cdot \mathrm{I} \\
\mathrm{III} + \left (\frac 1 3 \right ) \cdot \mathrm{I}\\
\end{array}
\end{align}
\begin{align}
\begin{array}{l}
\mathrm{I^{**}}\\
\mathrm{II^{**}} \\
\mathrm{III^{***}} \\
\end{array}
\left (
\begin{array}{rrr|r}
1 & 0 & 0 & 1 \\
0 & 1 & 0 & -1 \\
0 & 0 & 1 & 2 \\
\end{array}
\right )
\end{align}
\end{document}


If the numbers in the last column are of the same size, you can just put both matrices in the same align and put the alignment point (&) just after the matrices. I also added some extra space between the two lines with \2\jot]. \documentclass{article} \usepackage{amsmath} \begin{document} \begin{align} \begin{array}{l} \mathrm{I} \\ \mathrm{II} \\ \mathrm{III} \end{array} \left ( \begin{array}{rrr|r} 3 & 6 & 3 & 3 \\ 2 & 1 & -1 & -1 \\ -1 & 2 & 2 & 1 \end{array} \right )& \begin{array}{c} \\ \mathrm{II} + \left (-\frac 2 3 \right ) \cdot \mathrm{I} \\ \mathrm{III} + \left (\frac 1 3 \right ) \cdot \mathrm{I} \end{array} \\[2\jot] \begin{array}{l} \mathrm{I^{**}}\\ \mathrm{II^{**}} \\ \mathrm{III^{***}} \end{array} \left ( \begin{array}{rrr|r} 1 & 0 & 0 & 1 \\ 0 & 1 & 0 & -1 \\ 0 & 0 & 1 & 2 \end{array} \right )& \end{align} \end{document}  In order to further ease the reader's ability to let his/her eye roam vertically across the display, I would not only align the two vertical bars but also the various columns of the matrices through judicious insertions of \phantom{-} instructions. \documentclass{article} \usepackage{amsmath} \begin{document} \begin{align*} \begin{array}{l} \mathrm{I} \\ \mathrm{II} \\ \mathrm{III\phantom{^{***}}} \\ \end{array} &\left ( \begin{array}{rrr|r} 3 & \phantom{-}6 & 3 & 3 \\ 2 & 1 & -1 & -1 \\ -1 & 2 & 2 & 1 \\ \end{array} \right ) \begin{array}{l} \\ \mathrm{II} + \left (-\tfrac 2 3 \right ) \cdot \mathrm{I} \\ \mathrm{III} + \left (\tfrac 1 3 \right ) \cdot \mathrm{I}\\ \end{array} \\ \begin{array}{l} \mathrm{I^{**}}\\ \mathrm{II^{**}} \\ \mathrm{III^{***}} \\ \end{array} &\left ( \begin{array}{rrr|r} \phantom{-}1 & \phantom{-}0 & \phantom{-}0 & 1 \\ 0 & 1 & 0 & -1 \\ 0 & 0 & 1 & 2 \\ \end{array} \right ) \end{align*} \end{document}  You can do that easily with {NiceArray} of nicematrix. \documentclass{article} \usepackage{nicematrix} \begin{document} \NiceMatrixOptions{vlines-in-sub-matrix=I} \[\begin{NiceArray}{lcccIcl} \mathrm{I} & 3 & 6 & 3 & 3 \\ \mathrm{II} & 2 & 1 & -1 & -1 & \mathrm{II}+\bigl(-\frac{2}{3}\bigr)\cdot \mathrm{I} \\ \mathrm{III} & -1 & 2 & 2 & 1 & \mathrm{III} + \bigl(\frac{1}{3}\bigr) \cdot \mathrm{I} \\[2mm] \mathrm{I^{**}} & 1 & 0 & 0 & 1 \\ \mathrm{II^{**}} & 0 & 1 & 0 & -1 \\ \mathrm{III^{***}} & 0 & 0 & 1 & 2 \\ \CodeAfter \SubMatrix({1-2}{3-5}) \SubMatrix({4-2}{6-5}) \end{NiceArray}

\end{document}


You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).