Beamer:有没有一种优雅的方法可以将数学与各种环境叠加?

Beamer:有没有一种优雅的方法可以将数学与各种环境叠加?

我一直使用 overprint 环境来一次显示数学环境的一个元素。问题是,我必须为每张幻灯片重复数学运算。有没有更优雅的方式来做到这一点?这是我的示例代码:

\documentclass[dvipsnames,table,aspectratio=169]{beamer}    % 16:9 aspect ratio
%\usetheme{Monterey}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multirow,multicol}  % Allows multirows in equations and multicolumns in slides
\usepackage{setspace}   % Allows double spacing with the \doublespacing command

% Change text color
\newcommand{\black}[1]{\textcolor{black}{#1}}
\newcommand{\red}[1]{\textcolor{red}{#1}}
\newcommand{\lightgray}[1]{\textcolor{lightgray}{#1}}

% Bold math variables
\newcommand{\fb}{\mathbf{f}}
\newcommand{\xb}{\mathbf{x}}
\newcommand{\hb}{\mathbf{h}}
\newcommand{\ub}{\mathbf{u}}
\newcommand{\eb}{\mathbf{e}}
\newcommand{\pb}{\mathbf{p}}
\newcommand{\qb}{\mathbf{q}}
\newcommand{\gb}{\mathbf{g}}
\newcommand{\Xb}{\mathbf{X}}
\newcommand{\Zb}{\mathbf{Z}}
\newcommand{\lambdab}{\boldsymbol{\lambda}}
\newcommand{\nub}{\boldsymbol{\nu}}
\newcommand{\mub}{\boldsymbol{\mu}}
\newcommand{\chib}{\boldsymbol{\chi}}


\begin{frame}{Background}{Standard Optimal Control}
    \begin{itemize}
        \item Standard optimal control problem \cite{ross2015primer}
    \end{itemize}
    \setstretch{1.5}
    \vspace{-1cm}
    \begin{overprint}
        \onslide<1>
        \begin{gather*}
            \xb(t) = (x_1(t),\ldots,x_{N_x}(t)) \in \mathbb{R}^{N_x}, \quad
            \ub(t) = (u_1(t),\ldots,u_{N_u}(t)) \in \mathbb{R}^{N_u} \\
            (\textsf{P}) \left\lbrace
            \begin{array}{l l}
                \textsf{Minimize} & J[\xb(\cdot),\ub(\cdot),t_0,t_f] = \\
                & E(\xb_0,\xb_f,t_0,t_f) + \displaystyle\int_{t_f}^{t_0}F(\xb(t),\ub(t),t)\,dt\\
                \textsf{Subject to}  & \dot{\xb}(t) = \fb(\xb(t),\ub(t),t) \\
                & \eb^L \leq \eb(\xb_0,\xb_f,t_0,t_f) \leq \eb^U \\
                & \hb^L \leq \hb(\xb(t),\ub(t),t) \leq \hb^U 
            \end{array}
            \right.
        \end{gather*}
        \onslide<2>
        \lightgray{\begin{gather*}
            \black{\xb(t) = (x_1(t),\ldots,x_{N_x}(t)) \in \mathbb{R}^{N_x}, \quad
            \ub(t) = (u_1(t),\ldots,u_{N_u}(t)) \in \mathbb{R}^{N_u}} \\
            (\textsf{P}) \left\lbrace
            \begin{array}{l l}
                \textsf{Minimize} & J[\xb(\cdot),\ub(\cdot),t_0,t_f] = \\
                & E(\xb_0,\xb_f,t_0,t_f) + \displaystyle\int_{t_f}^{t_0}F(\xb(t),\ub(t),t)\,dt\\
                \textsf{Subject to}  & \dot{\xb}(t) = \fb(\xb(t),\ub(t),t) \\
                & \eb^L \leq \eb(\xb_0,\xb_f,t_0,t_f) \leq \eb^U \\
                & \hb^L \leq \hb(\xb(t),\ub(t),t) \leq \hb^U 
            \end{array}
            \right.
        \end{gather*}}
        \onslide<3>
        \lightgray{\begin{gather*}
            \xb(t) = (x_1(t),\ldots,x_{N_x}(t)) \in \mathbb{R}^{N_x}, \quad
            \ub(t) = (u_1(t),\ldots,u_{N_u}(t)) \in \mathbb{R}^{N_u} \\
            (\textsf{P}) \left\lbrace
            \begin{array}{l l}
                \black{\textsf{Minimize}} & \black{J[\xb(\cdot),\ub(\cdot),t_0,t_f] = }\\
                & \black{E(\xb_0,\xb_f,t_0,t_f) + \displaystyle\int_{t_f}^{t_0}F(\xb(t),\ub(t),t)\,dt}\\
                \textsf{Subject to}  & \dot{\xb}(t) = \fb(\xb(t),\ub(t),t) \\
                & \eb^L \leq \eb(\xb_0,\xb_f,t_0,t_f) \leq \eb^U \\
                & \hb^L \leq \hb(\xb(t),\ub(t),t) \leq \hb^U 
            \end{array}
            \right.
        \end{gather*}}
        \onslide<4>
        \lightgray{\begin{gather*}
            \xb(t) = (x_1(t),\ldots,x_{N_x}(t)) \in \mathbb{R}^{N_x}, \quad
            \ub(t) = (u_1(t),\ldots,u_{N_u}(t)) \in \mathbb{R}^{N_u} \\
            (\textsf{P}) \left\lbrace
            \begin{array}{l l}
                \textsf{Minimize} & J[\xb(\cdot),\ub(\cdot),t_0,t_f] = \\
                & E(\xb_0,\xb_f,t_0,t_f) + \displaystyle\int_{t_f}^{t_0}F(\xb(t),\ub(t),t)\,dt\\
                \black{\textsf{Subject to}}  & \black{\dot{\xb}(t) = \fb(\xb(t),\ub(t),t)} \\
                & \eb^L \leq \eb(\xb_0,\xb_f,t_0,t_f) \leq \eb^U \\
                & \hb^L \leq \hb(\xb(t),\ub(t),t) \leq \hb^U 
            \end{array}
            \right.
        \end{gather*}}
        \onslide<5>
        \lightgray{\begin{gather*}
            \xb(t) = (x_1(t),\ldots,x_{N_x}(t)) \in \mathbb{R}^{N_x}, \quad
            \ub(t) = (u_1(t),\ldots,u_{N_u}(t)) \in \mathbb{R}^{N_u} \\
            (\textsf{P}) \left\lbrace
            \begin{array}{l l}
                \textsf{Minimize} & J[\xb(\cdot),\ub(\cdot),t_0,t_f] = \\
                & E(\xb_0,\xb_f,t_0,t_f) + \displaystyle\int_{t_f}^{t_0}F(\xb(t),\ub(t),t)\,dt\\
                \black{\textsf{Subject to}}  & \dot{\xb}(t) = \fb(\xb(t),\ub(t),t) \\
                & \black{\eb^L \leq \eb(\xb_0,\xb_f,t_0,t_f) \leq \eb^U} \\
                & \hb^L \leq \hb(\xb(t),\ub(t),t) \leq \hb^U 
            \end{array}
            \right.
        \end{gather*}}
        \onslide<6>
        \lightgray{\begin{gather*}
            \xb(t) = (x_1(t),\ldots,x_{N_x}(t)) \in \mathbb{R}^{N_x}, \quad
            \ub(t) = (u_1(t),\ldots,u_{N_u}(t)) \in \mathbb{R}^{N_u} \\
            (\textsf{P}) \left\lbrace
            \begin{array}{l l}
                \textsf{Minimize} & J[\xb(\cdot),\ub(\cdot),t_0,t_f] = \\
                & E(\xb_0,\xb_f,t_0,t_f) + \displaystyle\int_{t_f}^{t_0}F(\xb(t),\ub(t),t)\,dt\\
                \black{\textsf{Subject to}}  & \dot{\xb}(t) = \fb(\xb(t),\ub(t),t) \\
                & \eb^L \leq \eb(\xb_0,\xb_f,t_0,t_f) \leq \eb^U \\
                & \black{\hb^L \leq \hb(\xb(t),\ub(t),t) \leq \hb^U} 
            \end{array}
            \right.
        \end{gather*}}
        \onslide<7>
        \begin{gather*}
            \xb(t) = (x_1(t),\ldots,x_{N_x}(t)) \in \mathbb{R}^{N_x}, \quad
            \ub(t) = (u_1(t),\ldots,u_{N_u}(t)) \in \mathbb{R}^{N_u} \\
            (\textsf{P}) \left\lbrace
            \begin{array}{l l}
                \textsf{Minimize} & J[\xb(\cdot),\ub(\cdot),t_0,t_f] = \\
                & E(\xb_0,\xb_f,t_0,t_f) + \displaystyle\int_{t_f}^{t_0}F(\xb(t),\ub(t),t)\,dt\\
                \textsf{Subject to}  & \dot{\xb}(t) = \fb(\xb(t),\ub(t),t) \\
                & \eb^L \leq \eb(\xb_0,\xb_f,t_0,t_f) \leq \eb^U \\
                & \hb^L \leq \hb(\xb(t),\ub(t),t) \leq \hb^U 
            \end{array}
            \right.
        \end{gather*}
    \end{overprint}
\end{frame}

\begin{frame}{Background}{Riemann-Stieltjes Optimal Control (cont.)}
    \begin{itemize}
        \item Continuous $\pb$-domain Riemann-Stieltjes optimal control problem          
    \end{itemize}
    \setstretch{1.5}
    \small
    \vspace{-0.5cm}
    \begin{overprint}
        \onslide<1>
        \begin{gather*}
            \xb \in \mathbb{X} \subseteq \mathbb{R}^{N_x}, \qquad
            \ub \in \mathbb{U} \subseteq \mathbb{R}^{N_u}, \qquad
            \pb \in supp(\pb) \\     
            (\textsf{RS}^\infty) \left\lbrace \begin{array}{l l l}
                \textsf{Minimize}   
                & J_{RS}[\xb(\cdot,\cdot),\ub(\cdot),t] := \\
                & \displaystyle \int_{supp(\pb)} J_u[\xb(\cdot,\pb),\ub(\cdot),t]\,d\alpha(\pb) & \\
                \textsf{Subject to} 
                & \dot{\xb}(t,\pb) = \fb(\xb(t,\pb),\ub(t),t) & 
                \multirow{3}{*}{$\left.\vphantom{\begin{matrix}0\\0\\0\end{matrix}}\right\rbrace\,\forall\,\pb$}    \\      
                & \eb_d(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f) \leq \mathbf{0} \\
                & \hb_d(\xb(t,\pb),\ub(t),t) \leq \mathbf{0} \\
                & \displaystyle \int_{supp(\pb)} \eb_u(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f)\,d\alpha(\pb) \leq \mathbf{0} & \\
                & \displaystyle \int_{supp(\pb)} \hb_u(\xb(t,\pb),\ub(t),t)\,d\alpha(\pb) \leq \mathbf{0} &
            \end{array}
            \right.
        \end{gather*}
        \onslide<2>
        \lightgray{\begin{gather*}
            \black{\xb \in \mathbb{X} \subseteq \mathbb{R}^{N_x}, \qquad
            \ub \in \mathbb{U} \subseteq \mathbb{R}^{N_u},} \qquad
            \red{\pb \in supp(\pb)} \\   
            (\textsf{RS}^\infty) \left\lbrace \begin{array}{l l l}
                \textsf{Minimize}   
                & J_{RS}[\xb(\cdot,\cdot),\ub(\cdot),t] := \\
                & \displaystyle \int_{supp(\pb)} J_u[\xb(\cdot,\pb),\ub(\cdot),t]\,d\alpha(\pb) & \\
                \textsf{Subject to} 
                & \dot{\xb}(t,\pb) = \fb(\xb(t,\pb),\ub(t),t) & 
                \multirow{3}{*}{$\left.\vphantom{\begin{matrix}0\\0\\0\end{matrix}}\right\rbrace\,\forall\,\pb$}    \\      
                & \eb_d(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f) \leq \mathbf{0} \\
                & \hb_d(\xb(t,\pb),\ub(t),t) \leq \mathbf{0} \\
                & \displaystyle \int_{supp(\pb)} \eb_u(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f)\,d\alpha(\pb) \leq \mathbf{0} & \\
                & \displaystyle \int_{supp(\pb)} \hb_u(\xb(t,\pb),\ub(t),t)\,d\alpha(\pb) \leq \mathbf{0} &
            \end{array}
            \right.
        \end{gather*}}
        \onslide<3>
        \lightgray{\begin{gather*}
            \xb \in \mathbb{X} \subseteq \mathbb{R}^{N_x}, \qquad
            \ub \in \mathbb{U} \subseteq \mathbb{R}^{N_u}, \qquad
            \pb \in supp(\pb) \\     
            (\textsf{RS}^\infty) \left\lbrace \begin{array}{l l l}
                \black{\textsf{Minimize}}   
                & \red{J_{RS}[\xb(\cdot,\cdot),\ub(\cdot),t] :=} \\
                & \red{\displaystyle \int_{supp(\pb)} J_u[\xb(\cdot,\pb),\ub(\cdot),t]\,d\alpha(\pb)} & \\
                \textsf{Subject to} 
                & \dot{\xb}(t,\pb) = \fb(\xb(t,\pb),\ub(t),t) & 
                \multirow{3}{*}{$\left.\vphantom{\begin{matrix}0\\0\\0\end{matrix}}\right\rbrace\,\forall\,\pb$}    \\      
                & \eb_d(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f) \leq \mathbf{0} \\
                & \hb_d(\xb(t,\pb),\ub(t),t) \leq \mathbf{0} \\
                & \displaystyle \int_{supp(\pb)} \eb_u(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f)\,d\alpha(\pb) \leq \mathbf{0} & \\
                & \displaystyle \int_{supp(\pb)} \hb_u(\xb(t,\pb),\ub(t),t)\,d\alpha(\pb) \leq \mathbf{0} &
            \end{array}
            \right.
        \end{gather*}}
        \onslide<4>
        \lightgray{\begin{gather*}
            \xb \in \mathbb{X} \subseteq \mathbb{R}^{N_x}, \qquad
            \ub \in \mathbb{U} \subseteq \mathbb{R}^{N_u}, \qquad
            \pb \in supp(\pb) \\     
            (\textsf{RS}^\infty) \left\lbrace \begin{array}{l l l}
                \textsf{Minimize}   
                & J_{RS}[\xb(\cdot,\cdot),\ub(\cdot),t] := \\
                & \displaystyle \int_{supp(\pb)} J_u[\xb(\cdot,\pb),\ub(\cdot),t]\,d\alpha(\pb) & \\
                \black{\textsf{Subject to}} 
                & \black{\dot{\xb}(t,\red{\pb}) = \fb(\xb(t,\red{\pb}),\ub(t),t)} & 
                \red{\multirow{3}{*}{$\left.\vphantom{\begin{matrix}0\\0\\0\end{matrix}}\right\rbrace\,\forall\,\pb$}}  \\      
                & \eb_d(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f) \leq \mathbf{0} \\
                & \hb_d(\xb(t,\pb),\ub(t),t) \leq \mathbf{0} \\
                & \displaystyle \int_{supp(\pb)} \eb_u(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f)\,d\alpha(\pb) \leq \mathbf{0} & \\
                & \displaystyle \int_{supp(\pb)} \hb_u(\xb(t,\pb),\ub(t),t)\,d\alpha(\pb) \leq \mathbf{0} &
            \end{array}
            \right.
        \end{gather*}}
        \onslide<5>
        \lightgray{\begin{gather*}
            \xb \in \mathbb{X} \subseteq \mathbb{R}^{N_x}, \qquad
            \ub \in \mathbb{U} \subseteq \mathbb{R}^{N_u}, \qquad
            \pb \in supp(\pb) \\     
            (\textsf{RS}^\infty) \left\lbrace \begin{array}{l l l}
                \textsf{Minimize}   
                & J_{RS}[\xb(\cdot,\cdot),\ub(\cdot),t] := \\
                & \displaystyle \int_{supp(\pb)} J_u[\xb(\cdot,\pb),\ub(\cdot),t]\,d\alpha(\pb) & \\
                \black{\textsf{Subject to}} 
                & \dot{\xb}(t,\pb) = \fb(\xb(t,\pb),\ub(t),t) & 
                \red{\multirow{3}{*}{$\left.\vphantom{\begin{matrix}0\\0\\0\end{matrix}}\right\rbrace\,\forall\,\pb$}}  \\      
                & \black{\eb_d(\xb(t_0,\red{\pb}),\xb(t_f,\red{\pb}),t_0,t_f) \leq \mathbf{0}} \\
                & \black{\hb_d(\xb(t,\red{\pb}),\ub(t),t) \leq \mathbf{0}} \\
                & \displaystyle \int_{supp(\pb)} \eb_u(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f)\,d\alpha(\pb) \leq \mathbf{0} & \\
                & \displaystyle \int_{supp(\pb)} \hb_u(\xb(t,\pb),\ub(t),t)\,d\alpha(\pb) \leq \mathbf{0} &
            \end{array}
            \right.
        \end{gather*}}
        \onslide<6>
        \lightgray{\begin{gather*}
            \xb \in \mathbb{X} \subseteq \mathbb{R}^{N_x}, \qquad
            \ub \in \mathbb{U} \subseteq \mathbb{R}^{N_u}, \qquad
            \pb \in supp(\pb) \\     
            (\textsf{RS}^\infty) \left\lbrace \begin{array}{l l l}
                \textsf{Minimize}   
                & J_{RS}[\xb(\cdot,\cdot),\ub(\cdot),t] := \\
                & \displaystyle \int_{supp(\pb)} J_u[\xb(\cdot,\pb),\ub(\cdot),t]\,d\alpha(\pb) & \\
                \black{\textsf{Subject to}} 
                & \dot{\xb}(t,\pb) = \fb(\xb(t,\pb),\ub(t),t) & 
                \multirow{3}{*}{$\left.\vphantom{\begin{matrix}0\\0\\0\end{matrix}}\right\rbrace\,\forall\,\pb.$}   \\      
                & \eb_d(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f) \leq \mathbf{0} \\
                & \hb_d(\xb(t,\pb),\ub(t),t) \leq \mathbf{0} \\
                & \red{\displaystyle \int_{supp(\pb)} \eb_u(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f)\,d\alpha(\pb) \leq \mathbf{0}} & \\
                & \red{\displaystyle \int_{supp(\pb)} \hb_u(\xb(t,\pb),\ub(t),t)\,d\alpha(\pb) \leq \mathbf{0}} &
            \end{array}
            \right.
        \end{gather*}}
        \onslide<7->
        \begin{gather*}
            \xb \in \mathbb{X} \subseteq \mathbb{R}^{N_x}, \qquad
            \ub \in \mathbb{U} \subseteq \mathbb{R}^{N_u}, \qquad
            \pb \in supp(\pb) \\     
            (\textsf{RS}^\infty) \left\lbrace \begin{array}{l l l}
                \textsf{Minimize}   
                & J_{RS}[\xb(\cdot,\cdot),\ub(\cdot),t] := \\
                & \displaystyle \int_{supp(\pb)} J_u[\xb(\cdot,\pb),\ub(\cdot),t]\,d\alpha(\pb) & \\
                \textsf{Subject to} 
                & \dot{\xb}(t,\pb) = \fb(\xb(t,\pb),\ub(t),t) & 
                \multirow{3}{*}{$\left.\vphantom{\begin{matrix}0\\0\\0\end{matrix}}\right\rbrace\,\forall\,\pb.$}   \\      
                & \eb_d(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f) \leq \mathbf{0} \\
                & \hb_d(\xb(t,\pb),\ub(t),t) \leq \mathbf{0} \\
                & \displaystyle \int_{supp(\pb)} \eb_u(\xb(t_0,\pb),\xb(t_f,\pb),t_0,t_f)\,d\alpha(\pb) \leq \mathbf{0} & \\
                & \displaystyle \int_{supp(\pb)} \hb_u(\xb(t,\pb),\ub(t),t)\,d\alpha(\pb) \leq \mathbf{0} &
            \end{array}
            \right.
        \end{gather*}
    \end{overprint} 
\end{frame}

答案1

\textcolor或等命令\color可以感知叠加层。这意味着您无需多次重复内容,而是可以指定\color<2->{lightgray} ...颜色应在哪些叠加层上改变:

\documentclass[dvipsnames,table,aspectratio=169]{beamer}    % 16:9 aspect ratio
%\usetheme{Monterey}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{multirow}  % Allows multirows in equations 
\usepackage{setspace}   % Allows double spacing with the \doublespacing command

% Change text color
\newcommand{\black}[1]{\textcolor{black}{#1}}
\newcommand{\red}[1]{\textcolor{red}{#1}}
\newcommand{\lightgray}[1]{\textcolor{lightgray}{#1}}

% Bold math variables
\newcommand{\fb}{\mathbf{f}}
\newcommand{\xb}{\mathbf{x}}
\newcommand{\hb}{\mathbf{h}}
\newcommand{\ub}{\mathbf{u}}
\newcommand{\eb}{\mathbf{e}}
\newcommand{\pb}{\mathbf{p}}
\newcommand{\qb}{\mathbf{q}}
\newcommand{\gb}{\mathbf{g}}
\newcommand{\Xb}{\mathbf{X}}
\newcommand{\Zb}{\mathbf{Z}}
\newcommand{\lambdab}{\boldsymbol{\lambda}}
\newcommand{\nub}{\boldsymbol{\nu}}
\newcommand{\mub}{\boldsymbol{\mu}}
\newcommand{\chib}{\boldsymbol{\chi}}

\begin{document}

\begin{frame}{Background}{Standard Optimal Control}
    \begin{itemize}
        \item Standard optimal control problem \cite{ross2015primer}
    \end{itemize}
    \setstretch{1.5}
    \vspace{-1cm}
    \begin{overprint}
        \color<2->{lightgray}\begin{gather*}
            \black{\xb(t) = (x_1(t),\ldots,x_{N_x}(t)) \in \mathbb{R}^{N_x}, \quad
            \ub(t) = (u_1(t),\ldots,u_{N_u}(t)) \in \mathbb{R}^{N_u}} \\
            (\textsf{P}) \left\lbrace
            \begin{array}{l l}
                \textsf{Minimize} & J[\xb(\cdot),\ub(\cdot),t_0,t_f] = \\
                & E(\xb_0,\xb_f,t_0,t_f) + \displaystyle\int_{t_f}^{t_0}F(\xb(t),\ub(t),t)\,dt\\
                \textsf{Subject to}  & \dot{\xb}(t) = \fb(\xb(t),\ub(t),t) \\
                & \eb^L \leq \eb(\xb_0,\xb_f,t_0,t_f) \leq \eb^U \\
                & \hb^L \leq \hb(\xb(t),\ub(t),t) \leq \hb^U 
            \end{array}
            \right.
        \end{gather*}\color{black}
    \end{overprint} 
\end{frame}

\end{document}

在此处输入图片描述

相关内容