# bordermatrix with blocks

I need to write a complicated matrix, that has a structure as in the attached picture.

-

The blkarray package allows to do complex border matrix with relatively simple code:

\documentclass{article}

\usepackage{blkarray}
\usepackage{multirow}

\begin{document}

$\begin{blockarray}{cc|cccc|cccc} & 1\dots 18 & 19 & 20 & 21 & 22 & 23 & 24 & 25 & 26 \\ \begin{block}{c(c|cccc|cccc@{\hspace*{5pt}})} A'_1 & A_1 & \BAmulticolumn{4}{c|}{\multirow{4}{*}{I}}&\BAmulticolumn{4}{c}{\multirow{4}{*}{I}}\\ A'_2 & A_2 & &&&&&&&\\ A'_3 & A_3 & &&&&&&&\\ A'_4 & A_4 & &&&&&&&\\ \cline{1-10}% don't use \hline B'_1 & B_1 & \BAmulticolumn{4}{c|}{\multirow{4}{*}{J}}&\BAmulticolumn{4}{c}{\multirow{4}{*}{I}}\\ B'_2 & B_2 & &&&&&&&\\ B'_3 & B_3 & &&&&&&&\\ B'_4 & B_4 & &&&&&&&\\ \end{block} \end{blockarray}$

\end{document}

-
Great. I didn't know this package before. It seems blkarray provides better spacing. – Leo Liu Feb 3 '11 at 9:39
Thank you very much. – user3307 Feb 4 '11 at 4:40
\documentclass{article}
\usepackage{blkarray}
\def\Big#1{\makebox(0,0){\huge#1}}

\begin{document}

$\begin{blockarray}{cc|c|c} & 1\ldots18&19\,20\,21\,22&23\,24\,25\,26\\ \begin{block}{c(c|c|c)} A_1^\prime & A_1 & & \\ A_2^\prime & A_2 & \Big{I}& \Big{I}\\ A_3^\prime & A_3 & & \\ A_4^\prime & A_4 & & \\\cline{1-4} B_1^\prime & B_1 & & \\ B_2^\prime & B_2 &\Big{J} & \Big{I}\\ B_3^\prime & B_3 & & \\ B_4^\prime & B_4 & & \\ \end{block} \end{blockarray}$
\end{document}


-
Is there a particular reason why you write ^\prime and not simply '? The latter expands to the former and is much clearer. – Hendrik Vogt Feb 3 '11 at 11:55
@Hendrik: you are right in this case it makes no sense. I did it by default. HOwever, cannot remember where I had to use instead of the accent – Herbert Feb 3 '11 at 12:52
This should be added to your mathmode.pdf. – kiss my armpit Nov 5 '12 at 16:28

Thanks to everyone. I managed to find solution myself as well. I have used package kbordermatrix. However very often math journals want to typeset the tex file themselves and they don't have all the packages. I'm sure that at least one variant will work. So thank again:) My solution is below:

\documentclass{article}
\usepackage{kbordermatrix}
\begin{document}

$$\kbordermatrix{ & 1 \ldots 18 & \vrule & 19 \text{ } 20 \text{ } 21 \text{ } 22 & \vrule & 23 \text{ } 24 \text{ } 25 \text{ } 26 \\ \begin{array}{c} \chi(A'_1) \\ \chi(A'_2) \\ \chi(A'_3) \\ \chi(A'_4) \end{array} & \begin{array}{c} \chi(A_1) \\ \chi(A_2) \\ \chi(A_3) \\ \chi(A_4) \end{array} & \vrule & I & \vrule& I \\ \hline \begin{array}{c} \chi(B'_1) \\ \chi(B'_2) \\ \chi(B'_3) \\ \chi(B'_4) \end{array} & \begin{array}{c} \chi(B_1) \\ \chi(B_2) \\ \chi(B_3) \\ \chi(B_4) \end{array} & \vrule & J & \vrule& I } ,$$
\end{document}


-
You should have enough rep now, so I edited in the picture. – Caramdir Feb 4 '11 at 5:06
I've tried to improve the formatting of your code a bit. Hope that's OK. – Hendrik Vogt Feb 4 '11 at 10:06
Thank you for editing my post – user3307 Feb 5 '11 at 0:26
Of course if you absolutely need a package as well as a self-contained .tex file, you can always just copy and paste the .sty file content in your main .tex file. Minus the \ProvidesPackage stuff of course. – Christian Jun 3 '12 at 21:34

Plain-kru represenz:

\font\Large=cmr10 at 20pt
\newcount\rowcount\rowcount=3
\def\fudge#1{\smash{\hbox{\Large#1}}}
\def\doublyso{\kern-.5em\smash{\vrule height \rowcount em depth .2em}\hidewidth}
\bordermatrix{ \global\everycr{\noalign{\global\advance\rowcount by 1}} &1\ldots18&19\;20\;21\;22&23\;24\;25\;26 \cr A_1'&A_1\cr A_2'&A_2\cr A_3'&A_3&\fudge I&\fudge I\cr A_4'&A_4\cr \noalign{\smallskip\hrule\smallskip} B_1'&B_1\cr B_2'&B_2\cr B_3'&B_3&\fudge J&\fudge I\cr B_4'&B_4&\doublyso&\doublyso\cr }
\everycr={}
\bye


In my "imitation of \atopwithdelims-line of thought"-spree, I made one for \bordermatrix as well (which is the Plain \bordermatrix with only the delims made as arguments):

\catcode@=11
\def\bordermatrixwithdelims#1#2#3{\begingroup \m@th
\setbox0=\vbox{\def\cr{\crcr\noalign{\kern2pt\global\let\cr=\endline}}
\ialign{$##$\hfil\kern2pt\kern\p@renwd&\thinspace\hfil$##$\hfil
&&\quad\hfil$##$\hfil\crcr
\omit\strut\hfil\crcr\noalign{\kern-\baselineskip}
#3\crcr\omit\strut\cr}}
\setbox2=\vbox{\unvcopy0 \global\setbox1=\lastbox}
\setbox2=\hbox{\unhbox1 \unskip \global\setbox1=\lastbox}
\setbox2=\hbox{$\kern\wd1\kern-\p@renwd \left#1 \kern-\wd1 \global\setbox1=\vbox{\box1\kern2pt} \vcenter{\kern-\ht1 \unvbox0 \kern-\baselineskip} \,\right#2$}
\null\;\vbox{\kern\ht1\box2}\endgroup}
\catcode@=12
%
\def\cbordermatrix#1{\bordermatrixwithdelims[]{#1}}
\def\bbordermatrix#1{\bordermatrixwithdelims\{\}{#1}}
\def\vbordermatrix#1{\bordermatrixwithdelims||{#1}}
%
$$\bordermatrix{&[a]&[b]\cr &1&2\cr&3&4} \cbordermatrix{&[a]&[b]\cr &1&2\cr&3&4} \bbordermatrix{&[a]&[b]\cr &1&2\cr&3&4} \vbordermatrix{&[a]&[b]\cr &1&2\cr&3&4}$$
\bye


So to achieve the look of which the OP settled on, one could just substitute the call to \bordermatrix in my original answer with \cbordermatrix

-

You can use multirow and bigdelim package for this matrix. Example:

\documentclass{article}
\usepackage{multirow,bigdelim}
\begin{document}
$\begin{array}{ccc|cc|ccc} && x & a & b & c & d \\ A &\ldelim({4}{0.5em}& x & \multicolumn{2}{c|}{\multirow{2}*{ab}} & \multicolumn{2}{c}{\multirow{2}*{cd}} & \rdelim){4}{0.5em} \\ B && y &&&& \\ \hline C && x & \multicolumn{2}{c|}{\multirow{2}*{ab}} & \multicolumn{2}{c}{\multirow{2}*{cd}} \\ D && y &&&& \\ \end{array}$
\end{document}


-