2

I am trying to write a code that shows the number of slides in each frame. However, the code seems to write the slides number of slides in the previous frame

In the MWE, the code reports frame 2 slides as 5 (slides in frame 1), reports number of frame 3 as 7 (slides in frame 2), etc.

How can I get a frame to show the number of its own slides? The desired result is not the same as the one we have in How can I show the numbering of slides of each frame?. Instead, I want the results to show (current slide in frame) of (total slides in frame). I have already achieved this, but 'total slides in frame' refers to the total slides in the previous frame.

\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}
2

You don't really need a counter but a command that will calculate the difference:

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

Full code:

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.