1

I am trying to put overlay arrows to describe parts of a mathematical expression using tikz as below. However, I am unable to position the arrows properly.

All I am getting is this: enter image description here

How can I place them correctly to point the three parts of the expression to the labels AAAA, BBBBBBB and CCCCCCCCCC?

\documentclass{beamer}

\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\begin{document}
    \begin{frame}
        \frametitle{Hello World}
        \begin{block}{Formulation}
        \tikzstyle{na} = [baseline=-.5ex]
                \vspace{0.6em}
                \begin{itemize}
                    \item Equation is 

                    \begin{equation}
                    \tikz[baseline]{\node[rounded corners,
                        fill=blue!10,draw=blue!30,anchor=base] (t12) {$AAAAA$};}
                    +p\,\,
                    \tikz[baseline]{\node[rounded corners,
                        fill=green!10,draw=green!30, anchor=base] (t22) {$BBBBB$};
                    }+q\,\,
                    \tikz[baseline]{\node[rounded corners,
                        fill=orange!10,draw=orange!30,anchor=base] (t32) {$CCCCCCC$};
                    }\nonumber
                    \end{equation}
                    AAAA\tikz[na] \node[coordinate] (n12) {}; \hfill
                      BBBBBBB\tikz[na] \node[coordinate] (n22) {};\hfill
                      \tikz[na] \node[coordinate] (n32) {};CCCCCCCCCC \\

                    \begin{tikzpicture}[overlay]
                    \path[->]<1-> (n12) edge[bend right](t12);
                    \path[->]<1-> (n22.north) edge[bend right](t22);
                    \path[->]<1-> (n32.west) edge[bend left](t32);
                    \end{tikzpicture}

               \end{itemize}                    
            \end{block}
    \end{frame}
\end{document}

Thanks in advance.

7
  • 2
    You need \tikz[remember picture,... throughout, and \begin{tikzpicture}[remember picture,overlay] where the arrows are drawn., Commented Aug 14, 2017 at 7:50
  • @TorbjørnT. Is the first \tikz[remember... to be applied everywhere, e.g. in the \tikz[na], etc also ? I will try soon. Thanks.
    – ffslq
    Commented Aug 14, 2017 at 7:55
  • Yes, you have multiple \tikz commands, and all of those need to have remember picture as an option. Commented Aug 14, 2017 at 7:56
  • Thanks! It simply worked. But I remember, earlier, more than a year ago, I used it without any remember and it worked then.
    – ffslq
    Commented Aug 14, 2017 at 7:57
  • I seriously doubt that, to be honest, but it could have been hidden away in a style. Commented Aug 14, 2017 at 8:31

1 Answer 1

3

In order for TikZ to be able to properly reuse coordinates from other tikzpictures, you need to have remember picture in the options for the environment/\tikz macro.

Hence, if you just add remember picture as an option to all your \tikz macros, and the tikzpicture enviroment, your code works fine. Or alternatively, say \tikzset{every picture/.append style={remember picture}} inside the frame.

enter image description here

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}

\begin{document}
    \begin{frame}
        \frametitle{Hello World}
        \begin{block}{Formulation}
                \vspace{0.6em}
                \tikzset{
                    na/.style={baseline=-.5ex},
                    % every picture/.append style={remember picture} % alternative to having remember picture everywhere below
                }
                \begin{itemize}
                    \item Equation is 

                    \begin{equation}
                    \tikz[baseline,remember picture]{\node[rounded corners,
                        fill=blue!10,draw=blue!30,anchor=base] (t12) {$AAAAA$};}
                    +p\,\,
                    \tikz[baseline,remember picture]{\node[rounded corners,
                        fill=green!10,draw=green!30, anchor=base] (t22) {$BBBBB$};
                    }+q\,\,
                    \tikz[baseline,remember picture]{\node[rounded corners,
                        fill=orange!10,draw=orange!30,anchor=base] (t32) {$CCCCCCC$};
                    }\nonumber
                    \end{equation}
                    AAAA\tikz[na,remember picture] \node[coordinate] (n12) {}; \hfill
                      BBBBBBB\tikz[na,remember picture] \node[coordinate] (n22) {};\hfill
                      \tikz[na,remember picture] \node[coordinate] (n32) {};CCCCCCCCCC \\

                    \begin{tikzpicture}[overlay,remember picture]
                    \path[->]<1-> (n12) edge[bend right](t12);
                    \path[->]<1-> (n22.north) edge[bend right](t22);
                    \path[->]<1-> (n32.west) edge[bend left](t32);
                    \end{tikzpicture}

               \end{itemize}                    
            \end{block}
    \end{frame}
\end{document}
2
  • Hi! Could you kindly tell me then, an use case of when remember picture is not used? It seems to me that this flag is always required in practice. Thanks.
    – ffslq
    Commented Aug 15, 2017 at 17:24
  • @ffslq On the contrary, remember picture is the exception. It's used whenever you need to reference a coordinate in a different tikzpicture. So it's not used when you don't need that, which is most diagrams. Commented Aug 15, 2017 at 17:33

You must log in to answer this question.

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