1

I want to be able to "gray" out sections of my beamer lectures (based on some expiration time predicate). With some very useful help from this forum I'm almost there. My solution is to define a new "expire" environment and place the text (could be math equations) in a TikZ node within this environment. Sadly the node consumes more height than I would like. In the slide below I would ideally like the grayed out box to be one line high. Is this fixable?

Many thanks. grayed out single equation

My MWE:

\documentclass{beamer}

\usepackage{environ}            % for the 'expire' idea
\usepackage{tikz}
\NewEnviron{expire}{%
  \begin{tikzpicture}
    \node [fill=gray!40, inner sep=0pt, inner ysep=0pt]{%  %gray!40
      \begin{minipage}{\textwidth}
        {\color{black}
          \BODY
        }
      \end{minipage}
    };
  \end{tikzpicture}
}

\begin{document}

\begin{frame} \frametitle{Exponents}
\[ x^{a}x^{b} = x^{a+b} \]
\[ \frac{x^a}{x^b} = x^{a-b} \]
\begin{expire}
\[(x^{a})^{b} = x^{ab}\]
\end{expire}
\[ x^n + x^n = 2x^n {\color{red} \neq} x^{2n} \]
\end{frame}

\end{document}
  • 1
    Remove the \begin{minipage}{\textwidth}{\color{black} and use options [align=center,minimum width=\textwidth,text=black] on the node – percusse Jan 18 '18 at 10:44
  • Do I not need the minipage in the case that I want to boxify a math environment, say? By replacing {\color{black}...} with [...,text=black...] the box has become neater but there's still a noticeable gap above/below it. Perhaps this is unavoidable... – healyp Jan 18 '18 at 14:46
  • align=center forces TikZ to use a minipage already to typeset. The other space comes from the above and below math skips – percusse Jan 18 '18 at 14:47
  • 1
    Use \textcolor{red}{\neq}. – egreg Jan 19 '18 at 7:17
4

As percusse said, you don't need a minipage. Moreover, I would use gather*:

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand{\expire}[1]{%
  \tikz{%
    \node[fill=gray!40, inner xsep=0pt, outer sep=0pt,
        gray!40, text=black, minimum width=\textwidth]{$#1$};}}

\begin{document}

\begin{frame}
\frametitle{Exponents}
\begin{gather*}
x^{a}x^{b} = x^{a+b}\\
\frac{x^a}{x^b} = x^{a-b}\\
\expire{(x^{a})^{b} = x^{ab}}\\[-4pt]% or any other dimension you prefer
x^n + x^n = 2x^n {\color{red} \neq} x^{2n} 
\end{gather*}
\end{frame}

\end{document}

enter image description here

Another solution could be a TikZ matrix of math nodes with a node style to put before the row you want to be gray (see |[expire]| here):

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{%
    expire/.style={
        fill=gray!40,
        text=black,  
    }
}

\begin{document}
\begin{frame}
\frametitle{Exponents}
    \begin{center}
        \begin{tikzpicture}
            \matrix[matrix of math nodes, nodes={inner xsep=0pt,
                minimum width=\textwidth}] {
                x^{a}x^{b} = x^{a+b}\\
                \dfrac{x^a}{x^b} = x^{a-b}\\
                |[expire]|(x^{a})^{b} = x^{ab}\\
                x^n + x^n = 2x^n {\color{red} \neq} x^{2n}\\
            };
        \end{tikzpicture}
    \end{center}
\end{frame}
\end{document}

enter image description here

If you want both text and math:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{%
    expire/.style={
        fill=gray!40,
        text=black,  
    }
}

\begin{document}
\begin{frame}
\frametitle{Exponents}
    \begin{center}
        \begin{tikzpicture}
            \matrix[matrix of nodes, nodes={inner xsep=0pt,
                minimum width=\textwidth}] {
                Here something\\
                |[expire]|not in math mode\\
                $x^{a}x^{b} = x^{a+b}$\\
                $\dfrac{x^a}{x^b} = x^{a-b}$\\
                |[expire]|$(x^{a})^{b} = x^{ab}$\\
                $x^n + x^n = 2x^n {\color{red} \neq} x^{2n}$\\
            };
        \end{tikzpicture}
    \end{center}
\end{frame}
\end{document}

enter image description here

  • Thanks but both of those solutions expect a math argument. I would like to be able to place /arbitrary/ text in the box and have it disappear according to some predicate. – healyp Jan 19 '18 at 10:35
  • 1
    @healyp That's not a problem, use a matrix of nodes instead of a matrix of math nodes and put $... $ in the node which have math text. – CarLaTeX Jan 19 '18 at 10:38
  • @healyp See my edit. – CarLaTeX Jan 19 '18 at 13:37
3

with simple tabular and \rowcolor

\documentclass[table]{beamer}
\usepackage{amsmath}

\begin{document}
\begin{frame}
\frametitle{Exponents}
\[  \setlength\tabcolsep{1pt}
    \renewcommand\arraystretch{1.3}
\begin{tabular}{>{\raggedleft$}p{0.475\linewidth}<{$} c >{$}p{0.475\linewidth}<{$}}
x^{a}x^{b}      & = & x^{a+b}\\
\frac{x^a}{x^b} & = & x^{a-b}\\[1pt]
\rowcolor{cyan!40}
(x^{a})^{b}     & = & x^{ab}\\
x^n + x^n       & = & 2x^n {\color{red} \neq} x^{2n}
\end{tabular}
\]
\end{frame}
\end{document}

enter image description here

2

Maybe the tcolorbox package could be an alternative:

\documentclass{beamer}
\usepackage[most]{tcolorbox}

\newtcolorbox{expire}{colback=gray!40!white,boxrule=0mm,arc=0mm,top=0.25mm,bottom=0.25mm}

\begin{document}

\begin{frame} \frametitle{Exponents}
\[ x^{a}x^{b} = x^{a+b} \]
\[ \frac{x^a}{x^b} = x^{a-b} \]
\begin{expire}
\[(x^{a})^{b} = x^{ab}\]
\end{expire}
\[ x^n + x^n = 2x^n {\color{red} \neq} x^{2n} \]
\end{frame}

\end{document}

enter image description here

  • Nice but the alignment is lost. – Denis Jan 19 '18 at 14:02

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.