Draw a matrix/array with arrows between rows and between elements matricestikz-arrowstikz-pgf How to draw a matrix/array with arrows between rows and between elements? Best Answer You may use the tikzmark library to draw around your matrix. Needs to be compiled twice. \documentclass{article} \usepackage{amsmath, tikz} \usetikzlibrary{tikzmark} \begin{document} \[ \begin{matrix} 1 & \tikzmarknode{A}{2} & 3 & 4 & \tikzmarknode{C}{5} \\ \tikzmarknode{B}{1} & 2 & 3 & 4 & \tikzmarknode{D}{5} \\ 1 & 2 & 3 & 4 & \tikzmarknode{E}{5} \\ 1 & 2 & 3 & 4 & \tikzmarknode{F}{5} \end{matrix} \] \begin{tikzpicture}[remember picture, overlay] \draw[->] (A) -- (B); \draw[->] (C.-10) to[out=-20, in=20, looseness=2] (D.10); \draw[->] (C.-10) to[out=-20, in=180, looseness=1.5] ++ (0.5,-0.25) node[right] {$1$}; \draw[->] (D.-10) to[out=-20, in=20, looseness=2] (E.10); \draw[->] (D.-10) to[out=-20, in=180, looseness=1.5] ++ (0.5,-0.25) node[right] {$1$}; \draw[->] (E.-10) to[out=-20, in=20, looseness=2] (F.10); \draw[->] (E.-10) to[out=-20, in=180, looseness=1.5] ++ (0.5,-0.25) node[right] {$1$}; \end{tikzpicture} \end{document} Related Solutions[Tex/LaTex] Matrix with arrows and labels Another way with TikZ similar to Highlight elements in the matrix: \documentclass{article} \usepackage{tikz} \newcommand{\tikzmark}[1]{\tikz[overlay, remember picture] \coordinate (#1);} \begin{document} \[ M_{reg} = \qquad \bordermatrix{~ & \tikzmark{harrowleft} 0 & 1 & 2 & 3 & 4\tikzmark{harrowright} \cr \tikzmark{varrowtop} 0 & 0 & 0 & 0 & 1 & 1 \cr 1 & 0 & 0 & 1 & 1 & 1 \cr 2 & 0 & 0 & 1 & 1 & 0 \cr 3 & 0 & 0 & 1 & 1 & 0 \cr \tikzmark{varrowbottom}4 & 0 & 0 & 0 & 0 & 0 \cr } \] \tikz[overlay,remember picture] { \draw[->] ([yshift=3ex]harrowleft) -- ([yshift=3ex]harrowright) node[midway,above] {\scriptsize DAG}; \draw[->] ([yshift=1.5ex,xshift=-2ex]varrowtop) -- ([xshift=-2ex]varrowbottom) node[near end,left] {\scriptsize $Ca^{2+}$}; } \end{document} [Tex/LaTex] How to define the proper space between elements of a matrix Here's one possible way; \overmat writes its first argument above the entries enclosed in the second argument; the separation between columns in the inner matrix was increased using 10pt for arraycolsep: \documentclass{article} \usepackage{amsmath} \usepackage{array} \usepackage{xcolor} \newcommand\overmat[2]{% \makebox[0pt][c]{$\smash{\color{white}\overbrace{\vphantom{% \begin{matrix}{c}#2\end{matrix}}}^{\mkern12mu \text{\color{black}#1}}}$}#2} \newcommand\diagdown{}% temporal definition \begin{document} \[D^{4}_{2}= \left[\begin{array}{c@{}c} \diagdown & \\ {\begin{array}{>{\scriptstyle}c} \{1,2\} \\ \{1,3\} \\ \{2,3\} \\ \{1,4\} \\ \{2,4\} \\ \{3,4\} \end{array}} & \setlength\arraycolsep{10pt} {\left(\begin{array}{@{\mkern5mu}cccccc@{\mkern5mu}} \overmat{\{1,2\}}{0} & \overmat{\{1,3\}}{0} & \overmat{\{2,3\}}{0} & \overmat{\{1,4\}}{0} & \overmat{\{2,4\}}{0} & \overmat{\{3,4\}}{1} \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 & 0 & 0 \\ \end{array}\right)} \end{array}\right] \] \end{document} Since I didn't know the definition of \diagdown, I provided a partial definition \newcommand\diagdown{}. Use your actual definition in your document. Related Question[Tex/LaTex] Matrix with lines and labels with arrowsMatrix with external elements and dashed separation lines
Best Answer
You may use the
tikzmark
library to draw around your matrix. Needs to be compiled twice.