TikZ 节点位置

TikZ 节点位置

我正在尝试发现 PDF 的某些部分(可用这里) 逐帧绘制(即,矩形 1 在一帧上,矩形 2 在下一帧上,依此类推)TikZ。但是,我在引用非常规节点位置时遇到困难。如何引用红色“X”标记显示的位置?我知道可以通过北、南、东北等访问黑色“X”标记。我如何访问标有红色“X”标记的节点,以便可以逐帧发现 PDF?

滑动

在此处输入图片描述

平均能量损失

\documentclass{beamer}
\usepackage{tikz}

\begin{document}
    \begin{frame}
        \begin{tikzpicture}
            \node[anchor=south west,inner sep=0] (B) at (4,0) {\includegraphics[height=0.72\textheight,keepaspectratio]{tikz_rectangle.pdf}};
            \only<1>
            {
            \fill [draw=none, fill=white, fill opacity=0.8] (B.north west) -- (B.north east) -- (B.south east) -- (B.south west) -- (B.north west) -- cycle;
            }
            \only<2>
            {
            \fill [draw=none, fill=white, fill opacity=0.0] (B.north west) -- (B.north east) -- (B.south east) -- (B.south west) -- (B.north west) -- cycle;
            }
            \only<3>
            {
            \fill [draw=none, fill=white, fill opacity=0.8] (B.north) -- (B.north east) -- (B.322) -- (B.218) -- (B.140) -- (B.110) -- (B.north) -- cycle;
            }
            \only<4>
            {
            \fill [draw=none, fill=white, fill opacity=0.8] (B.north) -- (B.north east) -- (B.322) -- (B.218) -- (B.west) -- (B.150) -- (B.center) -- (B.110) -- cycle;
            \fill [draw=none, fill=white, fill opacity=0.8] (B.120) -- (B.center) -- (B.110) -- cycle;          
            }
        \end{tikzpicture}
    \end{frame}
\end{document}

答案1

正如指出的那样这个答案,引入具有图片尺寸的局部坐标系通常是有利的。在这些坐标中,十字具有像 这样的坐标(1/4,1/4),但我们不需要它们。相反,您可以使用overlay-beamer-styles库(作为“副作用”,避免跳跃)来获得

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\begin{document}
    \begin{frame}
        \begin{tikzpicture}
            \node[anchor=south west,inner sep=0,anchor=south west] (B) at (0,0)
        {\includegraphics[height=0.72\textheight,width=0.36\textheight]{example-image-a}};
        \begin{scope}[x={(B.south east)},y={(B.north west)}]
         \foreach \X in {1,...,8}
         {\fill[white,visible on=<1-\X>] ({mod(\X-1,2)/2},{1-int((\X-1)/2)/4}) rectangle ++ 
         (1/2,-1/4);
         \draw[visible on=<\the\numexpr\X+1\relax->] ({mod(\X-1,2)/2},{1-int((\X-1)/2)/4}) rectangle ++ 
         (1/2,-1/4) node[midway]{\X}; }
         \path[visible on=<9>];
        \end{scope}
        \end{tikzpicture}
    \end{frame}
\end{document}

在此处输入图片描述

感谢您添加图片!此图片的工作方式相同。我还添加了节点B-1……B-8其中有您似乎正在寻找的锚点,并添加了两个蓝色十字以说明如何使用它们。

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles,shapes.misc}
\begin{document}
 \begin{frame}
  \begin{tikzpicture}
   \node[anchor=south west,inner sep=0] (B) at (0,0) {\includegraphics[height=0.72\textheight,keepaspectratio]{tikz_rectangle.pdf}};
    \path (B.north east);
    \pgfgetlastxy{\myx}{\myy}
    \begin{scope}[x={(B.south east)},y={(B.north west)}]
     \foreach \X in {1,...,8}
     {\node[minimum width=0.5*\myx,minimum height=0.25*\myy,
       anchor=north west,inner sep=0pt,outer sep=0pt] (B-\X) at ({mod(\X-1,2)/2},{1-int((\X-1)/2)/4})
      {};}
     \foreach \X in {1,...,8}
     {\fill[white,visible on=<1-\X>] ({mod(\X-1,2)/2},{1-int((\X-1)/2)/4}) rectangle ++ 
     (1/2,-1/4); }
     \path[visible on=<9>];
    \end{scope}
    %\examples
    \node[cross out,draw=blue,inner sep=2pt] at (B-1.south){};
    \node[cross out,draw=blue,inner sep=2pt] at (B-4.west){};
  \end{tikzpicture}
 \end{frame}
\end{document}

在此处输入图片描述

相关内容