# Curly arrow from a matrix to another

I am trying to put an arrow that goes from a matrix to another one with some text above. I came with this code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\begin{document}

$$\begin{bmatrix} 1 & \tikz[remember picture] \node (n3){1}; & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \\ \end{bmatrix} = \begin{bmatrix} 1 & \tikz[remember picture] \node (n4){1}; & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \\ \end{bmatrix}$$

\begin{tikzpicture}[remember picture,overlay]
\draw[->,very thick]  (n3) to [out=45,in=135] node[above] {some text here} (n4);
\end{tikzpicture}

\end{document}


but the two number higlighted by \node command are "floating" with respect the other ones. How can I fix? Thanks

Edit: As suggested, I am going to show a screenshot of the final work. As you can see, the zero and the theta are "floating" with respect to the other items on the same line.

• Welcome. // Please include a screenshot in your question. Jul 7 at 10:38
• @MS-SPO, Thanks for the advice! Jul 7 at 10:44

The most important change is to eliminate inner sep and use node's baseline as the baseline for the whole tikz picture. Additionally, outer sep is set so the arrow will keep a "safe distance" :_) from both nodes.

Also note tikzmark does similar settings more automatic and you can find its use cases on this site.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\tikzset{
my mark/.style={
remember picture, inner sep=0pt, outer sep=2pt, baseline=(#1.base)
}
}

\begin{document}

$$\begin{bmatrix} 1 & \tikz[my mark=n3] \node (n3){1}; & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \\ \end{bmatrix} = \begin{bmatrix} 1 & \tikz[my mark=n4] \node (n4){1}; & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \\ \end{bmatrix}$$

\begin{tikzpicture}[remember picture,overlay]
\draw[->,very thick, ] (n3) to [out=45,in=135] node[above] {some text here} (n4);
\end{tikzpicture}

\end{document}


• Also this is very nice, thank you! And thank you for the explanation. Jul 7 at 11:35

If you do it with pstricks, you won't have such a problem:

    \documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{pst-node}

\begin{document}

$$\begin{bmatrix} 1 & \Rnode{n3}{1} & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \\ \end{bmatrix} = \begin{bmatrix} 1 & \Rnode{n4}{1} & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \\ \end{bmatrix} \psset{linejoin=1, arrowinset=0.1} \nccurve[angleA=45, angleB=135,nodesep=1pt]{->}{n3}{n4} \naput[labelsep=2pt]{\text{some text here}}$$

\end{document}


• This work very very nice, thank you! Jul 7 at 11:33

With {bNiceMatrix} of nicematrix and Tikz.

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\begin{document}

$$\begin{bNiceMatrix}[name=A] 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \\ \end{bNiceMatrix} = \begin{bNiceMatrix}[name=B] 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \\ \end{bNiceMatrix}$$

\begin{tikzpicture}[remember picture,overlay]
\draw[->,very thick] (A-1-2) to [out=45,in=135] node[above] {some text here} (B-1-2);
\end{tikzpicture}

\end{document}


You need several compilations because of the PGF/Tikz nodes.

• Thank you also for your contribute! Jul 7 at 14:58