How can I write a matrix, with brackets that cover only rows/columns in a certain range, but still has the right indentation? What I would like:

My current solution:
\[
\overset{
\begin{array}{lrccccc}
\hspace{-8mm}x_1 & \hspace{6mm} x_2 & \hspace{3mm} \cdot & \hspace{0mm} \cdot & \hspace{0mm} \cdot & \hspace{2mm} x_n &
\end{array}}
{\left[\hspace{-2mm}
\begin{array}{ccccccc}
a_{11} & a_{12} & \cdot & \cdot & \cdot & a_{1n} & b_1 \\
a_{21} & a_{22} & \cdot & \cdot & \cdot & a_{2n} & b_2 \\
\cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot \\
\cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot \\
\cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot \\
a_{r1} & a_{r2} & \cdot & \cdot & \cdot & a_{rn} & b_r \\
a_{r+1,1} & a_{r+1,2} & \cdot & \cdot & \cdot & a_{r+1,n} & b_{r+1} \\
\cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot \\
\cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot \\
\cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot \\
a_{m1} & a_{m2} & \cdot & \cdot & \cdot & a_{mn} & b_m
\end{array}\hspace{-2mm}\right]}
\;\overset{\mbox{\large $\mathcal E$}}{\mbox{\Large $\sim $}}\;
\overset{
\begin{array}{lccccccccccc}
\hspace{-8mm}x'_1 & x'_2 & \hspace{1.5mm} x'_3 & \hspace{1mm} x'_4 & \hspace{2mm}\cdot & \hspace{0.5mm}\cdot & \hspace{4.7mm}\cdot & \hspace{4.mm} \cdot & \cdot & \cdot & \hspace{1.2mm} x'_n &
\end{array}}
{\left[\hspace{-1.5mm}
\begin{array}{lccccccccccc}
1 & a'_{12} & a'_{13} & a'_{14} & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & a'_{1n} & b'_1 \\
0 & 1 & a'_{23} & a'_{24} & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & a'_{2n} & b'_2 \\
\cdot &\cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot \\
\cdot &\cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot \\
\cdot &\cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot & \cdot \\
0 &\cdot & \cdot & \cdot & 0 & 1 & a'_{r,r+1}& \cdot & \cdot & \cdot & a'_{r,n}& b'_r \\
0 &\cdot & \cdot & \cdot & 0 & 0 & 0 & \cdot & \cdot & \cdot & 0 & b'_{r+1} \\
0 &\cdot & \cdot & \cdot & 0 & 0 & 0 & \cdot & \cdot & \cdot & 0 & \cdot \\
0 &\cdot & \cdot & \cdot & 0 & 0 & 0 & \cdot & \cdot & \cdot & 0 & \cdot \\
0 &\cdot & \cdot & \cdot & 0 & 0 & 0 & \cdot & \cdot & \cdot & 0 & \cdot \\
0 &\cdot & \cdot & \cdot & 0 & 0 & 0 & \cdot & \cdot & \cdot & 0 & b'_m
\end{array}\hspace{-2mm}\right]}
\]
I'm looking for less clumsy, more automatic solutions, that don't require the user to manually adjust the indentation (centering).


kbordermatrixis widely used. See http://tex.stackexchange.com/questions/71126/row-spacing-in-kbordermatrix for an example. – percusse Nov 04 '12 at 15:33\bordermatrixwith brackets[ ]instead of parentheses( )– barbara beeton Nov 04 '12 at 15:53