1

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}

enter image description here

Reza
  • 61
  • 4

2 Answers2

1
\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}

tikzmark arrows on equation

SebGlav
  • 19,186
  • 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. – SebGlav 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 ;) – SebGlav Feb 13 '21 at 14:16
  • Sure:) I thank you again – Reza Feb 13 '21 at 14:26
  • @Reza Sounds like you have an out of date version of the tikzmark library. I recommend that you update your TeX installation to get it. – Andrew Stacey Feb 15 '21 at 21:06
0

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 &lt;=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
Reza
  • 61
  • 4