\documentclass[]{article}
\usepackage{amsmath,color,hhline}

\textwidth=6.5in
\textheight=9.5in
\topmargin=-.5in
\headheight=0in
\headsep=.1in
\hoffset  -.75in

\def\dst{\displaystyle}
\def\LA{\LaTeX}
 \def\ra{\rightarrow}
\def\i{\infty}


\pagestyle{empty}

 
\begin{document}

\centerline {\large Lesson 12: Making Block Matrices in  \LaTeX     \ Name:
\rule[-1pt]{2.25in}{1pt} }
 
\vskip.25in

Putting vertical lines all the way down the columns is as easy as pie. Just   \textit{array} to make the
matrix and insert a vertical bar between the columns where you want a vertical bar. Note that this is
exactly like if you were using a tabular environment. For example


 
\begin{minipage}{3in}
\begin{verbatim}
$$
 \bigg[\begin{array}{c|c|c|c} 
A &Ab &\cdots &A^{n-1}b
\end{array}\bigg]
$$
\end{verbatim}
\end{minipage}\ \ \ \parbox{3in}{$$ \bigg[\begin{array}{c|c|c|c} 
A &Ab &\cdots &A^{n-1}b
\end{array}\bigg]
 $$}

\vskip.2in

\begin{minipage}{3in}
\begin{verbatim}
$$
 \left[\begin{array}{cccc|c} 
a_{11}&a_{12}&\cdots &a_{1n}&b_1\\
a_{21}&a_{22}&\cdots &a_{2n}&b_2\\
\vdots & &\ddots &\vdots *\vdots\\
a_{n1}&a_{n2}&\cdots &a_{nn}&b_n\\
\end{array}\right]
$$
\end{verbatim}
\end{minipage}\ \ \ \parbox{3in}{$$  \left[\begin{array}{cccc|c} 
a_{11}&a_{12}&\cdots &a_{1n}&b_1\\
a_{21}&a_{22}&\cdots &a_{2n}&b_2\\
\vdots & &\ddots &\vdots &\vdots\\
a_{n1}&a_{n2}&\cdots &a_{nn}&b_n\\
\end{array}\right]
 $$}
\vskip.2in


Putting in a horizontal   line that spans the whole matrix is no harder. In fact it is exactly the same
as it is for a tabular -- just insert an \verb+\hline+ after the \textit{double  backslash}. 

\begin{minipage}{3in}
\begin{verbatim}
$$
C=\left[
\begin{array}{cc} 
A  &\tempb \\ \hline
 C &\tempd
\end{array}\right]
$$
\end{verbatim}
\end{minipage}\ \ \ 
\parbox{3in}{$$
C=\left[
\begin{array}{c|c} 
A  &B \\ \hline
 C &D
\end{array}\right]
$$}


\vskip.2in
But suppose you only want to span a few columns. The you need to learn \verb+\cline{n-m}+ which puts a
horizontal line from column \textit{n} to \textit{m}
In this example I have also introduced the use of \textit{multicolumn} to just put a vertical bar
between two columns in one row.  This is the hardest thing. 
\vskip.2in

\begin{minipage}{3in}
\begin{verbatim}
$$
\newcommand*{\tempb}{\multicolumn{1}{|c}{B}}
P=\left[
\begin{array}{ccc} 
A &A &\tempb \\ \cline{1-2}
 C &C &D
\end{array}\right]
$$
\end{verbatim}
\end{minipage}\ \ \ 
\parbox{3in}{$$\newcommand*{\tempb}{\multicolumn{1}{|c}{B}}
P=\left[
\begin{array}{ccc} 
A &A &\tempb \\ \cline{1-2}
 C&C &D
\end{array}\right]
$$}


\vskip.2in


\begin{minipage}{3in}
\begin{verbatim} 
\renewcommand{\arraystretch}{2}
$$\newcommand*{\temp}{\multicolumn{1}{r|}{}}
A=\left[\begin{array}{cccccc} 
1 &2 &3 &\temp & 7& 6\\ \cline{1-6}
2 &4& 6&\temp &5& 4\\  
\end{array}\right]
$$
\end{verbatim}
\end{minipage}\ \ \ 
\parbox{3in}{ \renewcommand{\arraystretch}{2}
$$\newcommand*{\temp}{\multicolumn{1}{r|}{}}
A=\left[\begin{array}{cccccc} 1 &2 &3 &\temp & 7& 6\\ \cline{1-6}
2 &4& 6&\temp & 5&4\\  
\end{array}\right]
$$}
\vskip.2in

\begin{minipage}{3.75in}
\begin{verbatim}
$$\newcommand*{\temp}{\multicolumn{1}{c|}{0}}
B=\left[\begin{array}{cccccc} 
    1 &0 &\ast  & 0 &\ast   &\ast \\ \cline{1-1}
\temp & 1&\ast  & 0 &\ast   &\ast  \\ \cline{2-3}
    0 &0 &\temp & 1 &\ast   &\ast  \\ \cline{4-6}
    0 & 0&     0&  0& 0&0
\end{array}\right]
$$
\end{verbatim}
\end{minipage}\ \ \ 
\parbox{3in}{$$\newcommand*{\temp}{\multicolumn{1}{c|}{0}}
B=\left[\begin{array}{cccccc} 
    1 &0 &\ast  & 0 &\ast   &\ast \\ \cline{1-1}
\temp & 1&\ast  & 0 &\ast   &\ast  \\ \cline{2-3}
    0 &0 &\temp & 1 &\ast   &\ast  \\ \cline{4-6}
    0 & 0&     0&  0& 0&0
\end{array}\right]
$$}




%\begin{minipage}{3in}
%\begin{verbatim}
%$$\newcommand*{\tempa}{\multicolumn{1}{c|}{0}}
%\newcommand*{\tempb}{\multicolumn{1}{c|}{1}}
%\newcommand*{\tempc}{\multicolumn{1}{c|}{-1}}
%B=\left[\begin{array}{ccccc} 
%1 &2 &3 & \tempa & 7 \\ \cline{1-5}
%2 &4& 6&\tempb  & 1\\
% -1 &2& 3& \tempc &   6\\ 
%\end{array}\right]
%$$
%\end{verbatim}
%\end{minipage}\ \ \ 
%\parbox{3in}{$$\newcommand*{\tempa}{\multicolumn{1}{c|}{0}}
%\newcommand*{\tempb}{\multicolumn{1}{c|}{1}}
%\newcommand*{\tempc}{\multicolumn{1}{c|}{-1}}
%B=\left[\begin{array}{ccccc} 
%1 &2 &3 & \tempa & 7 \\ \cline{1-5}
%2 &4& 6&\tempb  & 1\\
% -1 &2& 3& \tempc &   6\\ 
%\end{array}\right]
%$$}
%

\vskip.2in

One final tool for doing this kind of block structure is the \textit{hhline} package which must be
requested in the preamble with  \verb+\usepackage{hhline}+. The manual is included with this lesson. 

\begin{minipage}{3in}
\begin{verbatim}
\setlength{\arrayrulewidth}{.5pt}
$$
G=\left[
\begin{array}{c|c} 
A  &B\\  \hhline{-|~}
 C &D \\ \hhline{~|~}
\end{array}\right]
$$
\end{verbatim}
\end{minipage}\ \ \ 
\parbox{3in}{\setlength{\arrayrulewidth}{.5pt}
$$
G=\left[
\begin{array}{c|c} 
A  &B\\  \hhline{-|~}
 C &D \\ \hhline{~|~}
\end{array}\right]
$$ }



\vskip.2in

\begin{minipage}{3in}
\begin{verbatim}
\setlength{\arrayrulewidth}{.6pt}
$$
F=\left[\begin{array}{cc}
2 & 0   \\ \cline{2-2}  %\hhline{~|-}
 \temp & \begin{array}{cc}  
A  &B\\   
 C &D \\  
\end{array}  \end{array}\right]
$$
\end{verbatim}
\end{minipage}\ \ \ 
\parbox{3in}{\setlength{\arrayrulewidth}{.6pt}
$$\newcommand*{\temp}{\multicolumn{1}{c|}{0}}
F=\left[\begin{array}{cc}
2 & 0   \\ \cline{2-2}  %\hhline{~|-}
 \temp & \begin{array}{cc}  
A  &B\\   
 C &D \\  
\end{array}  \end{array}\right]
$$}

\vskip.2in


 
 

\noindent \textbf{PROBLEM:}  
 \vskip.2in
 
\renewcommand{\arraystretch}{1.5}
 Give \LA syntax to build the matrix 
\ \ \ \ \ \ \  
$\dst \newcommand*{\temp}{\multicolumn{1}{l|}{C}}
F=\left[\begin{array}{cc}
A & B   \\ \cline{2-2}  %\hhline{~|-}
 \temp & D \end{array}\right]
$
 

 \vskip.2in
\setlength{\fboxrule}{1pt}

\setlength{\fboxsep}{1.5in}
\noindent \framebox[6.6in]{}





 

\end{document}
