4

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{equation}
\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}
\end{equation}

\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.

enter image description here

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

3 Answers 3

3

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{equation}
\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}
\end{equation}

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

\end{document}

enter image description here

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

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{equation}
    \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{equation}

    \end{document} 

enter image description here

1
2

With {bNiceMatrix} of nicematrix and Tikz.

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


\begin{document}

\begin{equation}
\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}
\end{equation}

\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.

Output of the above code

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.