3

I need to get the number of each slide and the total number of slides in order to calculate the progress of my presentation, but I can only do this for frames, as my MWE below shows.

Basically I need to do be able to replace the ? below with the actual expression.

Ps: I'm also not able to show the value of c@ratio. Any help with that would be great too.

\documentclass{beamer}

\makeatletter
\def\c@counter{} 
\newcount\c@counta
\newcount\c@countb
\newdimen\c@ratio

% counter
\def\c@counter{%

    \c@counta=\insertframenumber
    \c@countb=\inserttotalframenumber
    \c@ratio=\c@counta
    \divide\c@ratio by \c@countb

    }
\makeatother

\begin{document}

\begin{frame}{title 1}

\only<1>{

This is the \the\c@ratio \% of frames and the ? \% of slides

This is Frame number \insertframenumber, and Slide number ?}

\only<2>{

This is the \the\c@ratio \% of frames and the ? \% of slides

This is Frame number \insertframenumber, and Slide number ?}

\end{frame}

\begin{frame}{title 2}

\only<1>{

This is the \the\c@ratio \% of frames and the ? \% of slides

This is Frame number \insertframenumber, and Slide number ?}

\only<2>{

This is the \the\c@ratio \% of frames and the ? \% of slides

This is Frame number \insertframenumber, and Slide number ?}

\end{frame}

\end{document}
10
  • c@ratio is a length register, which can be shown with \the\c@ratio, but this will print it with a trailing pt (which is probably not what you want)
    – user31729
    Commented May 9, 2015 at 15:41
  • That command yields the following error: You can't use '\unhbox' after \the. \end{frame}
    – luchonacho
    Commented May 9, 2015 at 15:45
  • In TeX empty lines are not discarded but a whitespace is inserted everytime you run the code. . You have to either suppress them with % or remove them.
    – percusse
    Commented May 9, 2015 at 15:48
  • The current slide number is in the TeX counter beamer@slidesinframe. It can be shown with \the\beamer@slidesinframe
    – user31729
    Commented May 9, 2015 at 15:58
  • I get the following errors: 1) You can't use `the character @' after \the. \end{frame}. 2) Undefined control sequence. \end{frame}
    – luchonacho
    Commented May 9, 2015 at 16:02

1 Answer 1

3

This gives you the ratio of the current page to total page number:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}

\def\insertframeratio{%
    \pgfmathparse{\insertframenumber*100/\inserttotalframenumber}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\% %
}

\def\insertpageratio{%
    \pgfmathparse{\insertpagenumber*100/\insertdocumentendpage}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\% %
}

\begin{document}
    
\begin{frame}
\frametitle{title 1}
    \only<1>{
        Frames: \insertframenumber{} of \inserttotalframenumber: \insertframeratio\\
        Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
    }
    \only<2>{
        Frames: \insertframenumber{} of \inserttotalframenumber: \insertframeratio\\
        Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
    }
\end{frame}

\begin{frame}
\frametitle{title 2}
    \only<1>{
        Frames: \insertframenumber{} of \inserttotalframenumber: \insertframeratio\\
        Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
    }
    \only<2>{
        Frames: \insertframenumber{} of \inserttotalframenumber: \insertframeratio\\
        Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
    }
\end{frame}

\end{document}

Just in case anybody might want to calculate the ratio for slides within a frame:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}

\def\insertframeratio{%
    \pgfmathparse{\insertframenumber*100/\inserttotalframenumber}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\% %
}

\def\insertpageratio{%
    \pgfmathparse{\insertpagenumber*100/\insertdocumentendpage}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\% %
}

\def\insertslideratio{%
    \pgfmathparse{(\insertpagenumber-\insertframestartpage+1)*100/(\insertframeendpage-\insertframestartpage+1)}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\% %
}

\def\insertslides{%
    \pgfmathparse{\insertframeendpage-\insertframestartpage+1}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}%
}

\def\inserttheslide{%
    \pgfmathparse{\insertpagenumber-\insertframestartpage+1}%
    \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}%
}


\begin{document}
    
\begin{frame}
\frametitle{title 1}
    \only<1>{
        Slide in Frame: \inserttheslide{} of \insertslides: \insertslideratio\\
        Frames: \insertframenumber{} of \inserttotalframenumber: \insertframeratio\\
        Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
    }
    \only<2>{
        Slide in Frame: \inserttheslide{} of \insertslides: \insertslideratio\\
        Frames: \insertframenumber{} of \inserttotalframenumber: \insertframeratio\\
        Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
    }
\end{frame}

\begin{frame}
\frametitle{title 2}
    \only<1>{
        Slide in Frame: \inserttheslide{} of \insertslides: \insertslideratio\\
        Frames: \insertframenumber{} of \inserttotalframenumber: \insertframeratio\\
        Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
    }
    \only<2>{
        Slide in Frame: \inserttheslide{} of \insertslides: \insertslideratio\\
        Frames: \insertframenumber{} of \inserttotalframenumber: \insertframeratio\\
        Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
    }
\end{frame}

\end{document}

enter image description here

1
  • This is it! What I was looking for was these two commands: \insertpagenumber and \insertdocumentendpage. Then I can easily create the ratio! Thanks so much! Should I change my code above or leave it as it is?
    – luchonacho
    Commented May 9, 2015 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .