Matrices and TikZ : arrows inside the matrix

Matrix delimiters are nodes but unnamed by default. Therefore, if you add a name you can use them as reference like any other node and lines will stop on their borders.

In following code, I've used every right delimiter style to add a name which is used later on.

A matrix is an special kind of node which contains other nodes. So if you want to stop a line on matrix border you can use the matrix name as reference. Matrix elements have their own border. I've used intersection points between column center and south matrix border to place the vertical arrow and row center and east anchor on right delimiter to place the horizontal arrow. If you need to understand -| (or |-) syntax, look at https://tex.stackexchange.com/a/481234/1952 or https://tex.stackexchange.com/a/22954/1952.

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit}
\begin{document}

\begin{tikzpicture}[>=stealth,thick,baseline,
every right delimiter/.append style={name=rd},
]
\matrix [matrix of math nodes, 
    left delimiter=(, 
    right delimiter=),
    ](A){ 
a_{1,1} & a_{1,2} & \dots  & a_{1,j} & \dots & a_{1,n}\\
a_{2,1} & a_{2,2} & \dots  & a_{2,j} & \dots & a_{2,n}\\  
\vdots  & \vdots  &  & \vdots  &  & \vdots\\
a_{i,1} & a_{i,2} & \dots  & a_{i,j} & \dots & a_{i,n}\\
\vdots  & \vdots  &  & \vdots  &  & \vdots\\
a_{n,1} & a_{n,2} & \dots  & a_{n,j} & \dots & a_{n,n}\\
};

\draw[<-] (rd.east|-A-4-1.center)--++(0:6mm) node[right]{$i$-ième colonne};
\draw[<-] (A.south-|A-1-4.center) --++(-90:6mm) node[below]{$j$-ième colonne};

\end{tikzpicture}

\end{document}

enter image description here


Add an xshift:

 \documentclass[border=5pt]{standalone}
    \usepackage{tikz}
    \usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit}
    \begin{document}

    \begin{tikzpicture}[>=stealth,thick,baseline]
    \matrix [matrix of math nodes,left delimiter=(,right delimiter=)](A){ 
    a_{1,1} & a_{1,2} & \dots  & a_{1,j} & \dots & a_{1,n}\\
    a_{2,1} & a_{2,2} & \dots  & a_{2,j} & \dots & a_{2,n}\\  
    \vdots  & \vdots  &  & \vdots  &  & \vdots\\
    a_{i,1} & a_{i,2} & \dots  & a_{i,j} & \dots & a_{i,n}\\
    \vdots  & \vdots  &  & \vdots  &  & \vdots\\
    a_{n,1} & a_{n,2} & \dots  & a_{n,j} & \dots & a_{n,n}\\
   };

   \node[
     fit=(A-4-6)(A-4-6),
     inner xsep=20pt,inner ysep=0,
     label=right: $i$-ième ligne
    ](L) {};

   \node[
     fit=(A-6-4)(A-6-4),
     inner xsep=20pt,inner ysep=20pt,
     label=below: $j$-ième colonne
     ](C) {};

    \draw[->](L.east)-- ([xshift=12pt]A-4-6.east);
    \draw[->](C.south)-- (A-6-4);

    \end{tikzpicture}

    \end{document}

enter image description here

Or shorten the arrow:

 \documentclass[border=5pt]{standalone}
    \usepackage{tikz}
    \usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit}
    \begin{document}

    \begin{tikzpicture}[>=stealth,thick,baseline]
    \matrix [matrix of math nodes,left delimiter=(,right delimiter=)](A){ 
    a_{1,1} & a_{1,2} & \dots  & a_{1,j} & \dots & a_{1,n}\\
    a_{2,1} & a_{2,2} & \dots  & a_{2,j} & \dots & a_{2,n}\\  
    \vdots  & \vdots  &  & \vdots  &  & \vdots\\
    a_{i,1} & a_{i,2} & \dots  & a_{i,j} & \dots & a_{i,n}\\
    \vdots  & \vdots  &  & \vdots  &  & \vdots\\
    a_{n,1} & a_{n,2} & \dots  & a_{n,j} & \dots & a_{n,n}\\
   };

   \node[
     fit=(A-4-6)(A-4-6),
     inner xsep=20pt,inner ysep=0,
     label=right: $i$-ième ligne
    ](L) {};

   \node[
     fit=(A-6-4)(A-6-4),
     inner xsep=20pt,inner ysep=20pt,
     label=below: $j$-ième colonne
     ](C) {};

    \draw[->, shorten > =12pt](L.east)-- (A-4-6.east);
    \draw[->](C.south)-- (A-6-4);

    \end{tikzpicture}

    \end{document}

And by the way why do you need fit?

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
    \usetikzlibrary{matrix, positioning}

    \begin{document}

    \begin{tikzpicture}[>=stealth,thick,baseline]
    \matrix [matrix of math nodes,left delimiter=(,right delimiter=)](A){ 
    a_{1,1} & a_{1,2} & \dots  & a_{1,j} & \dots & a_{1,n}\\
    a_{2,1} & a_{2,2} & \dots  & a_{2,j} & \dots & a_{2,n}\\  
    \vdots  & \vdots  &  & \vdots  &  & \vdots\\
    a_{i,1} & a_{i,2} & \dots  & a_{i,j} & \dots & a_{i,n}\\
    \vdots  & \vdots  &  & \vdots  &  & \vdots\\
    a_{n,1} & a_{n,2} & \dots  & a_{n,j} & \dots & a_{n,n}\\
   };

   \node[right =30pt of A-4-6.east](L)  {$i$-ième ligne};

   \node[below=20pt of A-6-4.south](C) {$j$-ième colonne};

    \draw[->, shorten > =12pt](L.west)-- (A-4-6.east);
    \draw[->](C.north)-- (A-6-4.south);

    \end{tikzpicture}

    \end{document}

enter image description here

Tags:

Tikz Pgf