1

I would like to add arrows that point to different parts of an equation in a beamer presentation. I would like to highlight them iteratively. I used this question to attempt this, but the arrows don't appear at all. I tried excluding the {\small ... }% environment but it did not fix it, not did getting rid of the highlighting or messing with the distances. Thanks for any help.

\documentclass[12pt,dvipsnames]{beamer}

\usetheme{metropolis}

\usepackage{textgreek}
\usepackage{tikz}

\newcommand{\tikzmark}[1]{\tikz[baseline,remember picture] \coordinate (#1) {};}

\usepackage{booktabs}
\usepackage[scale=2]{ccicons}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{multicol}
\usepackage{minted}
\usepackage{hyperref}
\hypersetup{
    colorlinks = false,
    linkbordercolor = {blue}
}

\title{Something Interesting}
\author{Name}
\date{\today}

\begin{document}
\maketitle

\begin{frame}[fragile]{Title}

{\small  
\begin{equation*}
\textrm{
Y\textsubscript{gt} =
\textbeta\textsubscript{0} +
\alert<2>{\tikzmark{V}\textbeta\textsubscript{1} A\textsubscript{1}} +
\alert<3>{\tikzmark{Vp}\textbeta\textsubscript{2} B\textsubscript{2}} +
\alert<4>{\tikzmark{Vt}\textbeta\textsubscript{3} C\textsubscript{3}} +
\alert<5>{\textgamma\textsubscript{4} X\textsubscript{4}} +
\textepsilon\textsubscript{...}
}
\end{equation*}

\begin{tikzpicture}[overlay,remember picture]
    \node (Ve) [below of = V, node distance = 4 em, anchor=west]{\footnotesize \textsf{Distribution volume}};
    \draw[<-, in=180, out=-90] (V.south)++(.25em,-.5ex) to (Ve.west);

    \node (Vpe) [below of = Vp, node distance = 3 em, anchor=west] {\footnotesize \textsf{Volume water in plasma}};
    \draw[<-, in=180, out=-90] (Vp.south)++(.25em,-.5ex) to (Vpe.west);

    \node (Vte) [below of = Vt, node distance = 2 em, anchor=west] {\footnotesize \textsf{Volume water in tissue}};
    \draw[<-, in=180, out=-90] (Vt.south)++(.25em,-.5ex) to (Vte.west);

\end{tikzpicture}
}%

\end{frame}
\end{document}

4
  • 3
    My suggestion: do not re-invent tikzmark, use the package... ctan.org/pkg/tikzmark?lang=en
    – Rmano
    Commented Feb 10, 2021 at 16:57
  • Rmano's comment is spot-on. There are subtleties when using tikzmark with beamer that are sorted out in the tikzmark library and which the naive version can fail on, particularly when there are overlays involved. It does mean a slight change to your code as you have to use the pic cs:... coordinate syntax to refer to tikzmarks and this means that they can't be used with below of, but there are simple ways to adjust the syntax to get the same positioning. Commented Feb 15, 2021 at 21:27
  • Upon further investigation, the issue seems to be to do with the interaction between AMS's \text command (which \textrm is an alias for) and TikZ's remember picture key. Using \tikzmark from the tikzmark package avoids this issue, but using an actual node does not. Commented Feb 16, 2021 at 0:42
  • Thank you! This is really helpful. That makes a lot of sense.
    – BHudson
    Commented Feb 16, 2021 at 22:03

1 Answer 1

1

This is actually something of a subtle issue with how TikZ/PGF remembers nodes and pictures. When a node is defined, it remembers the unique id of the picture in which it was defined. If the key remember picture is set then the location of the origin of that picture is written to the aux file, meaning that the absolute position of the node on the page can be figured out.

However, in certain circumstances a tikzpicture might be processed multiple times and only one of these versions written out to the PDF. This happens when \mathchoice is involved. As the nodes are defined each time, the last version is the one that a given node is associated with. However, if the last version is not the one that is written to the PDF, its position on the page is not remembered and so it is not possible to use that node's absolute position on the page.

Elsewhere, Heiko Oberdieck gave an answer to a related question using \label to write stuff to the aux file only for the version that is typeset and using that to figure out which version was set. Using the same idea, I've adapted \tikzmarknode so that it can figure out which tikzpicture was actually used and so associate its nodes with the right id.

(The mechanism for this can be used in other tikzpictures if so desired.)

Note that \tikzmark itself doesn't suffer from this as it doesn't use nodes anymore. So this only affects \tikzmarknode.

In your code, this problem enters the picture (ha ha) through the \textrm command. In the presence of the amsmath package, this is actually \text, and this uses \mathchoice internally.

I've uploaded a new version of tikzmark to github to implement this. Once I've stress-tested it then I'll upload it to CTAN.

Here's a fixed version of your code:

\documentclass[12pt,dvipsnames]{beamer}
%\url{https://tex.stackexchange.com/q/582811/86}

\usetheme{metropolis}

\usepackage{textgreek}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

%\newcommand{\tikzmark}[1]{\tikz[baseline,remember picture] \coordinate (#1) {};}

\usepackage{booktabs}
\usepackage[scale=2]{ccicons}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{multicol}
\usepackage{minted}
\usepackage{hyperref}
\hypersetup{
    colorlinks = false,
    linkbordercolor = {blue}
}

\title{Something Interesting}
\author{Name}
\date{\today}

\begin{document}
\maketitle

\begin{frame}[fragile]{Title}

{\small  
\begin{equation*}
\textrm{
Y\textsubscript{gt} =
\textbeta\textsubscript{0} +
\alert<2>{\tikzmarknode{V}\textbeta\textsubscript{1} A\textsubscript{1}} +
\alert<3>{\tikzmarknode{Vp}\textbeta\textsubscript{2} B\textsubscript{2}} +
\alert<4>{\tikzmarknode{Vt}\textbeta\textsubscript{3} C\textsubscript{3}} +
\alert<5>{\textgamma\textsubscript{4} X\textsubscript{4}} +
\textepsilon\textsubscript{...}
}
\end{equation*}

\begin{tikzpicture}[overlay,remember picture]
    \node (Ve) [below of = V, node distance = 4 em, anchor=west]{\footnotesize \textsf{Distribution volume}};
    \draw[<-, in=180, out=-90] (V.south)++(.25em,-.5ex) to (Ve.west);

    \node (Vpe) [below of = Vp, node distance = 3 em, anchor=west] {\footnotesize \textsf{Volume water in plasma}};
    \draw[<-, in=180, out=-90] (Vp.south)++(.25em,-.5ex) to (Vpe.west);

    \node (Vte) [below of = Vt, node distance = 2 em, anchor=west] {\footnotesize \textsf{Volume water in tissue}};
    \draw[<-, in=180, out=-90] (Vt.south)++(.25em,-.5ex) to (Vte.west);

\end{tikzpicture}
}%

\end{frame}
\end{document}

And a relevant frame:

fixed tikzmarknode in mathchoice

2
  • Thank you! This is really helpful and makes a lot of sense. I really appreciate you taking the time to answer and to commit to GitHub! Thanks so much for your work on this - it must be a huge commitment! Thanks again for your attention to my question.
    – BHudson
    Commented Feb 16, 2021 at 22:03
  • 1
    @BHudson I'm always interested in how my packages do and don't work, and when they don't work then I want to know why! So thank you for asking the question and giving me the opportunity to improve tikzmark. Commented Feb 16, 2021 at 22:53

You must log in to answer this question.

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