绘制以下两个矩阵

绘制以下两个矩阵
\documentclass[12pt,a4paper]{article}
%------------------------------------------------------------
\usepackage{amsmath,amssymb,amsthm}
\begin{document}
\[A=
\begin{pmatrix}
I       &0 &\ldots  &0\\
0 & I      &\ddots  &\vdots\\
\vdots  &\ddots  &I       &0\\
0 &\ldots  &0 &I
\end{pmatrix}
\]

and 
\[
B=\begin{pmatrix}
0 &\cdots &0& I\\
\vdots &0&I&0\\
\vdots & \vdots &  & \vdots\\
I & 0 &\cdots& 0\\
\end{pmatrix}
\]
\end{document}

我想用这种方式绘制以下两个矩阵。

在此处输入图片描述

答案1

这是使用该包的提案nicematrix。不幸的是,据我所知,它们漂亮的虚线不是某些可供用户用于自己的注释的样式,所以我不得不使用这个答案

\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}

在此处输入图片描述

或者带有平行虚线的版本。

\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}

或者没有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}

在此处输入图片描述

答案2

这是对薛定谔猫答案的改编。实际上,从最新版本nicematrix(3.13 2020-03-15) 开始,可以使用 Tikz 提供的任何线条样式绘制连续虚线。

评论:从此版本 3.13 开始,nicematrix不再加载tikz。它只会加载pgf(因为默认情况下,此新版本仅使用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}

上述代码的结果

相关内容