Beamer:如何将箭头指向特定位置,然后在该位置添加一些文本?

Beamer:如何将箭头指向特定位置,然后在该位置添加一些文本?

此链接上有一个类似的问题:如何在框架中画一个指向指定位置的箭头,并在箭头的另一端写一些注释?,但我在将它应用于我的情况时仍然有问题。我想要的是给等式的一部分涂上颜色,然后指出这一部分并将其指示给$\beta_0$$\beta_i$,它应该看起来像图像

根据此链接的解决方案,我定义一个命令,\newcommand{\tikzmark}[1]{\tikz[remember picture] \node[coordinate] (#1) {#1};}然后将此语法放在\tikzmark{t1}我想要选择的部分的末尾并指向$ \ beta_0 $,然后开始一个新的

\begin{itemize}[<+-| alert@+>]
        \item  \tikzmark{n1} $\beta_0$
    \end{itemize}

但是,它不起作用。事实证明,这不是我想要的。我认为我的情况与链接中的问题有点不同,所以我不知道如何成功地将它应用于我的情况。实际上,我不想从新项目开始,只需在箭头末尾添加 $\beta_0$ 和 $\beta_i$。有人能告诉我如何实现它吗?谢谢。

 \documentclass{beamer}
     \usepackage{tabularx} 
     \usepackage[customcolors,norndcorners]{hf-tikz}
     \usetheme{Madrid}
     \newcommand{\tikzmark}[1]{\tikz[remember picture] \node[coordinate] (#1) {#1};}

    \title{An empirical Bayes approach to predict
    radiation-induced toxicity using large-scale
    SNPs}

    \author[C.e]{Ch   \\ \vspace{5mm}}

    \institute[University]{\textbf {  University}}
    \date{11 September 2017}



    \subject{Theoretical Computer Science}



    % Let's get started
    \begin{document}

    \begin{frame}
      \titlepage 
    \end{frame}

    \section{Introduction}

    \subsection{The general problem}
    \begin{frame}{Modelling}
      \begin{itemize}
      \item {\textbf{SNP model}

      \begin{equation}\label{bernoulli}
    X_{ik}|Y \stackrel{iid}{\sim}
    \begin{cases} 
          \mathrm{Bernoulli}($\mathrm{p}_{i+}$) & \text{when} \hspace{4mm} Y= +1, \\
          \mathrm{Bernoulli}($\mathrm{p}_{i-}$) & \text{when} \hspace{4mm} Y =-1.
       \end{cases}
    \end{equation}


      }
      \item { \textbf{Prediction rule} 
         \scalebox{0.87}{
         \hfsetfillcolor{green!10}
      \hfsetbordercolor{green!10}
         \begin{equation}\label{predictionrule}
    \log \frac{\mathrm{P}(Y=+1|X)}{\mathrm{P}(Y=-1|X)}=\tikzmarkin{c}(0.05,-0.6)(-0.05,0.65) \log\frac{\mathrm{P}(Y=+1)}{\mathrm{P}(Y=-1)} +  \sum_{i=1}^{N}\left(\log\frac{1-\mathrm{p}_{i+} }{1-\mathrm{p}_{i-} } \right) \tikzmarkend{c}  \tikzmark{t1}

    + \tikzmarkin{a}(0.05,-0.6)(-0.05,0.65)\sum_{i=1}^{N}\left(\log\frac{\mathrm{p}_{i+} (1-\mathrm{p}_{i-}) }{\mathrm{p}_{i-} (1-\mathrm{p}_{i+} )}\right) \tikzmarkend{a} X_i.
    \end{equation}\\
      }}

      \end{itemize}

      \begin{itemize}[<+-| alert@+>]
        \item  \tikzmark{n1} $\beta_0$
    \end{itemize}
    \end{frame}
    \end{document}


  [1]: https://tex.stackexchange.com/questions/199218/how-to-draw-an-arrow-to-a-specified-position-in-a-frame-and-write-some-notes-on
  [2]: https://i.stack.imgur.com/mAYTJ.jpg

答案1

你的代码中有一些错误,例如环境中的美元符号cases。不确定你是否喜欢它,但我建议用另一种方式来排版最后一个方程,这种方式不涉及比例框。

对于 beta 版也无需使用 tikzmark,它们可以作为tikzpicture绘制箭头的一部分添加。

代码输出

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{tabularx} 
\usepackage[customcolors,norndcorners]{hf-tikz}
\usetikzlibrary{calc} %% added
\usetheme{Madrid}

\begin{document}

\begin{frame}{Modelling}
\begin{itemize}
  \item \textbf{SNP model}

   \begin{equation}\label{bernoulli}
     X_{ik}|Y \stackrel{iid}{\sim}
     \begin{cases} 
      \mathrm{Bernoulli}(\mathrm{p}_{i+}) & \text{when }  Y= +1, \\
      \mathrm{Bernoulli}(\mathrm{p}_{i-}) & \text{when }  Y =-1.
     \end{cases}
   \end{equation}

  \item  \textbf{Prediction rule} 
     \hfsetfillcolor{green!10}
     \hfsetbordercolor{green!10}
     \begin{equation}\label{predictionrule}
        \log \frac{\mathrm{P}(Y=+1|X)}{\mathrm{P}(Y=-1|X)} =
        \begin{aligned}[t]
          \tikzmarkin{c}(0.05,-0.6)(-0.05,0.65)
          \log\frac{\mathrm{P}(Y=+1)}{\mathrm{P}(Y=-1)} +
          \sum_{i=1}^{N}\left(\log\frac{1-\mathrm{p}_{i+} }{1-\mathrm{p}_{i-} } \right)
          \tikzmarkend{c}   \\
          \qquad{}+ \tikzmarkin{a}(0.05,-0.6)(-0.05,0.65) 
          \sum_{i=1}^{N}\left(\log\frac{\mathrm{p}_{i+} (1-\mathrm{p}_{i-}) }{\mathrm{p}_{i-} (1-\mathrm{p}_{i+} )}\right)
          \tikzmarkend{a} X_i.
        \end{aligned}
     \end{equation}

\end{itemize}

% draw arrows
\begin{tikzpicture}[remember picture,overlay]
% define two coordinates at bottom of each highlight box
\coordinate (aa) at ($(c)+(5mm,-1.3cm)$);
\coordinate (bb) at ($(a)+(5mm,-1.3cm)$);
% draw arrow down and place node below
\draw [->] (bb) -- ++(0,-3mm) node[below] (bi) {$\beta_i$};
% place beta0 node at same height as betai node
\node (b0) at (bi-|aa) {$\beta_0$};
% draw arrow
\draw [->] (aa) -- (b0);
\end{tikzpicture}

\end{frame}
\end{document}

答案2

在此处输入图片描述

上图是用纯tikz溶液生成的:

\documentclass{beamer}
\usetheme{Madrid}

\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, fit, tikzmark}

\usepackage{changepage}

\begin{document}
\begin{frame}[fragile]
\frametitle{Modelling}
\begin{adjustwidth}{-1em}{0em}
\footnotesize
    \begin{itemize}
\item   \textbf{SNP model}
    \begin{equation}\label{bernoulli}
X_{ik}|Y    \stackrel{iid}{\sim}
    \begin{cases}
\mathrm{Bernoulli}(\mathrm{p}_{i+}) & \text{when }  Y= +1, \\
\mathrm{Bernoulli}(\mathrm{p}_{i-}) & \text{when }  Y =-1.
    \end{cases}
\end{equation}

\item   \textbf{Prediction rule}
    \begin{align}\label{predictionrule}
    \MoveEqLeft
\log\frac{\mathrm{P}(Y=+1|X)}{\mathrm{P}(Y=-1|X)}
    &   \notag        \\
    & = \tikzmark{a1}
        \log\frac{\mathrm{P}(Y=+1)}{\mathrm{P}(Y=-1)} +  \sum\limits_{i=1}^{N}\left(\log\frac{1-\mathrm{p}_{i+}}{1-\mathrm{p}_{i-}}\right) \tikzmark{a2}
      +
        \tikzmark{b1}
        \sum\limits_{i=1}^{N}\left(\log\frac{\mathrm{p}_{i+} (1-\mathrm{p}_{i-})}
                                   {\mathrm{p}_{i-} (1-\mathrm{p}_{i+} )}\right)
        \tikzmark{b2}
        X_i.
    \end{align}
\end{itemize}
\end{adjustwidth}

    \begin{tikzpicture}[overlay,remember picture,
box/.style = {rounded corners, fill=#1},
pin edge={-Stealth,thick, red}
                        ]
\coordinate (A1) at ($({pic cs:a1})+(+0.5ex, 3ex)$);
\coordinate (A2) at ($({pic cs:a2})+(-0.5ex,-2ex)$);
\coordinate (B1) at ($({pic cs:b1})+(+0.5ex, 3ex)$);
\coordinate (B2) at ($({pic cs:b2})+(-0.5ex,-2ex)$);
\node[box=blue!30,semitransparent,
      fit=(A1) (A2),
      pin=below:\alert{$\beta_0$}]  {};
\node[box=red!30,semitransparent,
      fit=(B1) (B2),
      pin=below:\alert{$\beta_1$}]  {};
\end{tikzpicture}
\end{frame}

以上代码修正了包中cases第二个方程宏的使用和错误。为了给方程提供更多的空间,使用了包中的宏,从而增加了左侧框架文本的宽度。同时,字体大小减小至。\MoveEqLeftmathoolsadjustwidthchangepage1em\footnotesize

相关内容