两个矩阵之间的图形连接

两个矩阵之间的图形连接

我需要显示一个矩阵元素与另一个矩阵的列之间的连接,如下所示:

稀疏矩阵坐标系保存方法

我怎样才能做到这一点?

答案1

一个选项是\tikzmark使用tikzmark图书馆:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\newcommand\BoxMatrix[2]{%
  \tikz[remember picture,overlay]
  \draw 
  ([xshift=-1pt,yshift=-2pt]{pic cs:#1}) 
  rectangle ++(#2,2.65ex);
}
\newcommand\BoxEntry[2][fill=red!30]{
  \tikz[remember picture,overlay,baseline=(O.base)]\node[draw,inner sep=2.5pt,#1] (O){#2};
}
\begin{document}

\begin{tikzpicture}[remember picture,overlay]
\draw[fill=cyan!50] 
  ([xshift=-7pt,yshift=20pt]{pic cs:topa}) 
  rectangle 
  ([xshift=13pt,yshift=-15pt]{pic cs:bottoma});
\draw[->]
  ([yshift=3pt]{pic cs:starta}) 
  to[out=80,in=90] 
  ([yshift=22pt]{pic cs:topa});  
\end{tikzpicture}
\BoxMatrix{startAAa}{3cm}
\BoxMatrix{startJRa}{3cm}
\BoxMatrix{startJBa}{3cm}

\[
A = 
\begin{bmatrix} 
1 & 0 & 0 & 2 & 0 \\ 
3 & 4 & 0 & 5 & 0 \\ 
6 & 0 & 7 & \BoxEntry{8}\tikzmark{starta} & 9 \\ 
0 & 0 & 10 & 11 & 0 \\ 
0 & 0 & 0 & 0 & 12 
\end{bmatrix} 
\begin{array}{r@{\,=\ }rrr}
AA & 
\tikzmark{startAAa}12 & \tikzmark{topa}8 & 4\\[1ex]
JR &
\tikzmark{startJRa}\phantom{1}5 & 4 & 15\\[1ex]
JB &
\tikzmark{startJBa}\phantom{1}1 & \tikzmark{bottoma}13 & 6
\end{array}
\]

\begin{tikzpicture}[remember picture,overlay]
\draw[fill=orange!50] 
  ([xshift=-7pt,yshift=20pt]{pic cs:topb}) 
  rectangle 
  ([xshift=8pt,yshift=-15pt]{pic cs:bottomb});
\draw[->]
  ([yshift=3pt]{pic cs:startb}) 
  to[out=-50,in=230] 
  ([yshift=-18pt]{pic cs:bottomb});  
\end{tikzpicture}
\BoxMatrix{startAAb}{4cm}
\BoxMatrix{startJRb}{4cm}
\BoxMatrix{startJBb}{4cm}

\vspace{1cm}

\[
A = 
\begin{bmatrix} 
1 & 0 & 0 & 2 & 0 \\ 
3 & 4 & 0 & 5 & 0 \\ 
6 & 0 & 7 & 8 & 9 \\ 
0 & 0 & 10 & 11 & 0 \\ 
0 & 0 & \BoxEntry[fill=yellow]{30}\tikzmark{startb} & 0 & 12 
\end{bmatrix} 
\begin{array}{r@{\,=\ }rrr}
AA & 
\tikzmark{startAAb}12 & 8 & \tikzmark{topb}4\\[1ex]
JR &
\tikzmark{startJRb}\phantom{1}5 & 4 & 15\\[1ex]
JB &
\tikzmark{startJBb}\phantom{1}1 & 13 & \tikzmark{bottomb}6
\end{array}
\]

\end{document}

在此处输入图片描述

相关内容