0

I try to put a colored bar on the bottom of each frame of a Beamer document the lenght of which increases during the presentation. I wrote the following code:

\setbeamertemplate{footline}{%
\leavevmode%
  \hbox{%
        \begin{tikzpicture}
            \draw[-, ultra thick, yellow!50!green] (0,0) -- (\paperwidth*\value{framenumber}/\total,0) ;
        \end{tikzpicture}
  }
}

and its works well, but the \total command is the total number of frames which I previousely manually defined (I need it because I want the bar to reach the right side of the screen at the last frame). If I can get the current frame number with \value{framenumber}, I do not find an equivalent command to get the value of the total frame number. I would like to know if there exists a solution (I think it is possible since \inserttotalframenumber can print it, but I do not know how it really works to calculate it since it does not seem to be related to some counter "totalframenumber"...).

4
  • 3
    Welcome! Please post a complete minimal example we can compile rather than a code snippet as that is much more useful. To get the total frame number, you need to write the value to an external file at the end of compilation and read it back during the next run. Typically the .aux is used for this.
    – cfr
    Commented Jul 18 at 17:54
  • 3
    At the end of the document, beamer does \immediate\write\@auxout{\string\@writefile{nav}% {\noexpand\headcommand{\noexpand\gdef\noexpand\inserttotalframenumber{\the\c@framenumber}}}} so \inserttotalframenumber just is \the\c@framenumber i.e. the value of the counter framenumber at the end of the previous compilation (or 1 by default).
    – cfr
    Commented Jul 18 at 18:03
  • \inserttotalframenumber normally works fine. Can you show a Mwe in which you face a problem? Commented Jul 19 at 10:31
  • You are right! In fact, I had tried (unsuccessfully) some uncorrect "\value{\inserttotalframenumber}" or "\arabic{\inserttotalframenumber}" but it seems that I was so convinced that \inserttotalframenumber would not work alone at a number value that I had not even tried it... It is done now, and it perfectly works.
    – Dor4
    Commented Jul 19 at 14:15

2 Answers 2

0

You can use \inserttotalframenumber not only to print the total number of frames, you can also use it in your calculation:

\documentclass{beamer}
\usepackage{tikz}

\setbeamertemplate{footline}{%
  \begin{tikzpicture}[overlay,remember picture]
      \draw[-, line width=0.2cm, yellow!50!green] (current page.south west) -- (\paperwidth*\value{framenumber}/\inserttotalframenumber,0) ;
  \end{tikzpicture}
}

\begin{document}
\begin{frame}
test
\end{frame}
\begin{frame}
test
\end{frame}
\end{document}

enter image description here

0

I finally found a solution by discovering the package totcount which deals with .aux files. Here is an ECM of what I have wrote:

\documentclass[t]{beamer}

\usepackage{totcount}
\regtotcounter{framenumber}

\usepackage{tikz}
\usepackage{lipsum}

\setbeamertemplate{footline}{%
\leavevmode%
  \hbox{%
    \hspace{-0.3cm}        
    \begin{tikzpicture}
        \draw[-, line width = 5pt, yellow!50!green] (0,0) -- (\paperwidth*\value{framenumber}/\totvalue{framenumber}+4,0) ;
    \end{tikzpicture}
  }
}

\setbeamertemplate{navigation symbols}{}

\begin{document}

\begin{frame}
\lipsum[1]
\end{frame}

\begin{frame}
\lipsum[2]
\end{frame}

\begin{frame}
\lipsum[3]
\end{frame}

\begin{frame}
\lipsum[4]
\end{frame}

\begin{frame}
\lipsum[5]
\end{frame}

\end{document}

It needs to be compiled two times to update the total frame number. The \hspace{-0.3cm} and the +4 are little adjustments to make the bar touch the border of the frame.

3
  • 1
    Does \inserttotalframenumber from the comment of CFR tex.stackexchange.com/questions/722754/… not work for you?
    – Stephen
    Commented Jul 19 at 9:25
  • This command allows me to print the total frame number on my slides but I did not found any way to extract the value from it as a parameter I can put in a TikZ command.
    – Dor4
    Commented Jul 19 at 9:42
  • Try \draw[-, line width = 5pt, yellow!50!green] (0,0) -- (\paperwidth*\value{framenumber}/\inserttotalframenumber+4,0) ; with removed \usepackage{totcount}\regtotcounter{framenumber} .
    – Stephen
    Commented Jul 19 at 17:27

You must log in to answer this question.

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