
Eu gostaria de fazer um diagrama usando tikz parecido com este
Eu gostaria que tivesse duas linhas. A primeira linha é a redução de linha da matriz, e a segunda linha é para reunir algumas colunas de matrizes de redução de linha na primeira linha e tem setas conectando (por exemplo, a primeira coluna na primeira matriz na primeira linha se conecta à primeira coluna de L no segunda linha (presumo que isso precise de tikz). Gostaria de saber se isso é possível em látex.
Um exemplo de código está listado abaixo:
\[
\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}
\]
Obrigado.
Responder1
Aqui está uma possibilidade usando nicematrix
e tikzmark
. Observe que você deve compilar 3 vezes.
\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}
Responder2
Esta solução é apenas uma ligeira variação da solução (muito boa) de Sandy G. Ela mostra como é possível obter a mesma saída usando os nós criados por nicematrix
(sem 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}
Como sempre nicematrix
, você precisa de várias compilações.
Responder3
Eu acho que você está procurando algo assim:
\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}
Para obter mais informações sobre como escrever matemática em LaTeX, consultewiki, matemática básica, especialwiki, matemática avançadae outros textos introdutórios.
Editar:
- Você (até agora) não fornece informações sobre onde deve começar e terminar a seta desejada.
- Então, abaixo está apenas adivinhando o que você procura
- Se minha suposição estiver errada, pelo menos é dado um princípio de como você pode desenhar setas entre os elementos da equação usando
tikzmark
a biblioteca dotikz
pacote.
\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}