[Tex/LaTex] Draw arrows between elements inside math matrix

amsmatharticletikz-pgf

I want to make this,

enter image description here

without having to do the entire thing in TikZ. I tried this (pst-node), which sort of worked, but then I had to use the Basic Builder and I want to avoid that.

Also I tried to make the arrows with TikZ, but I wasn't able to shift the tikzpicture into the equation environment.

\documentclass[12pt,norsk, fleqn]{article}
\usepackage{amssymb, amsmath}
\begin{document}
    \begin{equation*}
        \begin{matrix}
            x_1&y_1&z_1&x_1&y_1&z_1\\
            x_2&y_2&z_2&x_2&y_2&z_2
        \end{matrix}
    \end{equation*}
\end{document}

Any ideas?

Best Answer

The question reads “without having to do the entire thing in TikZ”, so here is a solution that keeps the original matrix:

\documentclass[12pt,norsk, fleqn]{article}
\usepackage{amssymb, amsmath}

\usepackage{tikz}
\newcommand{\rn}[2]{%% "rn": "remember node"
    \tikz[remember picture,baseline=(#1.base)]\node [inner sep=0] (#1) {$#2$};%
}

\begin{document}
    %% The original matrix, but with commands to remember the nodes:
    \begin{equation*}
        \begin{matrix}
            x_1 & \rn{11}{y_1} & \rn{12}{z_1} & \rn{13}{x_1} & \rn{14}{y_1} & z_1
        \\
            x_2 & \rn{21}{y_2} & \rn{22}{z_2} & \rn{23}{x_2} & \rn{24}{y_2} & z_2
        \end{matrix}
    \end{equation*}

    %% Draw the arrows:
    \begin{tikzpicture}[overlay,remember picture]
        \draw [->] (11) -- (22);
        \draw [->] (12) -- (23);
        \draw [->] (13) -- (24);
        \draw [->] (21) -- (12);
        \draw [->] (22) -- (13);
        \draw [->] (23) -- (14);
    \end{tikzpicture}
\end{document}

Explanation: The command \rn puts its second argument in a tikz node. The option remember picture makes these nodes available even after the mini tikzpicture, i.e., after the equation. Later, another tikzpicture draws the arrows. The option overlay ensures that it takes no space and can draw on top of the matrix above.

It looks like before, but with the desired arrows: result