2

There is a similar question on this link: How to draw an arrow to a specified position in a frame and write some notes on the another end of arrow?, but I still have problems in applying it in my case. What I want is to put color on part of the equation and then point out this part and indicate it to $\beta_0$ and $\beta_i$, which should look like as image

According to the solution of this link, I define a command \newcommand{\tikzmark}[1]{\tikz[remember picture] \node[coordinate] (#1) {#1};} then put this syntax \tikzmark{t1} at the end of the part that I want to be selected and point to $\beta_0$, then start a new

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

However, it does not work. It turns out to be, which is not what I want. I think my case is a little bit different with the question in the link, so I don't know how to successfully apply it to my case. Actually, I don't want to start with a new item, just add $\beta_0$ and $\beta_i$ at the end of the arrow. Could someone indicate me how realize it? Thank you.

 \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

2 Answers2

2

You had some errors in your code, e.g the dollar signs inside the cases environment. Not sure if you like it, but I suggest a different way of typesetting that last equation, that doesn't involve a scalebox.

There's no need to use a tikzmark for the betas as well, those can be added as part of the tikzpicture used to draw the arrows.

output of code

\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}
Torbjørn T.
  • 206,688
2

enter image description here

above image is produced with pure tikz solution:

\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}

in above code are corrected errors in use of cases and for second equation macro \MoveEqLeft from package mathools. for more space for equation is used adjustwidth from package changepage, by which the frame text width is increased for 1em on left side. aslo the size of fonts is reduced to \footnotesize.

Zarko
  • 296,517