2

I would like to draw this matrix using LaTeX. I've seen solutions using the array environment, but, as you can notice from the picture, the lines don't go all the way through, so some of them aren't functioning answers.

Perhaps using TikZ?

Thank you all.

Jordan Canonical form

2 Answers 2

4

With judicious use of \multicolumn:

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

\begin{document}

\[
\newcommand{\?}[1]{\multicolumn{1}{c|}{#1}}
\left(\begin{array}{ccccccc}
2 & 1 & \?0 & 0 &   0 & 0 & 0 \\
0 & 2 & \?1 & 0 &   0 & 0 & 0 \\
0 & 0 & \?2 & 0 &   0 & 0 & 0 \\
\cline{1-5}
0 & 0 & \?0 & 2 & \?1 & 0 & 0 \\
0 & 0 & \?0 & 0 & \?2 & 0 & 0 \\
\cline{4-6}
0 & 0 &   0 & 0 & \?0 & \?3 & 0 \\
\cline{6-7}
0 & 0 &   0 & 0 &   0 & \?0 & 3
\end{array}\right)
\]

\end{document}

The \? command is locally defined just to ease input (and reading).

enter image description here

With full borders (\| is locally redefined, again for ease of input).

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

\begin{document}

\[
\newcommand{\?}[1]{\multicolumn{1}{c|}{#1}}
\renewcommand{\|}[1]{\multicolumn{1}{|c}{#1}}
\left(\,\begin{array}{ccccccc}
\cline{1-3}
\|2 & 1 & \?0 & 0 & 0 & 0 & 0 \\
\|0 & 2 & \?1 & 0 & 0 & 0 & 0 \\
\|0 & 0 & \?2 & 0 & 0 & 0 & 0 \\
\cline{1-5}
0 & 0 & \?0 & 2 & \?1 & 0 & 0 \\
0 & 0 & \?0 & 0 & \?2 & 0 & 0 \\
\cline{4-6}
0 & 0 &   0 & 0 & \?0 & \?3 & 0 \\
\cline{6-7}
0 & 0 &   0 & 0 &   0 & \?0 & \?3 \\
\cline{7-7}
\end{array}\,\right)
\]

\end{document}

enter image description here

Possibly more appealing:

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

\begin{document}

\[
\settowidth{\dimen0}{$0$}
\settoheight{\dimen2}{$0$}
\setlength{\arraycolsep}{4pt}
\newcolumntype{C}{%
  >{\vrule width 0pt height \dimexpr\dimen2+\arraycolsep\relax depth \arraycolsep}
  w{c}{\dimen0}
}
\renewcommand{\arraystretch}{0}
\newcommand{\?}[1]{\multicolumn{1}{c|}{#1}}
\renewcommand{\|}[1]{\multicolumn{1}{|c}{#1}}
\left(\,\begin{array}{CCCCCCC}
\cline{1-3}
\|2 & 1 & \?0 & 0 & 0 & 0 & 0 \\
\|0 & 2 & \?1 & 0 & 0 & 0 & 0 \\
\|0 & 0 & \?2 & 0 & 0 & 0 & 0 \\
\cline{1-5}
0 & 0 & \?0 & 2 & \?1 & 0 & 0 \\
0 & 0 & \?0 & 0 & \?2 & 0 & 0 \\
\cline{4-6}
0 & 0 &   0 & 0 & \?0 & \?3 & 0 \\
\cline{6-7}
0 & 0 &   0 & 0 &   0 & \?0 & \?3 \\
\cline{7-7}
\end{array}\,\right)
\]

\end{document}

enter image description here

4

Here is an option using nicematrix

enter image description here

If you want to change the style of the lines, you can add \usepackage{tikz} and then you can add any TikZ options to the borders options, e.g., tikz={dashed,red}

\documentclass{article}

\usepackage{nicematrix}

\begin{document}
\[
\begin{pNiceMatrix}
\Block[borders={bottom,right}]{3-3}{}
2 & 1 & 0 & 0 & 0 & 0 & 0\\
0 & 2 & 1 & 0 & 0 & 0 & 0\\
0 & 0 & 2 & 0 & 0 & 0 & 0\\
0 & 0 & 0 & \Block[borders={bottom,right,top,left}]{2-2}{} 2 & 1 & 0 & 0\\
0 & 0 & 0 & 0 & 2 & 0 & 0\\
0 & 0 & 0 & 0 & 0 & \Block[borders={bottom,right,top,left}]{1-1}{} 3 & 0\\
0 & 0 & 0 & 0 & 0 & 0 & \Block[borders={top,left}]{1-1}{}3\\
\end{pNiceMatrix}
\]
\end{document}
1
  • Instead of \Block[borders={bottom,right,top,left}], it's also possible to write \Block[draw] :-) Sep 11, 2023 at 12:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .