Drawing the following two matrices
Here is a proposal using the nicematrix
package. Unfortunately, as far as I could see, their nice dotted lines are not in some styles that can be used by the user for their own annotations, so I had to redo it using a variant of this answer.
\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\usepackage{nicematrix}
\tikzset{Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
line width=1pt,
dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
shorten >=0.3em,shorten <=0.3em},
Dotted/.default=5}
\begin{document}
\[A=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (2-2) -- (3-3);
\end{tikzpicture}}]%
I &0 &\Cdots &0\\
0 & I &\Ddots &\Vdots\\
\Vdots &\Ddots &I &0\\
0 &\Cdots &0 &I
\end{pNiceArray}
\]
and
\[B=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (3-2) -- (2-3);
\draw[Dotted] (3-1) -- (1-3);
\draw[Dotted] (4-2) -- (2-4);
\end{tikzpicture}}]%
0 &\Cdots &0 &I\\
\Vdots & &I &0\\
0 &I & &\Vdots\\
I &0 &\Cdots &0
\end{pNiceArray}
\]
\end{document}
Or a version with parallel dotted lines.
\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\usepackage{nicematrix}
\tikzset{Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
line width=1pt,
dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
shorten >=0.3em,shorten <=0.3em},
Dotted/.default=5}
\begin{document}
\[A=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (2-2) -- (3-3);
\end{tikzpicture}}]%
I &0 &\Cdots &0\\
0 & I &\Ddots &\Vdots\\
\Vdots &\Ddots &I &0\\
0 &\Cdots &0 &I
\end{pNiceArray}
\]
and
\[B=
\begin{pNiceArray}{CCCC}[
code-after = {\begin{tikzpicture}
%
\draw[Dotted] (3-2.30) -- (2-3.-150);
\draw[Dotted] (3-1) -- (1-3);
\draw[Dotted] (4-2) -- (2-4);
\end{tikzpicture}}]%
0 &\Cdots &0 &I\\
\Vdots & &I &0\\
0 &I & &\Vdots\\
I &0 &\Cdots &0
\end{pNiceArray}
\]
\end{document}
Or without nicematrix
.
\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,mathdots}
\begin{document}
\[A=
\begin{pmatrix}
I &0 &\cdots &0\\
0 & I \smash{\makebox[0pt][l]{\;\raisebox{-0.8em}{$\ddots$}}} &\ddots &\vdots\\
\vdots &\ddots &I &0\\
0 &\cdots &0 &I
\end{pmatrix}
\]
and
\[B=
\begin{pmatrix}
0 &\cdots &0 &I\\
\vdots & \iddots &I &0\\
0 &I\smash{\makebox[0pt][l]{\;\raisebox{0.8em}{$\iddots$}}} & \iddots &\vdots\\
I &0 &\cdots &0
\end{pmatrix}
\]
\end{document}
This is an adaptation of the answer of Schrödinger's cat. In fact, since a recent version of nicematrix
(3.13 2020-03-15), it's possible to draw the continuous dotted lines with any line style provided by Tikz.
Remark: Starting with this version 3.13, nicematrix
doesn't load tikz
any longer. It only loads pgf
(because, by default, this new version only uses pgf
).
\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\usepackage{nicematrix}
\usepackage{tikz}
\tikzset{Dotted/.style={% https://tex.stackexchange.com/a/52856/194703
line width=1pt,
dash pattern=on 0.01\pgflinewidth off #1\pgflinewidth,line cap=round,
shorten >=0.3em,shorten <=0.3em},
Dotted/.default=5}
\begin{document}
\begin{gather*}
A=
\begin{pNiceArray}{CCCC}[code-after={\line[line-style = Dotted]{2-2}{3-3}}]
I & 0 & \Cdots &0 \\
0 & I & \Ddots &\Vdots\\
\Vdots &\Ddots & I &0 \\
0 &\Cdots & 0 &I
\end{pNiceArray}
\\
B=
\begin{pNiceArray}{CCCC}[
code-after = {
\line[line-style = Dotted]{3-2}{2-3} }
]%
0 & \Cdots & 0 & I\\
\Vdots & \Iddots[line-style=Dotted] & I & 0\\
0 & I & \Iddots[line-style=Dotted] & \Vdots\\
I & 0 &\Cdots & 0
\end{pNiceArray}
\end{gather*}
\end{document}