# Array environment cell over two rows keeping alignment

I am trying to span braces over two rows while keeping the aligment in the following example

correct alignment

in this case the alignment is correct. I think I am nearly there, any help would be greatly appreciated.

The above image is generated by

$$\begin{array}[t]{ccccccccccl} & & & & & a & a & a &a & \} & d \vspace{0.1cm} \\ \hline \vspace{-0.4cm}\\ & & & & &a & a & a &a\\ & & & & & & b & b & b& \Big\} &d\\ & & & c & c & c & c &c& c \\ \hline \vspace{-0.4cm}\\ & & & a &a & a & a & a &a\\ & & & & b &b &b & b & b & \Big\} & d\\ & c &c & c & c&c& &c& c\vspace{0.1cm} \\ \end{array}\label{eq:diagramm}$$.


The braces should look like

correct braces

but this destroys the alignment. This try is based on this question

\documentclass{article}
\usepackage{amsmath,amsthm,array}% http://ctan.org/pkg/{amsmath,amsthm,array}
\newcommand{\twolinebrace}{\left.\kern-\nulldelimiterspace\begin{array}{@{}c@{}}   \\\\\end{array}\right\}}
\newtheorem{theorem}{Theorem}
\begin{document}
$\renewcommand{\arraystretch}{1.25} \begin{array}{@{}l@{\quad}l@{}} \begin{array}{lllllllll} & & & & &a & a & a &a\\ % RHS & & & & & & b & b & b \\ % RHS & & & &c& c& c &c& c % RHS \end{array} & \twolinebrace\text{d} \\ \begin{array}{lllllllll} & & & & a &a & a & a &a\\ % RHS & & & & & b & b & b & b \\ % RHS & & & c&c& c& c &c& c % RHS \end{array} & \twolinebrace\text{d} \end{array}$
\end{document}


You can do that easily with the blkarray package. It requires two columns less than in your code:

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

\begin{document}
$\renewcommand{\arraystretch}{1.3} \begin{blockarray}{*{9}{l}} \begin{block}{*{8}{l}l<{\,}\Right{\}}{\, d }} & & & & &a & a & a &a \\ & & & & & & b & b & b \\ & & & &c& c& c &c& c \\ \end{block} \begin{block}{*{8}{l}l<{\,}\Right{\}}{\, d }} & & & & a & a & a & a & a \\ & & & & & b & b & b & b \\ & & & c & c & c & c & c & c \\ \end{block} %\end{block} \end{blockarray}$
\end{document}


to keep the alignment, you need to use just one array.

the braces can be \smashed, avoiding the spreading of the rows.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\renewcommand{\arraystretch}{1.25} \begin{array}{lllllllllll} & & & & &a & a & a &a &&\\ % RHS & & & & & & b & b & b & \smash{\Bigg\}} & d\\ % RHS & & & &c& c& c &c& c \\% RHS & & & & a &a & a & a &a &&\\ % RHS & & & & & b & b & b & b & \smash{\Bigg\}} & d\\ % RHS & & & c&c& c& c &c& c % RHS \end{array}$
\end{document}


this uses, for convenience, the largest existing size, \Bigg, but a larger one could be constructed if necessary, enlarging the dimension used to construct the "big" fences:

\def\Big#1{{\hbox{$\left#1\vbox to11.5\p@{}\right.\n@space$}}}
\def\bigg#1{{\hbox{$\left#1\vbox to14.5\p@{}\right.\n@space$}}}
\def\Bigg#1{{\hbox{$\left#1\vbox to17.5\p@{}\right.\n@space$}}}


the difference between steps is 3pt, so the next two steps would be

\def\biggg#1{{\hbox{$\left#1\vbox to20.5\p@{}\right.\n@space$}}}
\def\Biggg#1{{\hbox{$\left#1\vbox to23.5\p@{}\right.\n@space$}}}


(these definitions are from plain.tex, and assume the computer modern fonts.)

Add a \phantom{c} in one of the early cells in the third row of the first large array, and your code needs no further tweaking.

\documentclass{article}
\usepackage{amsmath,amsthm,array}% http://ctan.org/pkg/{amsmath,amsthm,array}
\newcommand{\twolinebrace}{\left.\kern-\nulldelimiterspace\begin{array}{@{}c@{}}   \\\\\end{array}\right\}}
\newtheorem{theorem}{Theorem}
\begin{document}
$\renewcommand{\arraystretch}{1.25} \begin{array}{@{}l@{\quad}l@{}} \begin{array}{lllllllll} & & & & &a & a & a &a\\ % RHS & & & & & & b & b & b \\ % RHS & & & \phantom{c}&c& c& c &c& c % RHS \end{array} & \twolinebrace\text{d} \\ \begin{array}{lllllllll} & & & & a &a & a & a &a\\ % RHS & & & & & b & b & b & b \\ % RHS & & & c&c& c& c &c& c % RHS \end{array} & \twolinebrace\text{d} \end{array}$
\end{document}


Addendum: One piece of your code that does look like it could stand some tweaking is the macro \twolinebrace: Since the brace spans three rather than just two rows, you may want to define (and use) a new macro, which I'll name \threelinebrace:

\newcommand{\threelinebrace}{\left.\kern-\nulldelimiterspace\begin{array}{@{}c@{} \\\\\\ \end{array}\right\}}


Compared with \twolinebrace, the new macro features an additional \\ pair.