答案1
为了好玩:这很容易pstricks
:
\documentclass[11pt,x11names]{standalone}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}
\usepackage{amsmath}
\usepackage{sansmath}
\begin{document}
\mathversion{sans}\setlength\fboxsep{0pt}
\begin{postscript}
$\begin{pmatrix}
0 & 0 & 0 & 0 & \dots & 0 \\ 0 & \pnode[0,1.5ex]{A} & & &\pnode[0,1.5ex]{Dh} \\0\\0\\\vdots &\pnode{Dv} \\0 & & & & & \pnode{B}
\end{pmatrix}$
\psset{arrowinset=0, linewidth=1.5pt, linearc=0.2pt, nodesep = 6pt,, arrows =c- }
\psline{<->}(A)(B)
\psset{linecolor=RoyalBlue2, fillcolor=RoyalBlue1!15!, arrows =c-}
\ncangle[angleB=90, linestyle = none, fillstyle=solid,]{A}{B}
\ncline[nodesepB=9.5pt]{A}{Dh}
\ncangle[angleA=90, nodesepB=7.5pt]{B}{Dh}
\rput(Dh){\color{RoyalBlue2}\dots}
\psset{angleA=-90, angleB=180, linecolor=Red1!60!, fillcolor=Red1!10!, arrows =-c}
\ncangle[linestyle=none, fillstyle=solid]{A}{B}
\ncangle[nodesepA=3pt,]{Dv}{B}
\ncline[nodesepA=12pt]{Dv}{A}
\rput[B](Dv){\color{Red1!60!}\vdots}
\end{postscript}
\end{document}
答案2
使用 TikZ 可以轻松:
\documentclass[border=3mm,
tikz,
prewiev]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of math nodes,
left delimiter=(,
right delimiter=),
nodes in empty cells] (m)
{
0 & 0 & 0 & 0 & \dots & 0 \\
0 & \vphantom{0}
& & & & \\
0 & & & & & \\
0 & & & & & \\
\vdots & & & & & \\
0 & & & & & \\
};
\fill[blue!30] (m-2-2.north west) -| (m-6-6.south east);
\fill[ red!30] (m-2-2.north west) |- (m-6-6.south east);
\draw[line width=3mm,white] (m-2-2.north west) -- (m-6-6.south east);
\draw[thick,stealth-stealth] (m-2-2.north west) -- (m-6-6.south east);
\end{tikzpicture}
\end{document}
编辑:
Gonzalo Medina 提醒我忘记了dots
,对此深表歉意。现在我将它们添加到第一行和第一列,并使用白色背景线来显示对角线。
编辑(2):
如果您用或其他适当的环境括起来或放入矩阵,矩阵将在文本中居中,\begin{center} ... \end{center}
例如 \begin{figure}\centering\begin{tikzpicture} ... \end{tikzpicture}\end{figure} 等。
对于圆形阴影填充,您需要添加选项rounded corners
。请参阅下面的新 MWE。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage[active,tightpage]{preview}% just for show only picture
\PreviewEnvironment{center}%
\setlength\PreviewBorder{1em}
\begin{document}
\begin{center}
\begin{tikzpicture}
\matrix[matrix of math nodes,
left delimiter=(,
right delimiter=),
nodes in empty cells] (m)
{
0 & 0 & 0 & 0 & \dots & 0 \\
0 & \vphantom{0}
& & & & \\
0 & & & & & \\
0 & & & & & \\
\vdots & & & & & \\
0 & & & & & \\
};
\fill[rounded corners,blue!30] (m-2-2.north west) -| (m-6-6.south east);
\fill[rounded corners, red!30] (m-2-2.north west) |- (m-6-6.south east);
\draw[line width=3mm,white] (m-2-2.north west) -- (m-6-6.south east);
\draw[thick,stealth-stealth] (m-2-2.north west) -- (m-6-6.south east);
\end{tikzpicture}
\end{center}
\end{document}