Arrows pointing to parts of equation in tcolorbox offset and untidy in XeLaTeX

In my opinion, the arrows should be added as an overlay= option to the tcolorbox, not as a separate environment.

\documentclass{article}

\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,,arrows,shapes,decorations.pathreplacing}
\tikzset{every picture/.style={remember picture}}

\usepackage{amsmath}
\usepackage[framemethod=default]{mdframed}
\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={
  arc=0pt,
  outer arc=0pt,
  colback=gray!30,
  colframe=black,
  boxrule=0.8pt,
  left=2pt,
  right=2pt,
  highlight math style={
    arc=0pt,
    outer arc=0pt,
    colback=gray,
    colframe=blue.
    }
  }
}

\begin{document}
\begin{enumerate}
\item The minimum settling time is given as
  \begin{tcolorbox}[enhanced,ams equation, myformula,overlay={
      \draw[blue,thick,latex-,rounded corners] (d1) |- ++ (0.6cm,-1.5cm) node[anchor=west,text = black,] (label1) {input\ order};
      \draw[blue,thick,latex-,rounded corners] (d2) |- ($(label1.east)-(-0.8cm,-0.6cm)$) node[anchor=west,text = black] {G(z)};}
    ]
\text{Minimum Settling Time } = (%
\tikz[baseline=d1.base]{\node(d1) {$q$}} +%
\tikz[baseline=d2.base]{\node(d2) {$\text{max}\{\ell -1, 0 \}$}} + 1)
\end{tcolorbox}

\item This is another item

\end{enumerate}
\end{document}

enter image description here


I would suggest not to draw parts of the formula by hands and let LaTeX render it. The problem with your formula is that it's hard to get correct spacing. As for the arrows, you can use tikzmarks to label the place on the page where to point them. The following example does that (I borrowed using the tcolorbox overlay idea from the Christian's answer):

\documentclass{article}

\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc,,arrows,shapes,decorations.pathreplacing}
\tikzset{every picture/.style={remember picture}}

\usepackage{amsmath}
\usepackage[framemethod=default]{mdframed}
\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\tcbset{myformula/.style={
  arc=0pt,
  outer arc=0pt,
  colback=gray!30,
  colframe=black,
  boxrule=0.8pt,
  left=2pt,
  right=2pt,
  highlight math style={
    arc=0pt,
    outer arc=0pt,
    colback=gray,
    colframe=blue.
    }
  }
}

\begin{document}
\begin{enumerate}
\item The minimum settling time is given as
\begin{tcolorbox}[enhanced,ams equation, myformula,overlay={
  \draw[blue,thick,latex-,rounded corners] (pic cs:d1)+(3pt,-1.1ex) |- ++ (0.6cm,-1.5cm) node[anchor=west,text=black] (label1) {input\ order};
  \draw[blue,thick,latex-,rounded corners] (pic cs:d2)+(3pt,-1.1ex) |- ($(label1.east)-(-0.8cm,-0.6cm)$) node[anchor=west,text=black] {G(z)};}
  ]
  \text{Minimum Settling Time} = (\tikzmark{d1}q+\max\{\ell\tikzmark{d2}-1,0\}+1)T
\end{tcolorbox}
\vspace{1cm}

\item This is another item

\end{enumerate}
\end{document}

This example still doesn't work with XeLaTeX. pdfLaTeX and LuaLaTeX work fine.

formula