# Labeling two different parts of one equation with two arrows with different start and end points

I want to write a formula, like the attachment picture, with two different arrows for two parts of the formula. I could write the below code by \xymatrix finally. But the starting point of the second arrow is not correct.

%
%%-------------------------------------------------------------
%% Modern Particle Physics, Mark Thomson, Cambridge University, 2013
%%-------------------------------------------------------------
%
\documentclass[openany,11pt]{book}

\usepackage{amsthm,amsmath,amssymb,mathrsfs,amsfonts}
%\usepackage[cmex10]{amsmath}
\usepackage[all]{xy}
\usepackage{setspace}
\usepackage{makeidx}
\usepackage{colortbl}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{graphics}

\begin{document}

%-----------------
\begin{eqnarray}
\xymatrix{
|K_L\rangle=\frac{1}{\sqrt{2(1+|\epsilon^2|)}}[(1+\varepsilon)\mkern-25mu&\mkern-25mu|K^0\rangle \ar[rd]%
+/d:(1,1) 5pt/\mkern-25mu&\mkern-25mu - (1 - \varepsilon)\mkern-25mu&\mkern-25mu|\bar{K^0}\ar[rd]%
+/d:(1,1) 5pt/\rangle]. \\\nonumber
\mkern-25mu&\mkern-25mu&\mkern-25mu\pi^-e^+\nu_e \mkern-25mu&\mkern-25mu \mkern-25mu&\mkern-25mu \pi^+e^-\bar{\nu}_e}\mkern-25mu \nonumber
\end{eqnarray}
%-----------------

\end{document}



• tikzmark package is your saviour! And please, provide a complete MWE, not just a snippet, in order to let us work on it without rewrinting all the context. Feb 13 '21 at 11:19
• Thanks a lot, I replaced the code with a comploete MWE.
– Reza
Feb 13 '21 at 11:59
• I provided a very straightforward solution with tikzmark below. Feb 13 '21 at 12:01

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}

$|K_L\rangle=\frac{1}{\sqrt{2(1+|\varepsilon^2|)}}\left[(1+\varepsilon)| \tikzmarknode{K1}{K^0}\rangle- (1 - \varepsilon)| \tikzmarknode{K2}{\overline{K}^0}\rangle\right]$

\begin{tikzpicture}[
overlay,remember picture,
arr/.style={-stealth,shorten <=5pt}]

\draw[arr] (K1.south) |-++ (.5,-1) node[at end,right] {$\pi^-e^+\nu_e$};
\draw[arr] (K2.south) |-++ (.5,-.5) node[at end,right] {$\pi^+e^-\overline{\nu}_e$};

\end{tikzpicture}

\end{document}


• Thanks a lot for your fast answer. Your output is exactly what I wanted. But when I just cope and run this code, I get these errors: Undefined control sequence. \tikzmarknode Undefined control sequence. \tikzmarknode Package pgf Error: No shape named K1 is known. \draw[arr] (K1.south) Package pgf Error: No shape named K2 is known. \draw[arr] (K2.south)
– Reza
Feb 13 '21 at 12:21
• Did you just copy and paste my code or did you try to include it into another document? It could be a compatibility issue with your document class. Or maybe you don't have the most recent version of the library. Feb 13 '21 at 12:43
• I just add the below line in your code and the problem solved. \newcommand{\tikzmarknode}[1]{\tikz[baseline,remember picture] \coordinate (#1) {};}
– Reza
Feb 13 '21 at 13:38
• You shouldn't have to. It's probably a question of library obsolescence. Anyway, you can vote and accept my answer ;) Feb 13 '21 at 14:16
• Sure:) I thank you again
– Reza
Feb 13 '21 at 14:26

Final complete code with your help:

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

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

\begin{document}

\begin{align*}
|K_L\rangle =\frac1{\sqrt{2(1 + \lvert\varepsilon^2\rvert)}}
\Bigl[(1 + \varepsilon)
{|K\tikzmarknode{K1}^0\rangle} - (1 - \varepsilon)
{|\bar K\tikzmarknode{K2}^0\rangle} \Bigr].
\end{align*}

\begin{tikzpicture}[overlay,remember picture,
arr/.style={-stealth,shorten <=5pt}]

\draw[arr] (K1.south) |-++ (.5,-1) node[at end,right] {$\pi^-e^+\nu_e$};
\draw[arr] (K2.south) |-++ (.5,-.5) node[at end,right] {$\pi^+e^-\overline{\nu}_e$};

\end{tikzpicture}

\end{document}

enter code here