Use different scale for one tikz scope in two slides in beamer

beamerpdftextikz-nodetikz-pgfxetex

Basic Info

I use xelatex (even though the same things happen while using pdflatex) and TeX Live 2019 in an MBP.

Original Problems

I want to use different scales for the same tizk scope in different slides. To give an example, I want to combine the following two scopes into one while still keeping the functionality of changing the scale from slide 1 to 2. The real node is much more complicated than this, so I don't want to copy and paste.

\documentclass[aspectratio=169]{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
    \begin{tikzpicture}[remember picture, overlay]
        \begin{scope}[scale=1,transform shape]
             \node<1> (test) at (current page) [circle,very thick, draw=black, fill=white, text width=0.3\textwidth, align=center, font=\huge\bfseries , inner sep=-1ex] {TEST};
        \end{scope}

        \begin{scope}[scale=2,transform shape]
            \node<2> (test) at (current page) [circle,very thick, draw=black, fill=white, text width=0.3\textwidth, align=center, font=\huge\bfseries , inner sep=-1ex] {TEST};
       \end{scope}
    \end{tikzpicture}
\end{frame}
\end{document}

I have tried the following strategy

\begin{scope}[\alt<1>{scale=1}{scale=2},transform shape]
    \node<1-2> ...
\begin{scope}[scale=\alt<1>{1}{2},transform shape]
    \node<1-2> ...
\begin{scope}\alt<1>{[scale=1,transform shape]}{[scale=2,transform shape]}
    \node<1-2> ...

But the first two give me some wrong messages and stop compiling and the last one simply doesn't work.

So, how to make this work?

Extensions

Actually, this question applies to nearly all the arguments of tikzpicture inside square brackets []. For example, what should I do if I want to change the font from \huge to \normalsize while the slide number change from 1 to 2?

Best Answer

Here's a solution using the TikZ library overlay-beamer-styles which defines a variety of useful keys, most relevant being:

alt=<overlay specification>{first styles}{second styles}

which applies the first styles when the overlay specification is met and the second styles when not. In your code, this could look like:

\documentclass[aspectratio=169]{beamer}
%\url{https://tex.stackexchange.com/q/611127/86}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}
\begin{document}
\begin{frame}<1-2> % <- needed to force a second frame
\begin{tikzpicture}[remember picture, overlay]
\begin{scope}[
  alt=<1>{scale=1}{scale=2}, % <- overlay-aware styles
  transform shape]
\node[
  alt=<1>{at=(current page)}{at=(current page.north)},
  circle,
  very thick,
  draw=black,
  fill=white,
  text width=0.3\textwidth,
  align=center,
  font=\huge\bfseries ,
  inner sep=-1ex
]
(test)  {TEST};
\end{scope}

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

This only works for things set in keys, so to use it for positioning a node then you need to use the at key rather than the inline at syntax, as demonstrated above.

The <1-2> on the \begin{frame} is because and \alt by itself doesn't force a second overlay; if other material on the slide referred to more overlays then that wouldn't be necessary.