6

I have been using the code for a progress bar given by @GonzaloMedina in this post for a nice progress bar. This code is customizable and gives very nice progress bars I find. However, I realized that over a certain number of slides (44) I get an Arithmetic Overflow error.

Here is my code:

\documentclass[10pt,fleqn]{beamer}
\mode<presentation>
\usepackage{tikz}   
% PROGRESS BAR 
\usetikzlibrary{calc}
\makeatletter
\def\progressbar@progressbar{} % the progress bar
\newcount\progressbar@tmpcounta% auxiliary counter
\newcount\progressbar@tmpcountb% auxiliary counter
\newdimen\progressbar@pbht %progressbar height
\newdimen\progressbar@pbwd %progressbar width
\newdimen\progressbar@tmpdim % auxiliary dimension
\progressbar@pbwd=\paperwidth
\progressbar@pbht=0.5ex
% the progress bar
\def\progressbar@progressbar{%
    \progressbar@tmpcounta= \insertframenumber % max = ?
    \progressbar@tmpcountb=\inserttotalframenumber      
    \progressbar@tmpdim=\progressbar@pbwd
    \multiply\progressbar@tmpdim by \progressbar@tmpcounta
    \divide\progressbar@tmpdim by \progressbar@tmpcountb
  \begin{tikzpicture}[rounded corners=1.5pt,very thin]
    \shade[top color=blue!20,bottom color=blue!20,middle color=blue!50]
      (0pt, 0pt) rectangle ++ (\progressbar@pbwd, \progressbar@pbht);
      \shade[draw=red,top color=red!50,bottom color=red!50,middle color=red] %
        (0pt, 0pt) rectangle ++ (\progressbar@tmpdim, \progressbar@pbht);
    \draw[color=normal text.fg!50]
      (0pt, 0pt) rectangle (\progressbar@pbwd, \progressbar@pbht)
        node[pos=0.5,color=normal text.fg] {\textnormal{%
        }%
    };
  \end{tikzpicture}%
}
\addtobeamertemplate{headline}{}
{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=1.5ex,center,dp=0ex]{white}%
    \progressbar@progressbar%
  \end{beamercolorbox}%
}
\makeatother    
%
\begin{document}
\frame[t]{
\frametitle{slide}
\small{
}
}

\frame[t]{
\frametitle{slide}
\small{
}
}
\end{document}

I only left here two slides for the sake of clarity but when more than 44 slides are used, the arithmetic overflow error kicks in... and I don't know why. A few things I have been thinking about: could it be related with the definition of the graphic increment from a slide to another ? Would 1/45 be some kind of lower bound here... ? But I don't know why...

Because the total number of frame seems to be the cause of the problem, I tried to add the following lines in the definition of the progress bar:

\multiply\progressbar@tmpcounta by 44
\divide\progressbar@tmpcounta by \progressbar@tmpcountb 

in order to somehow normalize all values with respect to the maximum number of slides I found acceptable but it did not work.

10

You can scale the arithmetic to keep within bounds, halving then doubling, I tested this with 67 pages.

\documentclass[10pt,fleqn]{beamer}
\mode<presentation>
\usepackage{tikz}   
% PROGRESS BAR 
\usetikzlibrary{calc}
\makeatletter
\def\progressbar@progressbar{} % the progress bar
\newcount\progressbar@tmpcounta% auxiliary counter
\newcount\progressbar@tmpcountb% auxiliary counter
\newdimen\progressbar@pbht %progressbar height
\newdimen\progressbar@pbwd %progressbar width
\newdimen\progressbar@tmpdim % auxiliary dimension
\progressbar@pbwd=\paperwidth
\progressbar@pbht=0.5ex
% the progress bar
\def\progressbar@progressbar{%
    \progressbar@tmpcounta= \insertframenumber % max = ?
    \progressbar@tmpcountb=\inserttotalframenumber      
    \progressbar@tmpdim=.5\progressbar@pbwd
    \multiply\progressbar@tmpdim by \progressbar@tmpcounta
    \divide\progressbar@tmpdim by \progressbar@tmpcountb
    \progressbar@tmpdim=2\progressbar@tmpdim
  \begin{tikzpicture}[rounded corners=1.5pt,very thin]
    \shade[top color=blue!20,bottom color=blue!20,middle color=blue!50]
      (0pt, 0pt) rectangle ++ (\progressbar@pbwd, \progressbar@pbht);
      \shade[draw=red,top color=red!50,bottom color=red!50,middle color=red] %
        (0pt, 0pt) rectangle ++ (\progressbar@tmpdim, \progressbar@pbht);
    \draw[color=normal text.fg!50]
      (0pt, 0pt) rectangle (\progressbar@pbwd, \progressbar@pbht)
        node[pos=0.5,color=normal text.fg] {\textnormal{%
        }%
    };
  \end{tikzpicture}%
}
\addtobeamertemplate{headline}{}
{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=1.5ex,center,dp=0ex]{white}%
    \progressbar@progressbar%
  \end{beamercolorbox}%
}
\makeatother    
%
\begin{document}
\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}

\frame[t]{
\frametitle{slide}
\small

}
\end{document}
| improve this answer | |
  • works like a charm!!! – user95439 Aug 11 '17 at 13:10

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.