如何在 Beamer 中将浮动文本中的箭头绘制到图片中?

如何在 Beamer 中将浮动文本中的箭头绘制到图片中?

我目前有以下图和代码

在此处输入图片描述

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

我想从汤姆和杰瑞画出两支箭头指向他们各自脸部的位置。我知道有一种方法可以使用 Tikz 节点来实现这一点。但我不确定如何在不出现编译错误的情况下做到这一点。

在此处输入图片描述]2

有人能帮助我实现这个效果吗?

答案1

正如所讨论的这个很好的答案,可以方便的在图像上引入局部坐标系。

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

在此处输入图片描述

当然,最后你可能想要删除网格。

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

在此处输入图片描述

请注意,您使用的是remember picture,overlay但实际上并未使用它。只要您没有真正使用它,我建议将其删除。我还添加了箭头和多线节点,如评论中所要求的那样。

相关内容