Matrix row alignment on two sides of an equation, with rules

I have the following code to generate a matrix equation, on the LHS matrix, a couple of rules are added, that causes the RHS corresponding rows misaligned (vertically). How do I adjust subtle vspace in the RHS matrix if I'm sticking with the current code? Also is there a way to adjust the gray-scale of the rules (to make them less distracting)?

\documentclass{article}
\usepackage{mathtools}
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,matrix,positioning}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=3pt, anchor=base] (#1) {#2};}

\begin{document}
$$\begin{bmatrix}[cc|c|c|c|c] \phantom{abcd} & \phantom{ } & & & 0 & \phantom{abcd} \\ & & & & 0 & \\ & & & & \cdots & \\ & & & & \cdots & \\ \cmidrule(lr){1-6} & & a^{*}_{ts} & & 1 & \\ \cmidrule(lr){1-6} & & & & 0 & \\ & & & & \cdots & \\ & & & & \cdots & \\ & & & & \cdots & \\ & & & & 0 & \\ & & & & 0 & \\ \cmidrule(lr){1-6} & & \tikzmark{enter}{c^{*}_s} & & \tikzmark{leaving}{c^{*}_t} & \\ \end{bmatrix} = \begin{bmatrix} \phantom{four} \\ \\ \\ \\ b^{*}_t \\ \\ \\ \\ \\ \\ \\ \\ -v \\ \end{bmatrix}$$
\tikz[overlay,remember picture] {
\draw[<-,>=stealth] (enter) -- ++(0,-1cm) node [label={[xshift=-8pt,yshift=-20pt]entering}] {};
\draw[<-,>=stealth] (leaving) -- ++(0,-1cm) node[label={[xshift=8pt,yshift=-20pt]leaving}] {};
}
\end{document}


-
When you use \midrule vertical rules don't connect; why don't you use \hline? – egreg Jun 4 '14 at 21:49
@egreg hline leaves no space to the delimiters [1]: i.stack.imgur.com/tz3qL.jpg – Jindan Zhou Jun 4 '14 at 21:59
Yes, that's a small problem. You solve it by using \left[\begin{array}{@{}cc|c|c|c|c@{}} and \end{array}\right] at the end. – egreg Jun 4 '14 at 22:01

In this case, array is more flexible:

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,matrix,positioning}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=3pt, anchor=base] (#1) {#2};}

\begin{document}
$$\left[ \begin{array}{@{\qquad}|c|@{\quad}|c|@{\qquad}} & 0 \\ & 0 \\ & \cdots \\ & \cdots \\ \hline a^{*}_{ts} & 1 \\ \hline & 0 \\ & \cdots \\ & \cdots \\ & \cdots \\ & 0 \\ & 0 \\ \hline \tikzmark{enter}{c^{*}_s} & \tikzmark{leaving}{c^{*}_t} \end{array} \right] = \left[\begin{array}{@{}c@{}} \\ \\ \\ \\ b^{*}_t \\ \\ \\ \\ \\ \\ \\ -v \end{array}\right]$$
\tikz[overlay,remember picture] {
\draw[<-,>=stealth] (enter) -- ++(0,-1cm) node [label={[xshift=-8pt,yshift=-20pt]entering}] {};
\draw[<-,>=stealth] (leaving) -- ++(0,-1cm) node[label={[xshift=8pt,yshift=-20pt]leaving}] {};
}
\end{document}


If you load also xcolor and colortbl, you can change the tint of the rules:

\documentclass{article}
\usepackage{mathtools,xcolor,colortbl}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,matrix,positioning}
\newcommand{\tikzmark}[2]{\tikz[overlay, remember picture] \node[inner sep=0pt, outer sep=3pt, anchor=base] (#1) {#2};}

\begin{document}
$$\arrayrulecolor{black!30} \left[ \begin{array}{@{\qquad}|c|@{\quad}|c|@{\qquad}} & 0 \\ & 0 \\ & \cdots \\ & \cdots \\ \hline a^{*}_{ts} & 1 \\ \hline & 0 \\ & \cdots \\ & \cdots \\ & \cdots \\ & 0 \\ & 0 \\ \hline \tikzmark{enter}{c^{*}_s} & \tikzmark{leaving}{c^{*}_t} \end{array} \right] = \left[\begin{array}{@{}c@{}} \\ \\ \\ \\ b^{*}_t \\ \\ \\ \\ \\ \\ \\ -v \end{array}\right] \arrayrulecolor{black}$$
\tikz[overlay,remember picture] {
\draw[<-,>=stealth] (enter) -- ++(0,-1cm) node [label={[xshift=-8pt,yshift=-20pt]entering}] {};
\draw[<-,>=stealth] (leaving) -- ++(0,-1cm) node[label={[xshift=8pt,yshift=-20pt]leaving}] {};
}
\end{document}


The color must be reestablished at the end, because \arrayrulecolor is a global declaration.

-
awesome! any way to pack the \cdots little tighter? – Jindan Zhou Jun 4 '14 at 22:28
@JindanZhou \newcommand{\pdots}{{\cdot}{\cdot}{\cdot}} – egreg Jun 4 '14 at 22:35