3

I currently have the following figure and code

enter image description here

\documentclass{beamer}
\usepackage{tikz}

\begin{document}

\begin{frame}
     \begin{tikzpicture}[remember picture, overlay]
            \node (image) at (current page.center) {\includegraphics[scale=0.5]{tj}};
            \node[align=center, yshift = 1.5cm, xshift = 4cm] at (current page.center) {Tom};
            \node[align=center, yshift = -1.5cm, xshift = 4cm] at (current page.center) {Jerry};
        \end{tikzpicture}
\end{frame}


\end{document}

I want to draw two arrows from Tom and Jerry to the location of their respective faces. I know there is a way to accomplish this using Tikz node. But I am not sure how to do this without compilation errors.

enter image description here]2

Can someone help me achieve this effect?

5

As discussed in this great answer, it is convenient to introduce a local coordinate system on top of the image.

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
% based on https://tex.stackexchange.com/a/9562/121799
\begin{frame}
\frametitle{\only<1>{Draw a coordinate system on top of the image}%
\only<2>{Draw the text nodes (with some generous inner sep)}%
\only<3>{Connec the text nodes to the points}%
\only<4>{Remove the grid}%
}
     \begin{tikzpicture}
            \node (image) at (current page.center) {\includegraphics[scale=0.5]{tj}};
            \begin{scope}[shift={(image.south west)},x={(image.south east)},y={(image.north west)}]
            \only<1-3>{
             \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
             \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
             \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }            
             }
             \only<2->{
             \node[fill=white,font=\large,inner sep=4pt] (Tom) at (0.9,0.74) {Tom};
             \node[fill=white,font=\large,inner sep=4pt] (Jerry) at (0.9,0.23) {Jerry};
             }
             \only<3->{
             \draw[ultra thick,red] (Tom) -- (0.49,0.42);
             \draw[ultra thick,red] (Jerry) -- (0.66,0.23);
             }
            \end{scope}

        \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

Of course, in the end you may want to erase the grid.

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
% based on https://tex.stackexchange.com/a/9562/121799
\begin{frame}
     \begin{tikzpicture}
            \node (image) at (current page.center) {\includegraphics[scale=0.5]{tj}};
            \begin{scope}[shift={(image.south west)},x={(image.south east)},y={(image.north west)}]
             \node[fill=white,font=\large,inner sep=4pt,align=center] 
                (Tom) at (0.9,0.74) {Bad\\ Tom};
             \node[fill=white,font=\large,inner sep=4pt,align=center] (Jerry) at (0.9,0.23) 
                {Tasty\\ Jerry};
             \draw[ultra thick,red,-stealth] (Tom) -- (0.49,0.42);
             \draw[ultra thick,red,-stealth] (Jerry) -- (0.66,0.23);
            \end{scope}     
        \end{tikzpicture}
\end{frame}
\end{document}

enter image description here

Note that you were using remember picture,overlay without actually using it. As long as you do not really make use of it I recommend dropping it. I also added the arrow heads and multiline nodes, as asked in the comments.

| improve this answer | |
  • Do you know if there is a way to easily put an arrow at the end <- – Shamisen Expert Nov 12 '18 at 19:22
  • @ShamisenExpert Sure, just replace \draw[ultra thick,red] (Tom) -- (0.49,0.42); \draw[ultra thick,red] (Jerry) -- (0.66,0.23); by \draw[ultra thick,red,-stealth] (Tom) -- (0.49,0.42); \draw[ultra thick,red,-stealth] (Jerry) -- (0.66,0.23);. (Will decouple now for a while.) – user121799 Nov 12 '18 at 19:24
  • Ok. I wonder if there is a way to write {Bad \\ Tom} i.e., Tom beneath Bad. I tried to do this but received errors. – Shamisen Expert Nov 12 '18 at 20:13
  • @ShamisenExpert You can definitely have mutliline text in nodes, you only need to specify the alignment. I added examples with align=center to the answer. – user121799 Nov 12 '18 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.