1

I am trying to uncover parts of a PDF (available here) frame by frame (i.e., rectangle 1 on one frame, rectangle 2 on next frame and so on) using TikZ. However, I am having difficulty in referencing unconventional node positions. How do I reference positions shown by the red 'X' marks? I know the black 'X' marks can be accessed by north, south, north east, etc. How do I access the nodes marked in red 'X' marks such that I can uncover the PDF frame by frame?

Slide

enter image description here

MWE

\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}
nxkryptor
  • 1,478

1 Answers1

2

As pointed out in this answer, it is often advantageous to introduce a local coordinate system that has the dimensions of the picture. In these coordinates, the crosses have coordinates like (1/4,1/4), but we won't need them explicitly. Rather you can use the overlay-beamer-styles library (which as a "side-effect" avoid jumps) to get

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

enter image description here

Thanks for adding your picture! It works the same way for this picture. I also added nodes B-1,... B-8 which have the anchors you seem to be seeking, and added two blue crosses that illustrate how you may use them.

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

enter image description here