# connecting arrows under equation

I am trying to create this equation. The arrows are pointing at the subscripts! I managed to write it but it is not quite right as you can see.

• Welcome to TeX.SX! Could you please show us what you tried? So instead of doing it all over, we can focus on fixing what isn't right. Sep 7, 2018 at 13:55

You can use this homemade tikzmark:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows}

\newcommand\tikzmark[1]{\tikz[remember picture,overlay]\coordinate (#1);}

\begin{document}

$Z_{\tikzmark{z1}1\tikzmark{z2}2} = X_{\tikzmark{x111}1\tikzmark{x112}1} Y_{\tikzmark{y121}1\tikzmark{y122}2} + X_{\tikzmark{x121}1\tikzmark{x122}2}Y_{\tikzmark{y221}2\tikzmark{y222}2}$

\begin{tikzpicture}[remember picture,overlay]
\draw[latex-latex]
([shift={(2pt,-2pt)}]z1)
-- ([shift={(2pt,-12pt)}]z1)
-- node[midway, below] {$\scriptstyle 12$} ([shift={(2pt,-12pt)}]z2)
-- ([shift={(2pt,-2pt)}]z2);

\draw[latex-latex]
([shift={(2pt,-2pt)}]x111)
-- ([shift={(2pt,-24pt)}]x111)
-- node[midway, below] {$\scriptstyle 12$} ([shift={(2pt,-24pt)}]y122)
-- ([shift={(2pt,-2pt)}]y122);

\draw[latex-latex]
([shift={(2pt,-2pt)}]x112)
-- ([shift={(2pt,-12pt)}]x112)
-- node[midway, below] {$\scriptstyle 11$} ([shift={(2pt,-12pt)}]y121)
-- ([shift={(2pt,-2pt)}]y121);

\draw[latex-latex]
([shift={(2pt,-2pt)}]x121)
-- ([shift={(2pt,-24pt)}]x121)
-- node[midway, below] {$\scriptstyle 12$} ([shift={(2pt,-24pt)}]y222)
-- ([shift={(2pt,-2pt)}]y222);

\draw[latex-latex]
([shift={(2pt,-2pt)}]x122)
-- ([shift={(2pt,-12pt)}]x122)
-- node[midway, below] {$\scriptstyle 22$} ([shift={(2pt,-12pt)}]y221)
-- ([shift={(2pt,-2pt)}]y221);
\end{tikzpicture}

\end{document}

I tried the standard tikzmark tikz library but it did not work, so I tried the trick from this answer and it worked:

A short code with pstricks:

\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{pst-node, auto-pst-pdf}

\begin{document}

$\begin{postscript} \everypsbox{\scriptstyle} %% Nodes Z_{\rnode[b]{Z1}{1}\rnode[b]{Z2}{2}} = X_{\rnode[b]{a}{1}\rnode[b]{b}{1}}Y_{\rnode[b]{c}{1} \rnode[b]{d}{2}} + X_{\rnode[b]{e}{1} \rnode[b]{f}{2}}X Y_{\rnode[b]{g}{2} \rnode[b]{h}{2}} %% Connections \psset{angle=-90, linejoin=1, arm=4.5mm, arrows=<->, arrowinset=0.1, nodesep=2pt, labelsep=1.5pt} \ncbar[offsetA=-1pt, offsetB=-1.5pt]{Z1}{Z2}\nbput{12} \ncbar[arm=9mm]{a}{d}\nbput{12} \ncbar{b}{c}\nbput{11} \ncbar{f}{g}\nbput{22} \ncbar[arm=9mm]{e}{h}\nbput{12} \end{postscript}$%

\end{document}