我正在为除第一张幻灯片外的所有幻灯片显示进度条创建一个主题。我将进度条放在脚注中,因为我希望它显示在底部。
我不明白为什么这不起作用(实际上如果你大量放大它会显示一个非常小的进度条)
\ifnum\insertframenumber>1\relax%
%progress bar code
\fi
这有效
\ifnum\insertframenumber=1\relax%
\else
%progress bar code
\fi
另一个问题是,如果我不添加\ifnum\inserttotalframenumber>1
,它将在第一次运行时失败,但在后续运行中可以正常工作。似乎 latex 在第一次运行中编译了两次代码,第一次编译的 \inserttotalframenumber 等于 1(导致除以 0)。这是正确的吗?
我把代码放在下面。有注释表示有效代码和无效代码。它是用 Luatex 编译的。我不确定 pdflatex 是否能工作。
% filename: beamerouterthemetest.sty
\mode<presentation>
\RequirePackage{tikz}
\newcount\progressbar@current
\newcount\progressbar@total
\newdimen\progressbar@curwidth
\newdimen\progressbar@width
\newdimen\progressbar@height
\progressbar@width=\paperwidth
\progressbar@height=1mm
% the progress bar
\def\progressbar@progressbar{%
\progressbar@current=\insertframenumber
\progressbar@total=\inserttotalframenumber
\advance\progressbar@current-1
\advance\progressbar@total-1
\progressbar@curwidth=\progressbar@width
\multiply\progressbar@curwidth by \progressbar@current
\divide\progressbar@curwidth by \progressbar@total
\begin{tikzpicture}[]
\draw[fill=fg] %
(0pt, 0pt) rectangle ++ (\progressbar@curwidth, \progressbar@height);
\end{tikzpicture}%
}
% THIS WORKS!!!!!!!!!!!!!!!!!!!
% Footline
\defbeamertemplate*{footline}{test}[1][] {
\ifnum\insertframenumber=1\relax%
\else
% Added next ifnum to avoid division by 0 crash in first run
\ifnum\inserttotalframenumber>1\relax%
\begin{beamercolorbox}[wd=\paperwidth]{progressbar}%
\progressbar@progressbar%
\end{beamercolorbox}%
\fi
\fi
}
% THIS DOESNT WORK!!!!!!!!!!!!!!!!!!!
% % Footline
% \defbeamertemplate*{footline}{test}[1][] {
% \ifnum\insertframenumber>1\relax%
% % Added next ifnum to avoid division by 0 crash in first run
% \ifnum\inserttotalframenumber>1\relax%
% \begin{beamercolorbox}[wd=\paperwidth]{progressbar}%
% \progressbar@progressbar%
% \end{beamercolorbox}%
% \fi
% \fi
% }
\mode<all>
% filename: test-example.tex
\documentclass[aspectratio=169]{beamer}
\useoutertheme{test}
\begin{document}
\begin{frame}{Slide 1}
\end{frame}
\begin{frame}{Slide 2}
\end{frame}
\begin{frame}{Slide 3}
\end{frame}
\begin{frame}{Slide 4}
\end{frame}
\begin{frame}{Slide 5}
\end{frame}
\begin{frame}{Slide 6}
\end{frame}
\begin{frame}{Slide 7}
\end{frame}
\end{document}
答案1
问题在于,beamer 在文档开头计算了框架几何形状,包括页脚线的高度。此时,框架编号显然不会大于 1,因此页脚高度计算为 0pt,因此页脚线不可见。
您可以通过确保页脚在文档开头具有合适的高度来避免此问题:
% filename: test-example.tex
\documentclass[aspectratio=169]{beamer}
\makeatletter
% filename: beamerouterthemetest.sty
\mode<presentation>
\RequirePackage{tikz}
\newcount\progressbar@current
\newcount\progressbar@total
\newdimen\progressbar@curwidth
\newdimen\progressbar@width
\newdimen\progressbar@height
\progressbar@width=\paperwidth
\progressbar@height=1mm
% the progress bar
\def\progressbar@progressbar{%
\progressbar@current=\insertframenumber
\progressbar@total=\inserttotalframenumber
\advance\progressbar@current-1
\advance\progressbar@total-1
\progressbar@curwidth=\progressbar@width
\multiply\progressbar@curwidth by \progressbar@current
\divide\progressbar@curwidth by \progressbar@total
\begin{tikzpicture}[]
\draw[fill=fg] %
(0pt, 0pt) rectangle ++ (\progressbar@curwidth, \progressbar@height);
\end{tikzpicture}%
}
%% THIS WORKS!!!!!!!!!!!!!!!!!!!
%% Footline
%\defbeamertemplate*{footline}{test}[1][] {
% \ifnum\insertframenumber=1\relax%
% \else
% % Added next ifnum to avoid division by 0 crash in first run
% \ifnum\inserttotalframenumber>1\relax%
% \begin{beamercolorbox}[wd=\paperwidth]{progressbar}%
% \progressbar@progressbar%
% \end{beamercolorbox}%
% \fi
% \fi
%}
% THIS DOESNT WORK!!!!!!!!!!!!!!!!!!!
% Footline
\defbeamertemplate*{footline}{test}[1][] {
\ifnum\insertframenumber>1%
% Added next ifnum to avoid division by 0 crash in first run
\ifnum\inserttotalframenumber>1\relax%
\begin{beamercolorbox}[wd=\paperwidth]{progressbar}%
\progressbar@progressbar%
\end{beamercolorbox}%
\fi
\else
\vskip0.2cm
\fi
}
\mode<all>
\makeatother
\begin{document}
\begin{frame}{Slide 1}
\end{frame}
\begin{frame}{Slide 2}
\end{frame}
\begin{frame}{Slide 3}
\end{frame}
\begin{frame}{Slide 4}
\end{frame}
\begin{frame}{Slide 5}
\end{frame}
\begin{frame}{Slide 6}
\end{frame}
\begin{frame}{Slide 7}
\end{frame}
\end{document}