Block matrices in LaTeX, part one
Alec Jacobson
August 11, 2010
When I'm writing out complicated linear systems by hand I usually draw the system as block matrices. And when I say block matrices, I mean that I really draw the boxes around each part of the matrix with matching row and column dimensions. So when I draw a single matrix it is just a single box. And when I draw a partitioned (block) matrix I draw a stack of these boxes (I realize "block matrix" technically refers to these partitioned matrices and not drawing them as blocks). This helps me see the matrix multiplication in my head and keep track of whether the system is determined, underdetermined, or over determined. Here's an example of my hand drawn block matrices in action:
I looked around and found that most packages print block matrices like this, with at most vertical or horizontal lines (not boxes) sectioning off entries in an array:
So I fiddled around with LaTeX box commands and came up with a first attempt to create the sort of boxed, block matrices that I use in my notes. Here're the commands that I define:
\newcommand{\blockmatrix}[3]{%These end of the line comments are neccessary
\begin{minipage}[t][#2][c]{#1}%
\center%
#3%
\end{minipage}%
}%
\newcommand{\fblockmatrix}[3]{%
\fbox{%
\begin{minipage}[t][#2][c]{#1}%
\center%
#3%
\end{minipage}%
}%
}
Note: The end of line comments are necessary to prevent fbox from adding spurious spacing.
And here's a document using the commands:
\documentclass[letterpaper,11pt]{article}
\newcommand{\blockmatrix}[3]{%These end of the line comments are neccessary
\begin{minipage}[t][#2][c]{#1}%
\center%
#3%
\end{minipage}%
}%
\newcommand{\fblockmatrix}[3]{%
\fbox{%
\begin{minipage}[t][#2][c]{#1}%
\center%
#3%
\end{minipage}%
}%
}
\begin{document}
\fblockmatrix{0.5in}{0.5in}{A} \fblockmatrix{0.1in}{0.5in}{x}
\blockmatrix{0.1in}{0.5in}{=} \fblockmatrix{0.1in}{0.5in}{b}
\\
\\
\fblockmatrix{0.5in}{0.3in}{A} \fblockmatrix{0.1in}{0.5in}{x}
\blockmatrix{0.1in}{0.5in}{=} \fblockmatrix{0.1in}{0.3in}{b}
\\
\\
\fblockmatrix{0.5in}{0.3in}{L}
\fblockmatrix{0.5in}{0.5in}{M}
\fblockmatrix{0.3in}{0.5in}{L}
\fblockmatrix{0.1in}{0.3in}{x}
\blockmatrix{0.25in}{0.3in}{=}
\fblockmatrix{0.1in}{0.3in}{b}
\\
\\
\fblockmatrix{0.6in}{0.4in}{L}
\fblockmatrix{0.6in}{0.6in}{M}
\fblockmatrix{0.4in}{0.6in}{L}
\fblockmatrix{0.1in}{0.4in}{x}
\blockmatrix{0.1in}{0.3in}{=}
\fblockmatrix{0.6in}{0.4in}{L}
\fblockmatrix{0.6in}{0.6in}{M}
\fblockmatrix{0.2in}{0.6in}{L}
\fblockmatrix{0.1in}{0.2in}{b}
\\
\\
\fblockmatrix{0.525in}{0.375in}{$L$}
\fblockmatrix{0.525in}{0.525in}{$M$}
\fblockmatrix{0.375in}{0.525in}{$L$}
\fblockmatrix{0.1in}{0.375in}{$x$}
\blockmatrix{0.1in}{0.275in} {$=$}
\fblockmatrix{0.525in}{0.375in}{$L$}
\fblockmatrix{0.525in}{0.525in}{$M$}
\blockmatrix{0.1in}{0.375in}{\Huge{ $($}}
\fblockmatrix{0.175in}{0.525in}{$L$}
\fblockmatrix{0.1in}{0.175in}{$b$}
\blockmatrix{0.1in}{0.4in}{$+$}
\fblockmatrix{0.1in}{0.525in}{$b_n$}
\blockmatrix{0.1in}{0.375in}{\Huge{ $)$}}
\\
\\
\begin{tabular}{llll}
\fblockmatrix{0.5in}{0.5in}{A}&
\fblockmatrix{0.1in}{0.5in}{x}&
\blockmatrix{0.1in}{0.5in}{=}&
\fblockmatrix{0.1in}{0.5in}{b}
\\
\fblockmatrix{0.5in}{0.25in}{G} & & &
\fblockmatrix{0.1in}{0.25in}{0}
\\
\end{tabular}
\\\\
\end{document}
Which produces this:
Admittedly there's a lot left to do. The parenthesis behavior is annoying and it's not terribly easy to stack them.