指向嵌套节点的 TikZ 标注

指向嵌套节点的 TikZ 标注

在以下 MWE 中,我想创建一个TikZ指向节点内节点的标注。外部节点用于突出显示环境,\tikzMe内部节点用于\tikzmark。不知何故,我无法正确显示标注。有解决方案吗?

\documentclass{beamer}
\usepackage{beamerthemeshadow}
\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
    },
    BeamerAlert/.style={alt={#1{fill=red!30,rounded corners}{}},anchor=base,inner sep=1pt}
  }

\newcommand<>{\tikzMe}[1]{%
        \tikz[baseline]\node[BeamerAlert={#2},anchor=base,text width=9cm] {#1};      
}

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

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture,baseline=-0.5ex] \node (#1) {};}

\begin{document}

\begin{frame}
\begin{itemize}
  \item Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices.
  \item \tikzMe<2>{Nam arcu libero, nonummy \tikzmark{x}eget, consectetuer id, \dots}
\end{itemize}
\end{frame}

\mycallout<3>{x.north}{Hahahahaha!!!}{5cm}{260}{0.7}{red}

\end{document}

注意:这个问题结合了以下答案投影机中的解释气泡使用 TikZ 节点在 Beamer 中突出显示

答案1

笔记:

  1. 您可以\mycallout用 来定义\newcommand<>;我不认为那xparsebeamer-aware。
  2. 的实际用途\mycallout并不在里面frame
  3. 纠正这两个问题后,您仍然会看到幻灯片 1 和 2 上未隐藏的标注阴影。
    • 方法 1:alt={#7{drop shadow}{invisible}}
    • 方法 2:\node#7[…

代码 1

\documentclass{beamer}
\usepackage{beamerthemeshadow}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts,shadows}

\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
    },
    BeamerAlert/.style={alt={#1{fill=red!30,rounded corners}{}},anchor=base,inner sep=1pt}
  }

\newcommand<>{\tikzMe}[1]{%
        \tikz[baseline]
            \node[BeamerAlert={#2},anchor=base,text width=9cm] {#1};%
}

\newcommand<>{\mycallout}[6]{%
    \tikz[remember picture, overlay]
    \node[
        rounded corners,
        align=left,
        fill=#6!30,
        text width=#3,
        alt={#7{drop shadow}{invisible}},
        draw,
        rectangle callout,
        anchor=pointer,
        callout relative pointer={(#4:#5cm)}
    ] at (#1) {#2};
}

\newcommand{\tikzmark}[1]{%
    \tikz[overlay,remember picture,baseline=-0.5ex]
        \node (#1) {};%
}

\begin{document}

\begin{frame}
\begin{itemize}
  \item Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices.
  \item \tikzMe<2>{Nam arcu libero, nonummy \tikzmark{x}eget, consectetuer id, \dots}
\end{itemize}
\mycallout<3>{x.north}{Hahahahaha!!!}{5cm}{260}{0.7}{red}
\end{frame}
\end{document}

代码 2

此代码实现了 Andrew Stacey 的注释。覆盖规范在 处使用\node#7[…

\documentclass{beamer}
\usepackage{beamerthemeshadow}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts,shadows}

\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
    },
    BeamerAlert/.style={alt={#1{fill=red!30,rounded corners}{}},anchor=base,inner sep=1pt}
  }

\newcommand<>{\tikzMe}[1]{%
        \tikz[baseline]
            \node[BeamerAlert={#2},anchor=base,text width=9cm] {#1};%
}

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

\newcommand{\tikzmark}[1]{%
    \tikz[overlay,remember picture,baseline=-0.5ex]
        \node(#1) {};%
}

\begin{document}

\begin{frame}
\begin{itemize}
  \item Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices.
  \item \tikzMe<2>{Nam arcu libero, nonummy \tikzmark{x}eget, consectetuer id, \dots}
\end{itemize}
\mycallout<3>{x.north}{Hahahahaha!!!}{5cm}{260}{0.7}{red}
\end{frame}
\end{document}

相关内容