5

Section 5.4, "Invariant Subspaces and the Cayley–Hamilton Theorem", of Friedberg, Insel, and Spence's Linear Algebra represents the direct sum of matrices like so:

image showing the direct sum of matrices, with lines surrounding the original matrices

I'm interested in recreating the weird crossing lines thing, preferably with the standard amsmath matrix environments.

New contributor
pigrammer is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3

4 Answers 4

7

I'm interested in recreating the weird crossing lines thing, preferably with the standard amsmath matrix environments.

For the matrix at hand, a basic array environment generates a better outcome than a pmatrix environment does. By "better", I mean that the horizontal lines do not touch the tall round parentheses when using an array environment.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for 'pmatrix' env.
\newcommand\mc[1]{\multicolumn{1}{c|}{#1}} % handy shortcut macro

\begin{document}
\[
B_1 \oplus B_2 \oplus B_3 =
\left(\begin{array}{ *{6}{c} }
1 & \mc{2} & 0 & 0 & 0 & 0 \\
1 & \mc{1} & 0 & 0 & 0 & 0 \\
\cline{1-3}
0 & \mc{0} & \mc{3} & 0 & 0 & 0 \\
\cline{3-6}
0 & 0 & \mc{0} & 1 & 2 & 1 \\
0 & 0 & \mc{0} & 1 & 2 & 3 \\
0 & 0 & \mc{0} & 1 & 1 & 1 
\end{array}\right)
\qquad
\begin{pmatrix}
1 & \mc{2} & 0 & 0 & 0 & 0 \\
1 & \mc{1} & 0 & 0 & 0 & 0 \\
\cline{1-3}
0 & \mc{0} & \mc{3} & 0 & 0 & 0 \\
\cline{3-6}
0 & 0 & \mc{0} & 1 & 2 & 1 \\
0 & 0 & \mc{0} & 1 & 2 & 3 \\
0 & 0 & \mc{0} & 1 & 1 & 1 
\end{pmatrix}
\]

\end{document} 
5

I know you asked for standard matrix environments, but I suggest nicematrix.

enter image description here

If you want additional space for the delimiters (so the lines don't touch them) you can include [extra-margin=3pt] in the following code:

\documentclass{article}

\usepackage{nicematrix, tikz}

\begin{document}

\[
B_1\oplus B_2\oplus B_3=
\begin{pNiceMatrix}%[extra-margin=3pt]
\CodeBefore
    \tikz \draw(1-|3) |- (4-|last) (3-|1) -| (last-|4);
\Body
1&2&0&0&0&0\\
1&1&0&0&0&0\\
0&0&3&0&0&0\\
0&0&0&1&2&1\\
0&0&0&1&2&3\\
0&0&0&1&1&1
\end{pNiceMatrix}.
\]

\end{document}

To clarify the (i-|j) notation: If tikz is loaded (note that nicematrix does not automatically load tikz) then (i-|j) is the intersection of the ith horizontal rule with the jth vertical rule (whether or not the rules are actually drawn). The 1st horizontal rule is above row 1; the 1st vertical rule is left of column 1. There is also position i.5 which is halfway between i and i+1 (useful for striking out rows or columns). The last position has the alias last.

These positions can be accessed using CodeBefore or CodeAfter (see the excellent nicematrix manual for details) just as one would use a node in TikZ. So in the CodeBefore, a tikzpicture can, for example, include \draw (1-|2) -- (3-|4); for a diagonal line, or \draw (1-|2) -| (3-|4); to draw horizontally then vertically.

3
  • 1
    Thanks for the answer; for this part: \draw(1-|3)|-(4-|7)(3-|1)-|(7-|4) what do those numbers mean? That is, if I wanted to modify this to make the lines in different places, say I was using different matrices, what would I have to change the numbers to?
    – pigrammer
    Commented yesterday
  • 2
    (r-|c) is the row/column coordinate. Coordinate (1-|1) is left of the first column and above the first row. You can also use half-integers so (1.5-|2.5) would be in the center of the 1,2-entry of the matrix (for example if you wanted to cross out a row or column). The |- and -| notation between coordinates is from TikZ: draw vertically then horizontally (or vice versa) to the next coordinate.
    – Sandy G
    Commented yesterday
  • @SandyG as comments might disappear, I urge you to edit this helpful addendum into your post :) Commented yesterday
4

It is possible with just the amsmath package, but the syntax is a bit convoluted and the lines are not nicely connected at the corners, therefore I am unsure whether I should recommend this:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
B_{1} \oplus B_{2} \oplus B_{3} =
\left(
\begin{array}{*6{c}}
1 & 2 & \multicolumn{1}{|c}{0}  & 0 & 0 & 0 \\
1 & 1 & \multicolumn{1}{|c}{0}  & 0 & 0 & 0 \\ \cline{1-3}
0 & 0 & \multicolumn{1}{|c|}{3} & 0 & 0 & 0 \\ \cline{3-6}
0 & 0 & \multicolumn{1}{c|}{0}  & 1 & 2 & 1 \\
0 & 0 & \multicolumn{1}{c|}{0}  & 1 & 2 & 3 \\
0 & 0 & \multicolumn{1}{c|}{0}  & 1 & 1 & 1 \\
\end{array}
\right)
\]

\end{document}

output of above code

2

You can do it with array and a couple of fixes.

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}

\begin{document}
\[
% local command to ease input
\newcommand{\K}[1]{\multicolumn{1}{c|}{#1}}%
\newcommand{\B}{\vrule width 0pt height \dimeval{\ht\strutbox+0.5\dp\strutbox}}%
\addtolength{\arraycolsep}{-1pt}
B_1\oplus B_2\oplus B_3=
\left(\,
\begin{array}{@{}*{6}{c}@{}}
1 & \K{2} & 0     & 0 & 0 & 0 \\
1 & \K{1} & 0     & 0 & 0 & 0 \B \\
\cline{1-3}
0 & \K{0} & \K{3} & 0 & 0 & 0 \B \\
\cline{3-6}
0 & 0     & \K{0} & 1 & 2 & 1 \B \\
0 & 0     & \K{0} & 1 & 2 & 3 \B \\
0 & 0     & \K{0} & 1 & 1 & 1 \B
\end{array}
\,\right)
\]

\end{document}

The center cell seems more “square”.

output

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.