正确使用 AtBeginSection Beamer

正确使用 AtBeginSection Beamer

我有这个 MWE(来自

\documentclass{beamer}
\usepackage{graphicx}

\usepackage{xparse}

\let\beameroldsection\section% Store the old definition first

\def\sectiondesc{}
\RenewDocumentCommand{\section}{sO{#3}m O{}}{%
    \gdef\sectiondesc{}
    \IfBooleanTF{#1}{% Grab the starred version, i.e. \section*
        \beameroldsection*{#3}%
    }{%
        \beameroldsection[#2]{#3}%
        \gdef\sectiondesc{#4}% Store argument 4
    }%
}

\setbeamertemplate{section page}
{
    \begin{centering}
        \begin{beamercolorbox}[sep=12pt,center]{part title}
            \usebeamerfont{section title}{\insertsection}\par \insertsectionhead
        \end{beamercolorbox}
    \end{centering}

    \begin{center}
        \sectiondesc        
    \end{center}

}


\AtBeginSection[]{
    \begin{frame}{Overview}
        \hfill
        \begin{minipage}{.45\textwidth}
            nothing?\sectionpage%\sectiondesc %%% Tried both `\sectionpage` and `\sectiondesc`
        \end{minipage}
    \end{frame}
}


\begin{document}


    \section[short title]{Long Title}[Really long description \\ multiple lines, often with graphics \includegraphics[width=.5\textwidth]{example-image-a}]

    \begin{frame}
    \sectionpage
    \end{frame}


%   \section*{Foo}
%   \begin{frame}
%   \sectionpage
%   \end{frame}

\end{document}

我尝试过将 放在\sectionpage每个部分的开头。但是,\sectiondesc此页面上的 是空的。

\sectiondesc我应该怎样做才能在开始幻灯片中打印?

答案1

在调用\AtBeginSection其余部分(即实际部分代码)之前,代码已“执行” 。在链接问题的答案定义中,被设置为,因此这在开始时始终为空。\section\beameroldsection\sectiondesc\gdef{}

\gdef\sectiondesc{#4}有效,如果没有描述(即第 4 个参数为空)则\sectiondesc宏将扩展为无。

\documentclass{beamer}
\usepackage{graphicx}

\usepackage{xparse}

\let\beameroldsection\section% Store the old definition first

\def\sectiondesc{}
\RenewDocumentCommand{\section}{sO{#3}m O{}}{%
  \gdef\sectiondesc{#4}% Store the 4th argument beforehand
    \IfBooleanTF{#1}{% Grab the starred version, i.e. \section*
        \beameroldsection*{#3}%
    }{%
        \beameroldsection[#2]{#3}%
     }%
}

\setbeamertemplate{section page}
{
    \begin{centering}
        \begin{beamercolorbox}[sep=12pt,center]{part title}
            \usebeamerfont{section title}{\insertsection}\par \insertsectionhead
        \end{beamercolorbox}
    \end{centering}

    \begin{center}
      \sectiondesc
    \end{center}

}


\AtBeginSection[]{
    \begin{frame}{Overview}
        \hfill
        \begin{minipage}{.45\textwidth}
            \sectionpage%%% Tried both `\sectionpage` and `\sectiondesc`
        \end{minipage}
    \end{frame}
}


\begin{document}


\section[short title]{Long Title}[Really long description \\ multiple lines, often with graphics \includegraphics[width=.5\textwidth]{example-image-a}]

\begin{frame}
  \sectionpage
\end{frame}


\end{document}

在此处输入图片描述

相关内容