在矩阵中添加穿过数字的箭头

在矩阵中添加穿过数字的箭头

这是我需要的图片。

需要帮助来实现这一目标。 在此处输入图片描述

箭在这里刺穿了行和列中的数字。

\documentclass[8pt,letterpaper]{article}  
\usepackage[left=8mm,top=6mm,bottom=6mm]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                tikzmark}   
\usepackage{nccmath}

\begin{document}
\[
\begin{bmatrix}
1 & 2 & -1\\
-2 & 0 & 1\\
1 & -1 & 0
\end{bmatrix}
\begin{bmatrix}
    1 & 1 & 2\\ 
    1& 1 & 1\\
    2 & 3 & 4
\end{bmatrix}
=
\begin{bmatrix}
    1 & 0 & 0\\ 
    0 & 1 & 0\\
    0 & 0 & 1
\end{bmatrix}
\]
\end{document}

答案1

nicematrix您可以使用在矩阵的每个单元下创建 Tikz 节点的扩展。

\documentclass{article}
\usepackage{tikz} %nicematrix does not load tikz. Must load tikz for arrows.meta
\usepackage{nicematrix} 
\usetikzlibrary{arrows.meta}
\begin{document}
$\begin{bNiceMatrix}[name=A]
1 & 2 & -1 \\
-2 & 0 & 1 \\
1 & -1 & 0 
\end{bNiceMatrix}$
%
\hspace{1cm}
$\begin{bNiceMatrix}[name=B]
1 & 1 & 2 \\
1 & 1 & 1 \\
2 & 3 & 4 
\end{bNiceMatrix}$
%
\begin{tikzpicture}%
    [ remember picture, 
      overlay, 
      every path/.style = 
        { -Straight Barb ,
          color=red,
          very thick,
          semitransparent,
          shorten >=-1pt,
          shorten <=-1pt } ]
 \draw (A-1-1.west) -- (A-1-3.east) ;
 \draw (B-1-2.north) -- (B-3-2.south) ;
\end{tikzpicture}
\end{document}

上述代码的结果

答案2

在此处输入图片描述

使用包tikzmark中的库tikz。要获得显示的结果,您需要至少编译 MWE 两次:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                tikzmark}       

\begin{document}
\[
\begin{bmatrix}
\tikzmarknode{a1}{1} 
    &  2 & \tikzmarknode{a2}{-1}    \\
 -2 &  0 &  1   \\
  1 & -1 &  0   \\
\end{bmatrix}
\begin{bmatrix}
  1 & \tikzmarknode{b1}{1} 
        & 2     \\   
  1 & 1 & 1     \\    
  2 & \tikzmarknode{b2}{3} 
        & 4     \\   
\end{bmatrix}
    \begin{tikzpicture}[overlay,remember picture, 
arr/.style = {draw=red, -Straight Barb, very thick, semitransparent,
              shorten >=-1pt, shorten <=-1pt}
                        ]
\draw[arr] (a1.west)  -- (a2.east);
\draw[arr] (b1.north) -- (b2.south);
    \end{tikzpicture}
\]
\end{document}

答案3

一家初创公司可以为你指明正确的方向——我想你可以从这里开始

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix, arrows.meta}
\begin{document}

\begin{tikzpicture}[>=Stealth, baseline=(mybaseline)]
\matrix[
    matrix of math nodes,
    left delimiter=(,
    right delimiter=),
    inner xsep=2pt,
    ] (mymatr) {%
    0 & 1 & 2 & 3 \\
    \vdots & \vdots & \ddots & \vdots \\
    {i-2} & {i-1} & \cdots & {i+j-3} \\
    y_{i-1}% there was a little typo here 
    & y_{i} & \cdots & y_{i+j-2} \\[12pt]
    y_{i} & y_{i+1} & \cdots & y_{i+j-1} \\
    y_{i+1} & y_{i+2} & \cdots & y_{i+j} \\[-6pt]
    \vdots & \vdots & \ddots & \vdots \\
    y_{2i-1} & y_{2i} & \cdots & y_{2i+j-2} \\
    };
\coordinate (mybaseline) at ([yshift=-9pt]mymatr-4-1.south west);
\coordinate (mystart) at ([yshift=-6pt]mymatr-4-1.south west);
\coordinate (mystop)  at ([yshift=-6pt]mymatr-4-4.south east);
\coordinate (myne)  at ([xshift=16pt]mymatr.north east);
\coordinate (myse)  at ([xshift=16pt]mymatr.south east);
\coordinate (mynw)  at ([xshift=-16pt]mymatr.north west);
\coordinate (mysw)  at ([xshift=-16pt]mymatr.south west);
\draw (mystart) -- (mystop);
\begin{scope}[every node/.style={midway},
every path/.style={->}]
\draw ([yshift=-10pt]mymatr.north west) -- ([yshift=-10pt]mymatr.north east) node[above] {$j$};
\end{scope}
\end{tikzpicture}

\end{document}

改编自@CarLaTeX 提供的解决方案——https://tex.stackexchange.com/a/430681/197451

相关内容