我怎样才能让一个框架显示它自己的幻灯片数量?(投影仪)

我怎样才能让一个框架显示它自己的幻灯片数量?(投影仪)

我正在尝试编写一个显示每帧幻灯片数量的代码。但是,代码似乎在前一帧中写入了幻灯片数量

在 MWE 中,代码将帧 2 幻灯片报告为 5(帧 1 中的幻灯片),将帧 3 的数量报告为 7(帧 2 中的幻灯片),等等。

如何让框架显示其自身的幻灯片数量?期望的结果与我们在我如何显示每帧幻灯片的编号?。相反,我希望结果显示(帧中的当前幻灯片)和(帧中的总幻灯片数)。我已经实现了这一点,但“帧中的总幻灯片数”是指上一帧中的总幻灯片数。

\documentclass{beamer}

\makeatletter
\def\c@slideinframe{\beamer@slideinframe}
\makeatother

\newcounter{totalslideinframe}
\AtBeginEnvironment{frame}{
    \setcounter{totalslideinframe}{\insertframeendpage}
    \addtocounter{totalslideinframe}{-\insertframestartpage}
    \addtocounter{totalslideinframe}{1}
                        }


\newcommand{\frameSlideNumbering}{Slide \arabic{slideinframe} of \arabic{totalslideinframe}}



\begin{document}

    \begin{frame}{Frame 1}



    This is slide \arabic{slideinframe} of \arabic{totalslideinframe} \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}


\begin{frame}{Frame 2}

    This is slide \arabic{slideinframe} of \arabic{totalslideinframe}

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}

\begin{frame}{Frame 3}

    This is slide \arabic{slideinframe} of \arabic{totalslideinframe}

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}


\begin{frame}{Frame 4}

    This is slide \arabic{slideinframe} of \arabic{totalslideinframe}

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}

\begin{frame}{Frame 5}

    This is slide \arabic{slideinframe} of \arabic{totalslideinframe}

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}

\end{document}

答案1

您实际上不需要计数器,而需要一个可以计算差异的命令:

\newcommand\totalslideinframe{\the\numexpr\insertframeendpage-\insertframestartpage+1}

完整代码:

\documentclass{beamer}

\makeatletter
\def\c@slideinframe{\beamer@slideinframe}
\makeatother

% You don't need a counter but a command
\newcommand\totalslideinframe{\the\numexpr\insertframeendpage-\insertframestartpage+1}

\newcommand{\frameSlideNumbering}{Slide \arabic{slideinframe} of \arabic{totalslideinframe}}



\begin{document}

    \begin{frame}{Frame 1}



    This is slide \arabic{slideinframe} of \totalslideinframe \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}


\begin{frame}{Frame 2}

    This is slide \arabic{slideinframe} of \totalslideinframe

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}

\begin{frame}{Frame 3}

    This is slide \arabic{slideinframe} of \totalslideinframe

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}


\begin{frame}{Frame 4}

    This is slide \arabic{slideinframe} of \totalslideinframe

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}

\begin{frame}{Frame 5}

    This is slide \arabic{slideinframe} of \totalslideinframe

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

    Contents \pause More contents \pause Extra contents \pause

\end{frame}

\end{document}

相关内容