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}
luchonacho
  • 4,161
  • 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) –  May 09 '15 at 15:41
  • That command yields the following error: You can't use '\unhbox' after \the. \end{frame} – luchonacho May 09 '15 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 May 09 '15 at 15:48
  • The current slide number is in the TeX counter beamer@slidesinframe. It can be shown with \the\beamer@slidesinframe –  May 09 '15 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 May 09 '15 at 16:02
  • @luchonacho: You have to wrap the command into some other command being defined above, between \makeatletter ...\makeatother ;-) –  May 09 '15 at 16:03
  • I think I'm too noob to understand your comment. Do you mind to write an answer? – luchonacho May 09 '15 at 16:06
  • @luchonacho: I'll can do, but I am not yet finished with my 'solution' –  May 09 '15 at 16:08
  • Very similar posting but not exact duplicate, however this about creating a progress bar for Beamer shows. http://tex.stackexchange.com/questions/59742/progress-bar-for-latex-beamer – R. Schumacher May 09 '15 at 18:33
  • Well spotted! I started in that post. That is the reason why I wanted to do this (a progress bar). However, the answer of that post counts only frames whereas I wanted slides. Here that issue is solved. – luchonacho May 09 '15 at 18:57

1 Answers1

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

  • 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 May 09 '15 at 18:07