矩阵之间的对角相交箭头

矩阵之间的对角相交箭头

我有以下矩阵,我想重新创建与该图像类似的效果,其中每个箭头都指向交换行的位置:

期望输出

\[
\begin{bmatrix}
    0 & 0 & 100 & 0 \\
    2.85714285714 & 45.7142857143 & 0 & 51.4285714286 \\
    0 & 92.0 & 0 & 8 \\
    100 & 0 & 0 & 0
\end{bmatrix}

\begin{bmatrix}
    100 & 0 & 0 & 0 \\
    0 & 92.0 & 0 & 8 \\
    0 & 0 & 100 & 0 \\
    2.85714285714 & 45.7142857143 & 0 & 51.4285714286 
\end{bmatrix}
\]

注:感谢您发现拼写错误

答案1

使用 TikZ 的可能解决方案:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,tikz}
\usetikzlibrary{calc}
\begin{document}

\newcommand*{\tikzmark}[1]{\tikz[overlay,remember picture]{\coordinate[yshift=.7ex](#1);}}

\[
\begin{bmatrix}
    0 & 0 & 100 & 0\tikzmark{A} \\
    2.86  & 45.71 & 0 & 51.43\tikzmark{B} \\
    0 & 92.0 & 0 & 8\tikzmark{C} \\
    100 & 0 & 0 & 0\tikzmark{D}
\end{bmatrix}
\tikzmark{M}\qquad\qquad
\tikzmark{m}\begin{bmatrix}
    \tikzmark{d}100 & 0 & 0 & 0 \\
    \tikzmark{c}0 & 92.0 & 0 & 8 \\
    \tikzmark{a}0 & 0 & 100 & 0 \\
    \tikzmark{b}2.86 & 45.71 & 0 & 51.43 
\end{bmatrix}
\]

\begin{tikzpicture}[overlay,remember picture,>=latex]
\foreach \l/\r in {A/a,B/b,C/c,D/d}
  \draw[->] ($(\l-|M)$)--($(\r-|m)$);
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

纯 TikZ 版本:矩阵如下tikzpicture

\documentclass[tikz,
               border=3mm,
               ]{standalone}
\usetikzlibrary{arrows.meta, matrix, positioning}

\begin{document}
    \begin{tikzpicture}[node distance = 22mm,
every left  delimiter/.style = {xshift=1.5ex},
every right delimiter/.style = {xshift=-1.5ex},
         every matrix/.style = {matrix of math nodes,
                                left delimiter={[},
                                right delimiter={]}
                                }
                    ]
\matrix (m1)
{
0               & 0             & 100   & 0             \\
2.85714285714   & 45.7142857143 & 0     & 51.4285714286 \\
0               & 92.0          & 0     & 8             \\
100             & 0             & 0     & 0             \\
};
\matrix (m2)    [right=of m1]
{
100             & 0             & 0     & 0             \\
0               & 92.0          & 0     & 8             \\
0               & 0             & 100   & 0             \\
2.85714285714   & 45.7142857143 & 0     & 51.4285714286 \\
};
\coordinate[right=1pt of m1] (a);
\coordinate[ left=1pt of m2] (b);
\draw[gray, very thick, -Stealth]
    (m1-1-4 -| a)  edge (m1-3-1 -| b)
    (m1-2-4 -| a)  edge (m1-4-1 -| b)
    (m1-3-4 -| a)  edge (m1-2-1 -| b)
    (m1-4-4 -| a)   to  (m1-1-1 -| b);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

{bNiceMatrix}和TikZ 的版本nicematrix使用 创建的节点来绘制箭头nicematrix

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\[
\begin{bNiceMatrix}[name = A]
    0 & 0 & 100 & 0 \\
    2.86 & 45.71 & 0 & 51.43 \\
    0 & 92.0 & 0 & 8 \\
    100 & 0 & 0 & 0
\end{bNiceMatrix}
\hspace{1cm}
\begin{bNiceMatrix}[name = B]
    100 & 0 & 0 & 0 \\
    0 & 92.0 & 0 & 8 \\
    0 & 0 & 100 & 0 \\
    2.86 & 45.71 & 0 & 51.43
\end{bNiceMatrix}
\]

\begin{tikzpicture}[remember picture, overlay, ->]
  \draw (A-1.5-|A-5) -- (B-3.5-|B-1) ; 
  \draw (A-2.5-|A-5) -- (B-4.5-|B-1) ; 
  \draw (A-3.5-|A-5) -- (B-2.5-|B-1) ; 
  \draw (A-4.5-|A-5) -- (B-1.5-|B-1) ; 
\end{tikzpicture}

\end{document}

上述代码的输出

答案4

厌恶pstricks

\documentclass{article}
\usepackage{geometry}
\usepackage{mathtools}
\usepackage{pgffor, pgfmath}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}
\small
\[ \setlength\arraycolsep{3pt}
  \begin{postscript}
    \begin{medsize}\textstyle
      \begin{bmatrix}
        0 & 0 & 100 & 0 \\
        2.85714285714 & 45.7142857143 & 0 & 51.4285714286 \\
        0 & 92.0 & 0 & 8 \\
        100 & 0 & 0 & 0
      \end{bmatrix}
      \begin{matrix}
        \pnode[-0.8ex, 0.8ex]{l1} \\ \pnode[-0.8ex, 0.8ex]{l2} \\ \pnode[-0.8ex, 0.8ex]{l3} \\ \pnode[-0.8ex, 0.8ex]{l4}
      \end{matrix}
      \hspace{3em}
      \begin{matrix}
        \pnode[1ex, 1ex]{r1} \\ \pnode[1ex, 1ex]{r2} \\ \pnode[1ex, 1ex]{r3} \\ \pnode[1ex, 1ex]{r4}
      \end{matrix}
      \begin{bmatrix}
        100 & 0 & 0 & 0 \\
        0 & 92.0 & 0 & 8 \\
        0 & 0 & 100 & 0 \\
        2.85714285714 & 45.7142857143 & 0 & 51.4285714286
      \end{bmatrix}
    \end{medsize}
    \psset{arrows=->, arrowinset=0.12}%
    \foreach \l/\r in {l1/r3, l2/r4, l3/r2, l4/r1}{\ncline{\l}{\r}}
  \end{postscript}
\]
\end{document} 

在此处输入图片描述

相关内容