我将进行绘图工作。这是一个矩阵,它将强调一些元素,如下所示
我知道 pgf 的节点matrix
可以轻松地为元素添加框架,但如何添加箭头?
答案1
所有TiKZ
解决方案都很简单,只需matrix of math nodes
:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (A) [matrix of math nodes, right delimiter = ), left delimiter =(] {
0 & & & & \\
a_1 & \ddots & & & \\
\vdots & & \ddots & & \\
a_2 & & & \ddots & \\
\vdots & b_1 & \ddots & & \\
\vdots & \vdots & & & \\
\vdots & b_2 & & & \\
\vdots & \vdots & c_1 & & \\
\vdots & \vdots & \vdots & & \\
\vdots & \vdots & c_2 & & \\
\vdots & \vdots & \vdots & & 0 \\
};
\draw[red] (A-2-1.north west) rectangle (A-4-1.south east);
\draw[red] (A-5-2.north west) rectangle (A-7-2.south east);
\draw[red] (A-8-3.north west) rectangle (A-10-3.south east);
\draw[->,blue] (A-4-1.south) --++(-90:1mm) -| (A-5-2.north);
\draw[->,blue] (A-7-2.south) --++(-90:1mm) -| (A-8-3.north);
\end{tikzpicture}
\end{document}
答案2
添加一些样式并使用matrix
可以PGF
实现以下效果:
代码:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[
block/.style={text height=0.5em
, minimum width=1em,
, outer sep=0pt}]
\matrix [matrix of math nodes
, left delimiter={(},right delimiter={)}
, nodes in empty cells
, nodes=block
, row sep=1em
, column sep=1em] at (0,0)
{
0 & & & & & & & & & & \\
|(a1)| a_1 & \ddots & \\
\vdots & & \ddots & & & & & & & & \\
|(an)| a_n & & & & & & & & & & \\
\vdots & |(b1)| b_1 & & & & & & & & & \\
\vdots & \vdots & & & & & & & & & \\
\vdots & |(bn)| b_n & & & & & & & & & \\
\vdots & \vdots & |(c1)| c_1 & & & & & & & & \\
\vdots & \vdots & \vdots & & & & & & & & \\
\vdots & \vdots & |(cn)| c_n & & & & & & & & \\
\vdots & \vdots & \vdots & & & & & & & & 0 \\
};
\draw[dashed,red] (a1.north west) rectangle (an.south east);
\draw[dashed,red] (b1.north west) rectangle (bn.south east);
\draw[dashed,red] (c1.north west) rectangle (cn.south east);
\draw[-latex,blue] (an.south) --++(-90:1mm) -| (b1.north);
\draw[-latex,blue] (bn.south) --++(-90:1mm) -| (c1.north);
\end{tikzpicture}
\end{document}