答案1
您可以使用这个自制的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}
我尝试了标准tikzmark
tikz 库,但是没有用,所以我尝试了这个答案并且有效:
答案2
简短的代码如下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}