# Arrows from equation causing equation to look untidy

in the code below, when I place the arrow to the equation, it messes with the alignment of the elements of the equation that the arrows are referring to. Is it possible to maintain the alignment of the equation (as shown in the second equation) and still have the arrows pointing to them? Thanks for your help.

Here is my code:

\documentclass{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{mathptmx}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,,arrows,shapes,decorations.pathreplacing}
\tikzset{every picture/.style={remember picture}}

\begin{document}
We denote
$$\hat{x}^{-}_{k} \equiv \hat{x}(\tikz[baseline]{\node(d1){k}}\mid \tikz[baseline]{\node(d2){k-1}})$$
\begin{tikzpicture}[remember picture,overlay]{
\draw[blue,thick,<-,rounded corners] (d1) |- ++ (0.6cm,-1.5cm) node[anchor=west,text = black,] (label1) {\emph{what is the $kth~x$}};
\draw[blue,thick,<-,rounded corners] (d2) |- ($(label1.west)-(-0.8cm,-0.6cm)$) node[anchor=west,text = black] {$given~\hat{x}_{k-1},~z_{k-1}$};}
\end{tikzpicture}
\vspace{1cm}

We denote
$$\hat{x}^{-}_{k} \equiv \hat{x}(k\mid k-1)$$

\end{document}

• Related non-tikz approach: tex.stackexchange.com/questions/263480/… Commented Dec 2, 2015 at 13:40
• not relevant to question, but ... since amssymb loads amsfonts, you needn't specify the latter. Commented Dec 2, 2015 at 20:42

As you're loading the tikzmark library anyway, use its \subnode, with the whole equation in one node:

\documentclass{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{mathptmx}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,arrows,shapes,decorations.pathreplacing}
%\tikzset{every picture/.style={remember picture}}

\begin{document}
We denote
$$\tikz{\node{\hat{x}^{-}_{k} \equiv \hat{x}(\subnode{d1}{k}\mid \subnode{d2}{k-1})};}$$
\begin{tikzpicture}[remember picture,overlay]{
\draw[blue,thick,<-,rounded corners] (d1) |- ++ (0.6cm,-1.5cm) node[anchor=west,text = black,] (label1) {\emph{what is the $k$th $x$}};
\draw[blue,thick,<-,rounded corners] (d2) |- ($(label1.west)-(-0.8cm,-0.6cm)$) node[anchor=west,text = black] {given $\hat{x}_{k-1},~z_{k-1}$};}
\end{tikzpicture}
\vspace{1cm}

We denote
$$\hat{x}^{-}_{k} \equiv \hat{x}(k\mid k-1)$$

\end{document}