正確使用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其餘部分之前被“執行”,即真正的部分程式碼( )。在連結問題的答案的定義中,ed 為,因此一開始始終為空。\section\beameroldsection\sectiondesc\gdef{}

\gdef\sectiondesc{#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}

在此輸入影像描述

相關內容