# Create blocked matrix

I have created a blocked matrix as shown below:

However, I'm not happy about the following three things:

1) How can I change those two demarcation lines (one with vertical bars and the other with dashed line) to two whole lines?

2) "G1" at the top is not well centered relative to the left portion of the matrix. "G1" and "G2" on the left side are not vertically centered relative to the upper and lower portion of the matrix, respectively.

3) The "R=" part on the left is not vertically centered.

Here is the code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{blkarray}
\begin{document}
\begin{minipage}{\textwidth}{
$\boldsymbol{R} = \begin{blockarray}{ccccccccccc} & & & & G1 & & | & & G2 & \\ & & S_1 & S_2 & ... & S_{n_1} & | & S_{n_1+1} & S_{n_1+2} & ... & S_n \\ \begin{block}{cc(ccccccccc)} &S_1 & {1} & r_{12} & ... & r_{1n_1} &| & r_{1(n_1+1)} & r_{1(n_1+2)} & ... & r_{1n} \\ G1&S_2 & r_{12} & 1 &...& r_{2n_1} & | & r_{2(n_1+1)} & r_{2(n_1+2)} & ... & r_{2n} \\ &\vdots & \vdots & \vdots &\vdots & \vdots & | &\vdots & \vdots & \vdots &\vdots \\ &S_{n_1} & r_{1n_1} & r_{2n_1} & ... & 1 & | & r_{n_1(n_1+1)} & r_{n_2(n_1+2)}& ... & r_{n_1n} \\ -&-& - & - & - & - & - & - & - & - & -\\ &S_{n1+1} & r_{1(n_1+1)} & r_{2(n_1+1)} & ... & r_{n_1(n_1+1)} & | & r_{(n_1+1)(n_1+1)} & r_{(n_1+1)(n_1+2)} & ... & r_{(n_1+1) n} \\ &S_{n1+2} & r_{1(n_1+2)} & r_{2(n+1+2)} & ... & r_{(n_1+2)(n_1+1)} & | & r_{(n_1+1)(n_1+2)} & r_{(n_1+2)(n_1+2)} & ... & r_{(n_1+2) n} \\ G2 &\vdots & \vdots & \vdots &\vdots & \vdots & | & \vdots &\vdots & \vdots & \vdots \\ &S_n & r_{1n} & r_{2n} &...& r_{n_1 n} & | & r_{(n_1+1)n} & r_{(n_1+2)n} & ... & r_{nn} \\ \end{block} \end{blockarray}$
}
\end{minipage}
\end{document}

• Have a look on this one. – MYaseen208 Dec 31 '15 at 16:51
• @MYaseen208 Thanks! That's almost what I'm looking for except: How can I attach the "R=" part vertically centered at the left side? – bluepole Dec 31 '15 at 17:01
• Here is another link for you. – MYaseen208 Dec 31 '15 at 17:10

Here is a solution with pst-node and some minor adjustments:

\documentclass{article}
\usepackage{amsmath}
\setlength\tabcolsep{4pt}
\usepackage{blkarray}
\usepackage{geometry}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\begin{document}

\noindent\begin{minipage}{\textwidth}{%
\begin{postscript}
$%\boldsymbol{R} = \begin{blockarray}{cc*{5}{c}!{\pnode{V1}}*{4}{c}} & & & \BAmulticolumn{4}{c}{G1} & \BAmulticolumn{4}{c}{G2}\\ & & & S_1 & S_2 & ... & S_{n_1} & S_{n_1+1} & S_{n_1+2} & ... & S_n \\ \begin{block}{c@{\hskip1.5em}c@{}c(*{8}{c})} \BAmultirow{1em}{$\boldsymbol{R} = $} & &S_1 & {1} & r_{12} & ... & r_{1n_1} & r_{1(n_1+1)} & r_{1(n_1+2)} & ... & r_{1n} \\ & &S_2 & r_{12} & 1 & ...& r_{2n_1} & r_{2(n_1+1)} & r_{2(n_1+2)} & ... & r_{2n} \\ & \raisebox{1ex}{$ G1 $}&\vdots & \vdots & \vdots &\vdots & \vdots &\vdots & \vdots & \vdots &\vdots \\ & &S_{n_1} & r_{1n_1} & r_{2n_1} & ... & 1 & r_{n_1(n_1+1)} & r_{n_2(n_1+2)}& ... & r_{n_1n} \\ & & & \pnode{H1}& & & & & & & \pnode{H2} \\ & &S_{n1+1} & r_{1(n_1+1)} & r_{2(n_1+1)} & ... & r_{n_1(n_1+1)} & r_{(n_1+1)(n_1+1)} & r_{(n_1+1)(n_1+2)} & ... & r_{(n_1+1) n} \\ & &S_{n1+2} & r_{1(n_1+2)} & r_{2(n+1+2)} & ... & r_{(n_1+2)(n_1+1)} & r_{(n_1+1)(n_1+2)} & r_{(n_1+2)(n_1+2)} & ... & r_{(n_1+2) n} \\ & \raisebox{1ex}{$ G2 $} &\vdots & \vdots & \vdots &\vdots & \vdots & \vdots &\vdots & \vdots & \vdots \\ & &S_n & r_{1n} & r_{2n} &...& r_{n_1 n} & r_{(n_1+1)n} & r_{(n_1+2)n} & ... & r_{nn} \\ \end{block} \begin{block}{c*{6}{c}!{\pnode{V2}}*{4}{c}} & & & & & & & & & \\ \end{block} \end{blockarray}$
\psset{linewidth=0.5pt, nodesepA=1ex, nodesepB=1.5ex, linestyle=dashed}
\ncline{V1}{V2}
\ncline[nodesep=-1.25em]{H1}{H2}
\end{postscript}
}
\end{minipage}

\end{document}


The output of this is still quite ugly, but it's better than what you had before.

You should use tikzmatrix instead as MYaseen208 suggested, so you can get a nicer result for the matrix. Then you can either use \lower8pt\hbox{$R=$} or the whatever is the appropriate vertical adjustment, or probably better would be \node at (appropriate coordinate) {$R=$};

\documentclass{article}
\usepackage{amsmath}
\usepackage{blkarray}
\usepackage[margin=0.5in]{geometry}
\begin{document}
\begin{minipage}{\textwidth}{
$\lower8pt\hbox{$\boldsymbol{R} =$}\;\; \begin{blockarray}{cccccc|cccc} & & & & G1 & & G2 & \\ & & S_1 & S_2 & \cdots & S_{n_1} & S_{n_1+1} & S_{n_1+2} & \cdots & S_n \\ \begin{block}{cc(cccc|cccc)} &S_1 & {1} & r_{12} & \cdots & r_{1n_1} & r_{1(n_1+1)} & r_{1(n_1+2)} & \cdots & r_{1n} \\ G1&S_2 & r_{12} & 1 &\cdots& r_{2n_1} & r_{2(n_1+1)} & r_{2(n_1+2)} & \cdots & r_{2n} \\ &\vdots & \vdots & \vdots &\ddots & \vdots & \vdots & \vdots & \ddots &\vdots \\ &S_{n_1} & r_{1n_1} & r_{2n_1} & \cdots & 1 & r_{n_1(n_1+1)} & r_{n_2(n_1+2)}& \cdots & r_{n_1n} \\[2pt]\BAhline &S_{n_1+1} & r_{1(n_1+1)} & r_{2(n_1+1)} & \cdots & r_{n_1(n_1+1)} & r_{(n_1+1)(n_1+1)} & r_{(n_1+1)(n_1+2)} & \cdots & r_{(n_1+1) n} \\ &S_{n_1+2} & r_{1(n_1+2)} & r_{2(n+1+2)} & \cdots & r_{(n_1+2)(n_1+1)} & r_{(n_1+1)(n_1+2)} & r_{(n_1+2)(n_1+2)} & \cdots & r_{(n_1+2) n} \\ G2 &\vdots & \vdots & \vdots &\ddots & \vdots & \vdots &\vdots & \ddots & \vdots \\ &S_n & r_{1n} & r_{2n} &\cdots& r_{n_1 n} & r_{(n_1+1)n} & r_{(n_1+2)n} & \cdots & r_{nn} \\ \end{block} \end{blockarray}$
}
\end{minipage}
\end{document}

• Thanks for the help!. Yes, I decided to use the strategy in the first link MYaseen208 provided. – bluepole Dec 31 '15 at 22:20