我正在尝试使用tikzmark
库来注释方程式。我有以下 MWE
\documentclass{article}
\usepackage{tikz,amsmath}
\usetikzlibrary{tikzmark}
\begin{document}
\[
\text{Regret}_T = \tikzmarknode{a}{T \cdot {\mu^*}} - \tikzmarknode{b}{\sum_{t=0}^{T-1} \mu_{a_t}}
\begin{tikzpicture}[remember picture,overlay]
\draw[red,thick,->] (a.south) to [in=90,out=245] +(190:3.0cm) node[anchor=north,text=red, align = center] {total expected reward \\ if pull best arm over $T$ rounds};
\draw[blue,thick,->] (b.south) to [in=90,out=245] +(360:3.0cm) node[anchor=north,text=blue, align = center] {total expected reward \\ of our selected arms};
\end{tikzpicture}
\]
And this line of text is overlapped. % NOTE THIS
\end{document}
请注意,后续文本重叠了,我认为这是由于环境overlay
选项造成tikzpicture
的。除了手动插入空行之外,我想知道是否有某种自动方法可以让 latex 识别这些箭头并安排布局,以便下面的行可以正确呈现。谢谢。
答案1
\documentclass{article}
\usepackage{tikz, amsmath}
\usetikzlibrary{tikzmark, positioning}
\begin{document}
\[
\text{Regret}_T = \tikzmarknode{a}{T \cdot {\mu^*}} - \tikzmarknode{b}{\sum_{t=0}^{T-1} \mu_{a_t}}
\]
\begin{center}
\tikzmarknode[text=red, align=center]{aa}{total expected reward\\if pull best arm over $T$ rounds}
\qquad
\tikzmarknode[text=blue, align=center]{bb}{total expected reward\\of our selected arms}
\end{center}
\begin{tikzpicture}[remember picture, overlay]
\draw[red, thick, ->, shorten <= 4pt] (a) to[out=250, in=90] (aa);
\draw[blue, thick,->, shorten <=-2pt] (b) to[out=320, in=90] (bb);
\end{tikzpicture}
And this line of text is not overlapped.
\end{document}