# Get number of each slide and total slides with respect to the whole presentation

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

• 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 May 9 '15 at 15:41
• That command yields the following error: You can't use '\unhbox' after \the. \end{frame} – luchonacho May 9 '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 9 '15 at 15:48
• The current slide number is in the TeX counter beamer@slidesinframe. It can be shown with \the\beamer@slidesinframe – user31729 May 9 '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 9 '15 at 16:02

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

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

\def\insertframeratio{%
\pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\% %
}

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

\begin{document}

\begin{frame}{title 1}
\only<1>{
Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
}
\only<2>{
Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
}
\end{frame}

\begin{frame}{title 2}
\only<1>{
Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
}
\only<2>{
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{%
\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\\
Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
}
\only<2>{
Slide in Frame: \inserttheslide{} of \insertslides: \insertslideratio\\
Page: \insertpagenumber{} of \insertdocumentendpage: \insertpageratio
}
\end{frame}

\begin{frame}{title 2}
\only<1>{
Slide in Frame: \inserttheslide{} of \insertslides: \insertslideratio\\
`