TransWikia.com

Adding Arrows that come through Numbers within Matrices

TeX - LaTeX Asked on February 28, 2021

Here is a pic of what I need.

Need help for achieving this.
enter image description here

The Arrow pierced numbers in rows and columns here.

documentclass[8pt,letterpaper]{article}  
usepackage[left=8mm,top=6mm,bottom=6mm]{geometry}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{arrows.meta,
                tikzmark}   
usepackage{nccmath}

begin{document}
[
begin{bmatrix}
1 & 2 & -1
-2 & 0 & 1
1 & -1 & 0
end{bmatrix}
begin{bmatrix}
    1 & 1 & 2 
    1& 1 & 1
    2 & 3 & 4
end{bmatrix}
=
begin{bmatrix}
    1 & 0 & 0 
    0 & 1 & 0
    0 & 0 & 1
end{bmatrix}
]
end{document}

3 Answers

You can use the extension nicematrix which creates Tikz nodes under each cell of the matrix.

documentclass{article}
usepackage{tikz} %nicematrix does not load tikz. Must load tikz for arrows.meta
usepackage{nicematrix} 
usetikzlibrary{arrows.meta}
begin{document}
$begin{bNiceMatrix}[name=A]
1 & 2 & -1 
-2 & 0 & 1 
1 & -1 & 0 
end{bNiceMatrix}$
%
hspace{1cm}
$begin{bNiceMatrix}[name=B]
1 & 1 & 2 
1 & 1 & 1 
2 & 3 & 4 
end{bNiceMatrix}$
%
begin{tikzpicture}%
    [ remember picture, 
      overlay, 
      every path/.style = 
        { -Straight Barb ,
          color=red,
          very thick,
          semitransparent,
          shorten >=-1pt,
          shorten <=-1pt } ]
 draw (A-1-1.west) -- (A-1-3.east) ;
 draw (B-1-2.north) -- (B-3-2.south) ;
end{tikzpicture}
end{document}

Result of the above code

Correct answer by F. Pantigny on February 28, 2021

A startup to point you in the right direction -- I think you will be able to take it from here

enter image description here

documentclass{article}
usepackage[utf8]{inputenc}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{matrix, arrows.meta}
begin{document}

begin{tikzpicture}[>=Stealth, baseline=(mybaseline)]
matrix[
    matrix of math nodes,
    left delimiter=(,
    right delimiter=),
    inner xsep=2pt,
    ] (mymatr) {%
    0 & 1 & 2 & 3 
    vdots & vdots & ddots & vdots 
    {i-2} & {i-1} & cdots & {i+j-3} 
    y_{i-1}% there was a little typo here 
    & y_{i} & cdots & y_{i+j-2} [12pt]
    y_{i} & y_{i+1} & cdots & y_{i+j-1} 
    y_{i+1} & y_{i+2} & cdots & y_{i+j} [-6pt]
    vdots & vdots & ddots & vdots 
    y_{2i-1} & y_{2i} & cdots & y_{2i+j-2} 
    };
coordinate (mybaseline) at ([yshift=-9pt]mymatr-4-1.south west);
coordinate (mystart) at ([yshift=-6pt]mymatr-4-1.south west);
coordinate (mystop)  at ([yshift=-6pt]mymatr-4-4.south east);
coordinate (myne)  at ([xshift=16pt]mymatr.north east);
coordinate (myse)  at ([xshift=16pt]mymatr.south east);
coordinate (mynw)  at ([xshift=-16pt]mymatr.north west);
coordinate (mysw)  at ([xshift=-16pt]mymatr.south west);
draw (mystart) -- (mystop);
begin{scope}[every node/.style={midway},
every path/.style={->}]
draw ([yshift=-10pt]mymatr.north west) -- ([yshift=-10pt]mymatr.north east) node[above] {$j$};
end{scope}
end{tikzpicture}

end{document}

Adapted from a solution provided by @CarLaTeX -- https://tex.stackexchange.com/a/430681/197451

Answered by js bibra on February 28, 2021

enter image description here

With use of the tikzmark library from tikz package. To get showed result you need to compile MWE at least twice:

documentclass{article}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{arrows.meta,
                tikzmark}       

begin{document}
[
begin{bmatrix}
tikzmarknode{a1}{1} 
    &  2 & tikzmarknode{a2}{-1}    
 -2 &  0 &  1   
  1 & -1 &  0   
end{bmatrix}
begin{bmatrix}
  1 & tikzmarknode{b1}{1} 
        & 2        
  1 & 1 & 1         
  2 & tikzmarknode{b2}{3} 
        & 4        
end{bmatrix}
    begin{tikzpicture}[overlay,remember picture, 
arr/.style = {draw=red, -Straight Barb, very thick, semitransparent,
              shorten >=-1pt, shorten <=-1pt}
                        ]
draw[arr] (a1.west)  -- (a2.east);
draw[arr] (b1.north) -- (b2.south);
    end{tikzpicture}
]
end{document}

Answered by Zarko on February 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP