![两个矩阵之间的图形连接](https://linux22.com/image/286804/%E4%B8%A4%E4%B8%AA%E7%9F%A9%E9%98%B5%E4%B9%8B%E9%97%B4%E7%9A%84%E5%9B%BE%E5%BD%A2%E8%BF%9E%E6%8E%A5.png)
我需要显示一个矩阵元素与另一个矩阵的列之间的连接,如下所示:
我怎样才能做到这一点?
答案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}