3

I am trying to incrementally reveal one node at a time in a figure while preserving the text alignment across two nodes.

Here is an example:

\documentclass[presentation]{beamer}
\usepackage{tikz}
\usepackage{transparent}
\usepackage{xcolor}

\tikzset{
  invisible/.style={opacity=0},
  visible on/.style={alt={#1{}{invisible}}},
  alt/.code args={<#1>#2#3}{%
    \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
  },
}
\newcommand{\x}{{\color{blue}\ensuremath{x}}}

\begin{document}
\begin{frame}
\begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{scope}
        \node[visible on=<1>] (b00) at (0, 0) {
            {\transparent{0}$3 \cdot ($}
            $f(\x)$
            {\transparent{0}$) + 5$}
            {$=$}
            {\transparent{0}$3 \cdot ($}
            $g(\x) * h(\x)$
            {\transparent{0}$) + 5$}
        };
        \node[visible on=<2>] (b00) at (0, 0) {
            {\transparent{0.5}$3 \cdot ($}
            $f(\x)$
            {\transparent{0.5}$) + 5$}
            {$=$}
            {\transparent{0.5}$3 \cdot ($}
            $g(\x) * h(\x)$
            {\transparent{0.5}$) + 5$}
        };
      \end{scope}
    \end{tikzpicture}
\end{figure}
\end{frame}
\end{document}

I am trying to get: f(x) = g(x) ∗ h(x) in the first slide and 3·(f(x)) + 5 = 3.(g(x)∗h(x)) + 5 in the second slide while preserving the alignment of f(x) = g(x) ∗ h(x) across both slides.

Here is the desired result

Is there a clean way to do this in TIKZ/PGF?

2
  • I guess you can consult the math spacing table (e.g. TeXbook page 170) and insert appropriate \math⟨type⟩ at appropriate places to get the correct spacing. there's an example in tex.stackexchange.com/questions/102254/… that one for color but the principle is about the same
    – user202729
    Aug 6 at 8:30
  • 1
    you visible/invisible code doesn't work. Why don't you use simply \node<1> and \node<2>? Aug 6 at 8:58

2 Answers 2

4

You can let beamer do the uncovering for you:

\documentclass[presentation]{beamer}
\usepackage{tikz}
\setbeamercovered{transparent}

\newcommand{\x}{{\color{blue}\ensuremath{x}}}

\setbeamercovered{still covered={\opaqueness<1>{30}\opaqueness<2->{0}}}

\begin{document}
\begin{frame}<-2>
\begin{figure}
    \begin{tikzpicture}
      \begin{scope}
        \node (b00) at (0, 0) {
          $
            \uncover<3->{3 \cdot (}
            f(\x)
            \uncover<3->{) + 5}
            =
            \uncover<3->{3 \cdot (}
            g(\x) * h(\x)
            \uncover<3->{) + 5}
          $
        };
      \end{scope}
    \end{tikzpicture}
\end{figure}
\end{frame}
\end{document}

enter image description here

2

Welcome to TeX.SX! You can simply color parts of the math. There is no need to seperate it that much. Use begingroup and \endgroup (like suggested in this answer in order to keep the spacing correct even for binary operators (which is not a problem in your case, anyways).

I would suggest that you use the library overlay-beamer-styles for TikZ instead of providing your own visible on style. In the following code I added a slide without color to ehow that the spacing is correct.

\documentclass[presentation]{beamer}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}

%\newcommand{\x}{{\color{blue}\ensuremath{x}}}

\newcommand{\makeblue}[1]{\begingroup\color{blue}\ensuremath{#1}\endgroup}
\newcommand{\maketransparent}[2][0]{\begingroup\color{black!#1}\ensuremath{#2}\endgroup}

\begin{document}
\begin{frame}
\begin{figure}
    \centering
    \begin{tikzpicture}
      \begin{scope}
        \node[visible on=<1>] (b00) at (0, 0) {
            $\maketransparent{3 \cdot (}
            f(\makeblue{x})
            \maketransparent{) + 5}
            =
            \maketransparent{3 \cdot (}
            g(\makeblue{x}) * h(\makeblue{x})
            \maketransparent{) + 5}$
        };
        \node[visible on=<2>] (b00) at (0, 0) {
            $\maketransparent[50]{3 \cdot (}
            f(\makeblue{x})
            \maketransparent[50]{) + 5}
            =
            \maketransparent[50]{3 \cdot (}
            g(\makeblue{x}) * h(\makeblue{x})
            \maketransparent[50]{) + 5}$
        };
        \node[visible on=<3>] (b00) at (0, 0) {
            $3 \cdot (f(x)) + 5 = 3 \cdot (g(x) * h(x)) + 5$
        };
      \end{scope}
    \end{tikzpicture}
\end{figure}
\end{frame}
\end{document}

enter image description here


A more flexible command could be:

\NewDocumentCommand{\maketransparent}{ O{0} O{black} m }{\begingroup\color{#2!#1}\ensuremath{#3}\endgroup}

It takes three arguments, two of which are optional and can be used to set the color and the opacity. The third argument takes the stuff that should be colored. A few examples:

\maketransparent{a}           % print an invisible a

\maketransparent[25]{a}       % print an a with 25 % opacity

\maketransparent[25][red]{a}  % print a red a with 25 % opacity
2
  • Is there a way to get \maketransparent working with all colors? For instance, \maketransparent{) \begingroup\color{red}+ 5\endgroup} does not work.
    – untitled
    Aug 6 at 15:32
  • @untitled No, you would need to adjust the macro for that. See my edit. Aug 7 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.