指向嵌套对齐/文本/数学环境的 TikZ 标注未显示

指向嵌套对齐/文本/数学环境的 TikZ 标注未显示

参见下面的 MWE。观察:在第二个版本中显示了标注,但在第一个版本中没有显示。

谁能告诉我为什么会这样?

\documentclass[10pt,xcolor=dvipsnames]{beamer}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts,shadows}
\usepackage{xparse}
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
}

\NewDocumentCommand{\mycallout}{r<> O{opacity=0.8,text opacity=1} m m m m m m}{%
\tikz[remember picture, overlay]\node[drop shadow, rounded corners, align=left, fill=#8!30, text width=#5,
#2,visible on=<#1>,
draw,rectangle callout,anchor=pointer,callout relative pointer={(#6:#7cm)}]
at (#3) {#4};
}

\newcommand{\refbox}[3]{
\tikz[remember picture, baseline=(#1.base)] \node[fill=#3!30,anchor=base,rounded corners] (#1) {#2};
}

\begin{document}
\frame{\frametitle{ABC}

%%%%%%%%%%%%%%%%% with this version the callout is not displayed %%%%%%%%%%%%%%%%
\begin{align*}                              
&\text{ $g(x)\refbox{rb2711121055}{$\sim$}{yellow} x^\alpha$}
\end{align*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    

%%%%%%%%%%%%%%%%% with this version the callout is displayed %%%%%%%%%%%%%%%%%%%%
% \begin{align*}                            
% \refbox{rb2711121055}{$2+2=4$}{yellow}
% \end{align*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\mycallout<1>{rb2711121055.north}{$1<2$}{1cm}{230}{1}{yellow}

}
\end{document}

PS:代码基于https://tex.stackexchange.com/a/83786/16865。我不认为问题与序言开头的复杂内容有任何关系,但由于不确定,我没有进一步简化示例。

答案1

您的使用似乎display math(text mode (inline math))影响了某些方面。如果您使用常规数学环境,则运行两次后即可正常工作。

\documentclass[10pt,xcolor=dvipsnames]{beamer}
\usepackage{mathtools,tikz,lmodern}
\usetikzlibrary{shapes.callouts,shadows}
\usepackage{xparse}
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
}
\NewDocumentCommand{\mycallout}{r<> O{opacity=0.8,text opacity=1} m m m m m m}{%
\tikz[remember picture, overlay]
{\node[drop shadow, rounded corners, align=left, fill=#8!30, text width=#5,
#2,visible on=<#1>,
draw,rectangle callout,anchor=pointer,callout relative pointer={(#6:#7cm)}]
at (#3) {#4};}
}
\newcommand{\refbox}[3]{
\tikz[remember picture, baseline=(#1.base)]{ 
         \node[fill=#3!30,anchor=base,rounded corners] (#1) {#2};}
}
\begin{document}
\begin{frame}{ABC}

\[
g(x)\refbox{rb}{$\sim$}{yellow} x^\alpha
\]

\mycallout<1>{rb.north}{$1<2$}{1cm}{230}{1}{yellow}

\end{frame}
\end{document}

在此处输入图片描述

相关内容