1

I'd like to have arrows pointing different elements in an equation and that they appear as I go explaining each term in the presentation. For instance, I want the first arrow to appear above ln_(w_j,t), then in the next slide I want the second arrow to appear above ln_(w_j,t-1), and so on. I tried using tikzpicture but it didn't work. Any help is very appreciated, thanks!

\documentclass[aspectratio=169]{beamer} 
\mode<presentation>
{
  \usetheme{default}
  \usecolortheme{default}
  \usefonttheme{default}
  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{caption}[numbered]
} 

\usepackage{wasysym}
\usepackage{amssymb}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{bbold} %indicator function
\usepackage{centernot}
\usepackage[absolute,overlay]{textpos}
\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Outline}
    \tableofcontents[currentsection]
  \end{frame}
}

\setbeamercovered{dynamic} 

\usepackage[normalem]{ulem}
\usepackage[thicklines]{cancel}
\usepackage{pgfpages}
\usepackage{amsmath}
\usepackage{threeparttable}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage{amsfonts}
\usepackage{appendixnumberbeamer}
\usepackage{bbm}
\usepackage{tabu}
\usepackage{anyfontsize}
\usepackage{setspace}
\usepackage{multirow}
\usepackage{graphics} 
\usepackage{hyperref}
\usepackage{comment}
\definecolor{light-gray}{gray}{0.8}
\definecolor{invisible}{gray}{1}
\definecolor{blue(pigment)}{rgb}{0.2, 0.2, 0.6}
\definecolor{ceruleanblue}{rgb}{0.16, 0.32, 0.75}
\definecolor{indigo(dye)}{rgb}{0.0, 0.25, 0.42}
\definecolor{kellygreen}{rgb}{0.3, 0.73, 0.09}
\definecolor{Blue}{HTML}{005073}
\definecolor{test}{RGB}{0,136,196}%{106,168,79}%{48,159,169}%{48,149,193}%{3,168,158}%%{69,160,199}%{37,132,214}

\usetheme{metropolis}
\setbeamercolor{frametitle}{bg=Blue}%ceruleanblue}
\setbeamercolor{background canvas}{bg=white}
\setbeamercolor{alerted text}{fg=test}

\newcommand*\MyCitem{%
  \item[\color{lightgray}{\textbullet}]}
  
%%% Stuff to create only partial handout
\makeatletter
\newcommand\changemode[1]{%
  \gdef\beamer@currentmode{#1}}
\makeatother

%%% Stuff to show video %%%
\usepackage{multimedia}

%%%% TIKZ STUFF
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit,shapes.geometric}
\usetikzlibrary{arrows.meta}

\usetikzlibrary{matrix,shapes,arrows,fit}
\newcolumntype{.}{D{.}{.}{-1}}
\usepackage{booktabs,dcolumn}
\usepackage{tabularx}

% Overlays

\newcounter{jumping}
\resetcounteronoverlays{jumping}

\makeatletter
\tikzset{
    stop jumping/.style={
        execute at end picture={%
            \stepcounter{jumping}%
            \immediate\write\pgfutil@auxout{%
                \noexpand\jump@setbb{\the\value{jumping}}{\noexpand\pgfpoint{\the\pgf@picminx}{\the\pgf@picminy}}{\noexpand\pgfpoint{\the\pgf@picmaxx}{\the\pgf@picmaxy}}
            },
            \csname jump@\the\value{jumping}@maxbb\endcsname
            \path (\the\pgf@x,\the\pgf@y);
            \csname jump@\the\value{jumping}@minbb\endcsname
            \path (\the\pgf@x,\the\pgf@y);
        },
    }
}
\def\jump@setbb#1#2#3{%
    \@ifundefined{jump@#1@maxbb}{%
        \expandafter\gdef\csname jump@#1@maxbb\endcsname{#3}%
    }{%
    \csname jump@#1@maxbb\endcsname
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    #3
    \pgfmathsetlength\pgf@x{max(\pgf@x,\pgf@xa)}%
    \pgfmathsetlength\pgf@y{max(\pgf@y,\pgf@ya)}%
    \expandafter\xdef\csname jump@#1@maxbb\endcsname{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
}
\@ifundefined{jump@#1@minbb}{%
    \expandafter\gdef\csname jump@#1@minbb\endcsname{#2}%
}{%
\csname jump@#1@minbb\endcsname
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
#2
\pgfmathsetlength\pgf@x{min(\pgf@x,\pgf@xa)}%
\pgfmathsetlength\pgf@y{min(\pgf@y,\pgf@ya)}%
\expandafter\xdef\csname jump@#1@minbb\endcsname{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
}
}
\makeatother



%%%%%% END TIKZ STUFF
\newenvironment{itemize1}{\begin{itemize}\setlength{\itemsep}{10pt}\setlength{\parskip}{10pt}}{\end{itemize}}
\newenvironment{itemize2}{\begin{itemize}\setlength{\itemsep}{5pt}\setlength{\parskip}{5pt}}{\end{itemize}}
\newenvironment{enumerate1}{\begin{enumerate}\setlength{\itemsep}{10pt}\setlength{\parskip}{10pt}}{\end{enumerate}}
\newenvironment{enumerate2}{\begin{enumerate}\setlength{\itemsep}{5pt}\setlength{\parskip}{5pt}}{\end{enumerate}}

% Wider slide
\newcommand\Wider[2][3em]{%
\makebox[\linewidth][c]{%
  \begin{minipage}{\dimexpr\textwidth+#1\relax}
  \raggedright#2
  \end{minipage}%
  }%
}


\setbeamertemplate{footline}{%
   \raisebox{5pt}{\makebox[\paperwidth]{\hfill\makebox[10pt]{\scriptsize\insertframenumber}}}}

\begin{frame}[label=model_earnings]{Earnings process}
    \begin{align*} 
            &  ln(w_{j,t})=\ln(w_{j,t-1})-\delta 1(h_{j,t-1}=0)+\epsilon_{j,t}\\
        & ln(w_1) \sim N(\mu_,\sigma_1)\\
        & \epsilon_{j,t} \sim N(0,\sigma)
    \end{align*}
\end{frame}

\end{document}

2 Answers 2

4

Please always include a "Minimal Working Example" (MWE) when you post a question. Your code has many unnecessary packages loaded (some more than once) and does not compile since it is missing \begin{document}. Here is what a minimal example would look like for your question:

\documentclass[aspectratio=169]{beamer} 

\definecolor{Blue}{HTML}{005073}

\usetheme{metropolis}
\setbeamercolor{frametitle}{bg=Blue} %ceruleanblue}

\begin{document}

\begin{frame}[label=model_earnings]{Earnings process}
    \begin{align*} 
         ln(w_{j,t})&=\ln(w_{j,t-1})-\delta_1(h_{j,t-1}=0)+\epsilon_{j,t}\\
         ln(w_1) &\sim N(\mu_,\sigma_1)\\
         \epsilon_{j,t} &\sim N(0,\sigma)
    \end{align*}
\end{frame}

\end{document}

I guarantee that you would have received many good answers by now if you had done this.

To produce the effect you want, I suggest using tikz and the tikzmark library by including

\usepackage{tikz} 
\usetikzlibrary{tikzmark}

in your preamble. The \tikzmarknode command can be added to the items you want referenced. Each node should get its own name. I used a1, a2, a3, a4 in the code below.

Then create a tikzpicture using the options remember picture, overlay. Now you can draw the arrows using whatever tikz commands you want. The named nodes will be available. I created a tikzset called explain using the options red, thick, <-, shorten <=3pt, so you can easily change the style for all arrows.

Finally, you can use the \only command to have the explanations appear and disappear with each click.

enter image description here

Here is the code. Important: You must compile it three times.

\documentclass[aspectratio=169]{beamer}
\usepackage{tikz} 
\usetikzlibrary{tikzmark}

\tikzset{explain/.style={red, thick, <-, shorten <=3pt}}

\definecolor{Blue}{HTML}{005073}

\usetheme{metropolis}
\setbeamercolor{frametitle}{bg=Blue} %ceruleanblue}

\begin{document}

\begin{frame}[label=model_earnings]{Earnings process}
    \begin{align*} 
         \tikzmarknode{a1}{ln(w_{j,t})}&=\tikzmarknode{a2}{\ln(w_{j,t-1})}-\tikzmarknode{a3}{\delta_1(h_{j,t-1}=0)}+\tikzmarknode{a4}{\epsilon_{j,t}}\\
         ln(w_1) &\sim N(\mu_,\sigma_1)\\
         \epsilon_{j,t} &\sim N(0,\sigma)
    \end{align*}
    \begin{tikzpicture}[remember picture, overlay]
    \only<2>{\draw[explain](a1)--++(-1,1)node[above]{This is item 1.};}
    \only<3>{\draw[explain](a2)--++(-.3,1)node[above]{This is item 2.};}
    \only<4>{\draw[explain](a3)--++(.3,1)node[above]{This is item 3.};}
    \only<5>{\draw[explain](a4)--++(1,1)node[above]{This is item 4.};}
    \end{tikzpicture}
\end{frame}

\end{document}
2
  • That's a really beautiful solution! When you define your coordinates for the node how do you know how much an unit is? And also how did you know it had to be compiled three times?
    – Michel
    Nov 6, 2022 at 5:56
  • 1
    @Michel: Units for coordinates are centimeters unless you specify otherwise. For example, you could use (.5in, 8mm) for a coordinate. Other acceptable units include pt, em, ex. See here for a more complete list. As for compiling, many LaTeX features require multiple compilations. See here for details. Note that you don't always have to compile 3 times—only when you make a change to the position of the marked contents.
    – Sandy G
    Nov 6, 2022 at 13:52
2

I have a somewhat working solution. I once needed to do something similar inside of tables. I can't find the original post where I found this solution, but it works reasonably well even inside of equations.

\documentclass[aspectratio=169]{beamer} 

\usepackage{tikz} 
\usetikzlibrary{arrows,calc}

\newcommand\tikzmark[2]{%
\tikz[remember picture,overlay] 
\node[inner sep=0pt,outer sep=2pt] (#1){#2};%
}

\newcommand\link[2]{%
\begin{tikzpicture}[remember picture, overlay, >=stealth, shorten >= 2pt]
  \draw[->,ultra thick] (#1) to  (#2);
\end{tikzpicture}%
}

\begin{document}

\begin{frame}[label=model_earnings]{Earnings process}
\tikzmark{a1}{Text here}
    \begin{align*} 
            &  \tikzmark{a2}{}ln(w_{j,t})=\ln(w_{j,t-1})-\delta 1(h_{j,t-1}=0)+\epsilon_{j,t}\\
        & ln(w_1) \sim N(\mu_,\sigma_1)\\
        & \epsilon_{j,t} \sim N(0,\sigma)
    \end{align*}
\link{a1}{a2}
\end{frame}  
\end{document}

It produces the following output:

Equation with notes

You can change the position of your notes using text alignment commands (ragged-right (\raggedright) ragged-left (\raggedleft) centred (\centering))

    \begin{frame}[label=model_earnings]{Earnings process}

    \centering\tikzmark{a3}{Or here}

    \begin{align*} 
            &  ln(w_{j,t})=\ln({w\tikzmark{a4}{}}_{j,t-1})-\delta 1(h_{j,t-1}=0)+\epsilon_{j,t}\\
        & ln(w_1) \sim N(\mu_,\sigma_1)\\
        & \epsilon_{j,t} \sim N(0,\sigma)
    \end{align*}
    \link{a3}{a4}
    \end{frame}

Centered label

If you want the arrowhead farther from the node just increase the shorten parameter defined at the \link command in the preamble.

4
  • Another solution similar has been posted here: link
    – Michel
    Oct 28, 2022 at 0:19
  • Thanks! How can I shorten the length of the arrow?
    – Giane
    Oct 28, 2022 at 19:56
  • Just increase the 'shorten' parameter (is currently set as 2 pt in the answer) in the definition of the \link command in the preamble as such: \newcommand\link[2]{% \begin{tikzpicture}[remember picture, overlay, >=stealth, shorten >= 10pt] \draw[->,ultra thick] (#1) to (#2); \end{tikzpicture}% }
    – Michel
    Oct 28, 2022 at 20:51
  • 1
    @Michel Instead of defining the tikzmark yourself, you could also load \usetikzlibrary{tikzmark} Oct 29, 2022 at 12:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .