[Tex/LaTex] How to use argmax or argmin inside case

cases

I want use argmax in my beamer slide. I have found this question really useful:
Command for argmin or argmax?
The problem is I can not use \argmax inside case environment.

Example 1: \argmax works fine outside of case:

\documentclass[demo]{beamer}% <-- demo only for test, delete it in real document
\mode<presentation> {
    \usetheme{Madrid}
    \setbeamertemplate{footline}[page number]
}

\usepackage{booktabs}           % Allows the use of \toprule,
% \midrule and \bottomrule in tables
\usepackage{tikz}               % add background image
\usepackage{mathtools}               % add background image
\DeclareMathOperator*{\argmax}{arg\,max}
\begin{document}
    \begin{frame}
        \frametitle{Solving MDP 2}
        \begin{block}{Optimal Policy}
            Optimal policy can be found by maximizing over $q_\ast (s,a)$
            \begin{equation*}
            \pi_\ast (a|s)=
            \begin{cases*}
            1 & \text{if }  (s,a) \\
            0 &  \text{otherwise}

            \end{cases*}
        \argmax_{x \in A}  q_\ast(s,a)          
          \end{equation*}

        \end{block}
    \end{frame}
\end{document}

Example 2: inside case \argmax does not work

 \documentclass[demo]{beamer}% <-- demo only for test, delete it in real document
\mode<presentation> {
    \usetheme{Madrid}
    \setbeamertemplate{footline}[page number]
}

\usepackage{booktabs}           % Allows the use of \toprule,
% \midrule and \bottomrule in tables
\usepackage{tikz}               % add background image
\usepackage{mathtools}               % add background image
\DeclareMathOperator*{\argmax}{arg\,max}
\begin{document}
    \begin{frame}
        \frametitle{Solving MDP 2}
        \begin{block}{Optimal Policy}
            Optimal policy can be found by maximizing over $q_\ast (s,a)$
            \begin{equation*}
            \pi_\ast (a|s)=
            \begin{cases*}
            1 & \text{if } \argmax_{x \in A}  q_\ast(s,a)  \\
            0 &  \text{otherwise}

            \end{cases*}

            \end{equation*}

        \end{block}
    \end{frame}
\end{document}

Best Answer

Avoid blank lines in math displays.

You can use \limits

\documentclass[demo]{beamer}% <-- demo only for test, delete it in real document
\mode<presentation> {
    \usetheme{Madrid}
    \setbeamertemplate{footline}[page number]
}

\usepackage{booktabs}           % Allows the use of \toprule,
% \midrule and \bottomrule in tables
\usepackage{tikz}               % add background image
\usepackage{mathtools}               % add background image
\DeclareMathOperator*{\argmax}{arg\,max}
\begin{document}

    \begin{frame}
        \frametitle{Solving MDP 2}
        \begin{block}{Optimal Policy}
            Optimal policy can be found by maximizing over $q_\ast (s,a)$
            \begin{equation*}
            \pi_\ast (a|s)=
            \begin{cases*}
            1 & if $\argmax\limits_{x \in A}  q_\ast(s,a)$  \\
            0 & otherwise
            \end{cases*}
            \end{equation*}
        \end{block}
    \end{frame}
\end{document}

enter image description here

Recall that in cases* the right column is started in text mode.

Related Question