Beamer:使用 tikzpicture 将文本放在图像的四边,但图片和文本同时移动

Beamer:使用 tikzpicture 将文本放在图像的四边,但图片和文本同时移动

我正在尝试在图像周围放置一些文字,如下所示: 在此处输入图片描述

这是使用 tikzpicture 完成的。

然而,一旦我改变(x,y)

        \node[align=center] at (x,y) {left};

框和文本同时移动!

我知道这可能与“align=center”选项有关,但我不确定如何更改它以使它们不同时移动。

有人可以帮忙吗?

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\begin{document}

\begin{frame}
     \begin{tikzpicture}
            \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[scale=0.5]{box}};
            \node[align=center] at (-2,5) {up};
            \node[align=center] at (-2,1) {down};
            \node[align=center] at (1,-1) {left};
            \node[align=center] at (3,-1) {right};
        \end{tikzpicture}
\end{frame}


\end{document}

答案1

您可以根据页面定位元素:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\begin{document}

\begin{frame}
     \begin{tikzpicture}[remember picture, overlay]
            \node (image) at (current page.center) {\includegraphics[scale=0.5]{example-image}};
            \node[align=center,yshift=3cm] at (current page.center) {up};
            \node[align=center,yshift=-3cm] at (current page.center) {down};        
            \node[align=center,xshift=-4cm] at (current page.center) {right};   
            \node[align=center,xshift=4cm] at (current page.center) {left};                               
        \end{tikzpicture}
\end{frame}


\end{document}

或者你可以放置一个足够大的隐形正方形来包含图像的所有元素:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\begin{document}

\begin{frame}
     \begin{tikzpicture}
        \path (-4,-3.5) rectangle (4,3.5);
            \node (image) at (0,0) {\includegraphics[scale=0.5]{example-image}};
            \node[align=center] at (0,3) {up};
            \node[align=center] at (0,-3) {down};
            \node[align=center] at (-3.5,0) {left};
            \node[align=center] at (3.5,0) {right};
        \end{tikzpicture}
\end{frame}


\end{document} 

如果您不介意标签伸出到边缘,您也可以将它们排除在图像的边界框之外:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\begin{document}

\begin{frame}
     \begin{tikzpicture}
            \node (image) at (0,0) {\includegraphics[scale=0.5]{example-image}};
            \begin{pgfinterruptboundingbox}
            \node[align=center] at (0,3) {up};
            \node[align=center] at (0,-3) {down};
            \node[align=center] at (-3.5,0) {left};
            \node[align=center] at (3.5,0) {right};
            \end{pgfinterruptboundingbox}
        \end{tikzpicture}
\end{frame}


\end{document}

相关内容