答案1
另一个解决方案是pstricks
:
\documentclass{article}
\usepackage[table, svgnames]{xcolor}
\usepackage{pst-node}
\begin{document}
$ \renewcommand{\arraystretch}{1.25}\begin{array}{l!{\hskip0.8em}ll>{\columncolor{Tan}}l }
m\pnode[0.4ex, 0.5ex]{a} & \pnode[-0.4ex, 0.5ex]{b}-n & -2n & -3n \\
m\pnode[0.45ex, 0.5ex]{c}& \pnode[-0.4ex, 0.5ex]{d}-12n & -6n & -4n \\
\hline
& -mn-12mn & -2mn-6mn & -3mn-4mn \\
&=-13mn & =-8mn & =-7mn
\psset{linecolor=Coral, linewidth=0.5pt}\ncline{a}{d}\ncline{b}{c}
\end{array} $
\end{document}
答案2
以下是使用 TikZ 的 MWE:
\documentclass{article}
\usepackage[table, svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark,arrows.meta}
\begin{document}
\begin{tabular}{
>{$}l<{\quad $} % Controls the gap size
@{}
*{2}{>{$}l<{$}}
>{\columncolor{Tan}$}l<{$}
}
\tikzmarknode{A}{m} & \tikzmarknode{B}{-n} & -2n & -3n \\ % TikZ nodes are defined as A, B, C and D.
\tikzmarknode{C}{m} & \tikzmarknode{D}{-12n} & -6n & -4n \\
\hline
& -mn-12mn & -2mn-6mn & -3mn-4mn \\
&=-13mn & =-8mn & =-7mn
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\draw[Coral,-{Stealth[length=1mm]}] (A.east) -- (D.west); % Lines are drawn with arrow size. You can use ([yshift=<amount>pt,xshift=<amount>pt]A.east) to shift the positions of the lines relative to the anchor points.
\draw[Coral,-{Stealth[length=1mm]}] (C.east) -- (B.west);
\end{tikzpicture}
\end{document}
我使用@campa MWE 作为模板。
答案3
和nicematrix
。
\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
$ \renewcommand{\arraystretch}{1.25}
\begin{NiceArray}{l!{\quad}ll>{\columncolor{red!15}}l}[colortbl-like]
m & -n & -2n & -3n \\
m& -12n & -6n & -4n \\
\hline
& -mn-12mn & -2mn-6mn & -3mn-4mn \\
&=-13mn & =-8mn & =-7mn
\CodeAfter \tikz \draw [red] (1-1.east) -- (2-2.west)
(1-2.west) -- (2-1.east) ;
\end{NiceArray} $
\end{document}
您需要多次编译(因为nicematrix
使用 PGF/Tikz 节点)。