描述矩阵的箭头

描述矩阵的箭头

假设我有一个 5x5 矩阵。我想在矩阵下方放置 2 个左右箭头(描述为“3”、“2”),但要非常靠近矩阵:第一个从 col1 指向 col3,第二个从 col4 指向 col5。另外还有上下箭头,效果类似。我该如何实现?

草稿:

1 1 1 | 1 1

<--> <->

答案1

在此处输入图片描述

矩阵已绘制...:-)

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

\begin{document}
\begin{tikzpicture}[LA/.style = {Straight Barb-Straight Barb,
                                 shorten <=1pt, shorten >=1pt,
                                 draw=red}
                    ]
\matrix (m) [matrix of math nodes,
             left  delimiter={[},
             right delimiter={]}
             ]
{
1 & 1 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 \\
};
\draw (m-1-3.north east) -- (m-5-3.south east);
\draw (m-4-1.north west) -- (m-4-5.north east);
%
\draw[LA] (m-5-1.south west |- m.south) to ["3" '] (m-5-3.south east |- m.south);
\draw[LA] (m-5-4.south west |- m.south) to ["2" '] (m-5-5.south east |- m.south);
%
\coordinate[right=5mm of m.east] (e);
\draw[LA] (m-1-5.north east -| e) to ["3"] (m-3-5.south east -| e);
\draw[LA] (m-4-5.north east -| e) to ["2"] (m-5-5.south east -| e);
\end{tikzpicture}
\end{document}

答案2

以下是您可以使用最新版本nicematrix(≥ v. 6.22 2023-08-14) 执行的操作。

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

\NiceMatrixOptions
  {
    code-for-first-row = \color{red} ,
    code-for-last-col = \color{red} ,
    xdots/horizontal-labels
  }

\begin{document}

$\begin{pNiceArray}{ccc|cc}[first-row,last-col,xdots/line-style=<->,margin=2pt]
\Hdotsfor{3}^{3} & \Hdotsfor{2}^{2} \\
1 & 1 & 1 & 1 & 1 & \Vdotsfor{3}^{3}\\
1 & 1 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 \\
\hline
1 & 1 & 1 & 1 & 1 & \Vdotsfor{2}^{2}\\
1 & 1 & 1 & 1 & 1 \\
\end{pNiceArray}$

\end{document}

您需要多次编译(因为nicematrix使用 PGF/Tikz 节点)。

上述代码的输出

相关内容