
我希望它有兩行。第一行是矩陣行約簡,第二行是收集第一行中行約簡矩陣的某些列,並有箭頭連接(例如第一行中的第一個矩陣中的第一列連接到L中的第一列)第二行(我認為這需要 tikz)。
下面列出了範例程式碼:
\[
\begin{pmatrix}
2 & 4 & -1 & 5 & -2 \\
-4 & -5 & 3 & 8 & 1 \\
2 & -5 & -4 & 1 & 8 \\
-6 & 0 & 7 & -3 & 1
\end{pmatrix}
\sim
\begin{pmatrix}
2 & 4 & & \\
& 3 & & \\
& -9 & & \\
& 12 & &
\end{pmatrix}
\sim
\begin{pmatrix}
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & 2 & 1 \\
& & & 4 & 7
\end{pmatrix}
\sim
\begin{pmatrix}
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & 2 & 1 \\
& & & & 5
\end{pmatrix}
= U
\]
%%%% how to add arrows between the two rows?
\[
L = \begin{pmatrix}
1 & 0 & 0 & 0 \\
-2 & 1 & 0 & 0 \\
1 & -3 & 1 & 0 \\
3 & 4 & 2 & 1 \\
\end{pmatrix}
\]
謝謝。
答案1
nicematrix
這是使用和 的可能性tikzmark
。注意一定要編譯3次。
\documentclass{article}
\usepackage{amsmath, nicematrix, tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\[
\begin{pNiceMatrix}[left-margin=.5em]
\Block[tikz={draw, thick, dashed, red}]{4-1}{}2 & 4 & -1 & 5 & -2 \\
-4 & -5 & 3 & 8 & 1 \\
2 & -5 & -4 & 1 & 8 \\
\tikzmarknode{a1}{-6} & 0 & 7 & -3 & 1
\end{pNiceMatrix}
\sim
\begin{pNiceMatrix}
2 & 4 & & \\
& \Block[tikz={draw, thick, dashed, red}]{3-1}{}3 & & \\
& -9 & & \\
& \tikzmarknode{a2}{12} & &
\end{pNiceMatrix}
\sim
\begin{pNiceMatrix}
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & \Block[tikz={draw, thick, dashed, red}]{2-1}{}2 & 1 \\
& & & \tikzmarknode{a3}{4} & 7
\end{pNiceMatrix}
\sim
\begin{pNiceMatrix}[right-margin=.5em]
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & 2 & 1 \\
& & & & \Block[tikz={draw, thick, dashed,red}]{1-1}{}\tikzmarknode{a4}{5}
\end{pNiceMatrix}
= U
\]
\vspace{1cm}
\[
L = \begin{pNiceMatrix}
\tikzmarknode{b1}{1} & \tikzmarknode{b2}{0} & \tikzmarknode{b3}{0} & \tikzmarknode{b4}{0} \\
-2 & 1 & 0 & 0 \\
1 & -3 & 1 & 0 \\
3 & 4 & 2 & 1 \\
\end{pNiceMatrix}
\]
\begin{tikzpicture}[remember picture, overlay]
\draw[red, ->, shorten <=1.5mm, shorten >=1mm](a1) to[out=south, in=north] (b1);
\draw[red, ->, shorten <=1.5mm, shorten >=1mm](a2) to[out=south, in=north] (b2);
\draw[red, ->, shorten <=1.5mm, shorten >=1mm](a3.west) to[out=west, in=north] (b3);
\draw[red, ->, shorten <=1.5mm, shorten >=1mm](a4) to[out=south, in=north] (b4);
\end{tikzpicture}
\end{document}
答案2
該解決方案只是 Sandy G 的(非常好的)解決方案的輕微nicematrix
變化tikzmark
。
\documentclass{article}
\usepackage{nicematrix, tikz}
\begin{document}
\[
\begin{pNiceMatrix}[left-margin=.5em,name=A1]
\Block[tikz={draw, thick, dashed, red}]{4-1}{}2 & 4 & -1 & 5 & -2 \\
-4 & -5 & 3 & 8 & 1 \\
2 & -5 & -4 & 1 & 8 \\
-6 & 0 & 7 & -3 & 1
\end{pNiceMatrix}
\sim
\begin{pNiceMatrix}[name=A2]
2 & 4 & & \\
& \Block[tikz={draw, thick, dashed, red}]{3-1}{}3 & & \\
& -9 & & \\
& 12 & &
\end{pNiceMatrix}
\sim
\begin{pNiceMatrix}[name=A3]
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & \Block[tikz={draw, thick, dashed, red}]{2-1}{} 2 & 1 \\
& & & 4 & 7
\end{pNiceMatrix}
\sim
\begin{pNiceMatrix}[right-margin=.5em,name=A4]
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & 2 & 1 \\
& & & & \Block[tikz={draw, thick, dashed,red}]{1-1}{} 5
\end{pNiceMatrix}
= U
\]
\vspace{1cm}
\[
L = \begin{pNiceMatrix}[name=B]
1 & 0 & 0 & 0 \\
-2 & 1 & 0 & 0 \\
1 & -3 & 1 & 0 \\
3 & 4 & 2 & 1 \\
\end{pNiceMatrix}
\]
\begin{tikzpicture}[remember picture, overlay]
\draw[red, ->, shorten <=1.5mm, shorten >=1mm](A1-4-1) to[out=south, in=north] (B-1-1);
\draw[red, ->, shorten <=1.5mm, shorten >=1mm](A2-4-2) to[out=south, in=north] (B-1-2);
\draw[red, ->, shorten <=1.5mm, shorten >=1mm](A3-4-4.west) to[out=west, in=north] (B-1-3);
\draw[red, ->, shorten <=1.5mm, shorten >=1mm](A4-4-5) to[out=south, in=north] (B-1-4);
\end{tikzpicture}
\end{document}
像往常一樣nicematrix
,您需要進行多次編譯。
答案3
我猜你正在尋找這樣的東西:
\documentclass{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\lipsum[66]
\begin{gather*}
\begin{multlined}
\begin{pmatrix}
2 & 4 & -1 & 5 & -2 \\
-4 & -5 & 3 & 8 & 1 \\
2 & -5 & -4 & 1 & 8 \\
-6 & 0 & 7 & -3 & 1
\end{pmatrix}
\sim
\begin{pmatrix}
2 & 4 & \\
& 3 & \\
& -9 & \\
& 12 &
\end{pmatrix} \\ % <---
\sim
\begin{pmatrix}
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & 2 & 1 \\
& & & 4 & 7
\end{pmatrix}
\sim
\begin{pmatrix}
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & 2 & 1 \\
& & & & 5
\end{pmatrix} = U
\end{multlined} \\ % <---
%
L = \begin{pmatrix}
1 & 0 & 0 & 0 \\
-2 & 1 & 0 & 0 \\
1 & -3 & 1 & 0 \\
3 & 4 & 2 & 1 \\
\end{pmatrix}
\end{gather*}
\end{document}
有關在 LaTeX 中編寫數學的更多信息,請參閱維基百科,基礎數學,特別是維基百科,高等數學以及其他介紹文字。
編輯:
- 您(到目前為止)沒有提供所需箭頭的開始和結束位置的資訊。
- 所以,以下只是瘋狂猜測你想要什麼
- 如果我的猜測是錯誤的,至少給出瞭如何使用包
tikzmark
庫在方程式元素之間繪製箭頭的原則tikz
。
\documentclass{article}
\usepackage{lipsum}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
fit,
tikzmark} % <---
\tikzset{FIT/.style = {fit=#1, node contents={},
draw=red, rounded corners, thick,
inner sep=1pt}
}
\begin{document}
\lipsum[66]
\begin{gather*}
\begin{multlined}
\begin{pmatrix}
\tikzmarknode{a}{2}
& 4 & -1 & 5 & -2 \\
-4 & -5 & 3 & 8 & 1 \\
2 & -5 & -4 & 1 & 8 \\
\tikzmarknode{b}{-6}
& 0 & 7 & -3 & 1
\end{pmatrix}
\sim
\begin{pmatrix}
2 & 4 & \\
& 3 & \\
& -9 & \\
& 12 &
\end{pmatrix} \\ % <---
\sim
\begin{pmatrix}
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & 2 & 1 \\
& & & 4 & 7
\end{pmatrix}
\sim
\begin{pmatrix}
2 & 4 & -1 & 5 & 2 \\
& 3 & 1 & 2 & -3 \\
& & & 2 & 1 \\
& & & & 5
\end{pmatrix} = U
\end{multlined} \\ % <---
%
L = \begin{pmatrix}
\tikzmarknode{c}{1}
~ & 0 & 0 & 0 \\
\tikzmarknode{d}{-2}
& 1 & 0 & 0 \\
1 & -3 & 1 & 0 \\
\tikzmarknode{e}{3}
& 4 & 2 & 1 \\
\end{pmatrix}
%
\begin{tikzpicture}[overlay, remember picture]
\node (A) [FIT=(a) (b)];
\node (B) [FIT=(c) (d) (e)];
\draw[red!50,ultra thick, -{Stealth[scale=0.8]}] (A) -- (B);
\end{tikzpicture}
\end{gather*}
\lipsum[66]
\end{document}