使用投影機中的總頁數作為計數器

使用投影機中的總頁數作為計數器

我試圖在總頁數上設定乳膠計數:

\newcount\mypagecount
\mypagecount=\insertpresentationendpage

但是,每當我這樣做時,它都會自動「列印」總頁數,而不是將數字作為計數。有沒有辦法將其設定為計數?

這是我想要做的更準確的事:

\newcount\mypagenum
\newcount\mypagecount
\newdimen\barwidth

\mypagenum=\insertpagenumber
\mypagecount=\insertpresentationendpage
\barwidth=\paperwidth

\multiply\barwidth by \mypagenum                                       
\divide\barwidth by \mypagecount

我嘗試使用計數器,但這也引發了錯誤:

\newcounter{mypagecount}
\setcounter{mypagecount}{\insertpresentationendpage}

如果我不能使用這些數字和/或如何實際使用這些數字,我有什麼想法可以在最後進行除法嗎?

答案1

以下內容與目前版本的 基本相同\insertpresentationendpagebeamer但設定的是計數器而不是列印的結果。我還包括了概念驗證進度條輸出。

\documentclass[]{beamer}

\newlength\barwidth
\newlength\tmpbarwidth
\newcount\mypagecount

\makeatletter
\newcommand*\progressbar
  {%
    \ifnum\mypagecount=0
      \ifx\beamer@startpageofappendix\@empty
        \mypagecount=\beamer@endpageofdocument\relax
      \else
        \mypagecount=\beamer@startpageofappendix\relax
        \advance\mypagecount\m@ne
      \fi
      \ifnum\mypagecount=0
        \global\mypagecount=1
      \else
        \global\mypagecount=\mypagecount
      \fi
    \fi
    \begingroup
      \tmpbarwidth\insertpagenumber\barwidth
      \divide\tmpbarwidth\mypagecount
      \rule{\tmpbarwidth}{5pt}%
      \advance\barwidth-\tmpbarwidth
      \textcolor{gray}{\rule{\barwidth}{5pt}}%
    \endgroup
  }
\makeatother

\setlength\barwidth{5cm}

\begin{document}
\begin{frame}
  \progressbar
\end{frame}
\begin{frame}
  \progressbar
\end{frame}
\begin{frame}
  \progressbar
\end{frame}
\begin{frame}
  \progressbar
\end{frame}

\end{document}

相關內容