TransWikia.com

Arrows describing matrix

TeX - LaTeX Asked on February 4, 2021

Lets say I have a 5×5 matrix.
I want to place 2 leftrightarrows (with descriptions “3”, “2”) underneath the matrix, but really close to it: first pointing from col1 to col3 and second from col4 to col5.
Plus updownarrows with similar outcome.
How can I achieve that?

draft:

1 1 1 | 1 1

<–> <->

2 Answers

enter image description here

matrix is drawn ... :-)

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}

Answered by Zarko on February 4, 2021

Here is what you can do with the latest version of nicematrix (v. 5.8 2021-01-01).

documentclass{article}

usepackage{nicematrix}
usepackage{tikz}

tikzset{H/.style = {solid,<->}}
tikzset{V/.style = {solid,<->,xshift=2mm}}

begin{document}

$begin{pNiceArray}{ccc|cc}[first-row,last-col]
Hdotsfor[line-style=H]{3}^{3} & Hdotsfor[line-style=H]{2}^{2} 
1 & 1 & 1 & 1 & 1 & Vdotsfor[line-style=V]{3}^{3}
1 & 1 & 1 & 1 & 1 
1 & 1 & 1 & 1 & 1 
hline
1 & 1 & 1 & 1 & 1 & Vdotsfor[line-style=V]{2}^{2}
1 & 1 & 1 & 1 & 1 
end{pNiceArray}$

end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

Answered by F. Pantigny on February 4, 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