兩個矩陣之間的圖形連接

兩個矩陣之間的圖形連接

我需要顯示矩陣的元素與另一個矩陣上的列的連接,如下所示:

稀疏矩陣保存座標法

我怎樣才能做到這一點?

答案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}

在此輸入影像描述

相關內容