latex-beamer 的进度条

latex-beamer 的进度条

除了幻灯片编号之外,我发现在底部有一个不显眼的进度条之类的东西非常好,每个幻灯片的进度条长度约为(屏幕宽度)/(幻灯片编号)。

我发现这里(德文页面)以下代码片段:

%%-----------------------------------------------------------------------
%% progress bar in footline
%% http://www.mrunix.de/forums/showpost.php?p=316577&postcount=3
%% -----------------------------------------------------------------------
\definecolor{lightgr}{rgb}{0.7 0.7 0.7}
\makeatletter
\addtobeamertemplate{footline}{%
  \color{lightgr}% to color the progressbar
  \hspace*{-\beamer@leftmargin}%
  \rule{\beamer@leftmargin}{2pt}%
  \rlap{\rule{\dimexpr
      \beamer@startpageofframe\dimexpr
      \beamer@rightmargin+\textwidth\relax/\beamer@endpageofdocument}{1pt}}
  % next 'empty' line is mandatory!

  \vspace{0\baselineskip}
  {}
}

一开始它工作正常,但是在我添加了一定数量的帧之后,它突然出现以下错误信息:

! Dimension too large.
<argument> ...amer@rightmargin +\textwidth \relax 
                                                  /\beamer@endpageofdocument 
l.517 \lyxframeend

我花了几个小时才弄清楚进度条导致了错误消息,因为只有当我添加某些图像时才会抛出该消息。但我无法弄清楚任何系统何时出现错误,何时不出现错误。有时可以毫无问题地添加新框架,有时则不行。有时当我使用 pdfpages 添加页面时会发生错误。

我使用 LyX(如您所见)和匹兹堡主题,但我认为这样的(运行)进度条片段对于许多用户来说都会很有趣(也包括那些使用其他主题而没有 LyX 的用户)。

一个框架的屏幕截图来说明结果:

截屏

我的问题:

  • 有没有办法让这个代码更稳定并与任何主题兼容?
  • 将其变成一个包裹容易吗?
  • 我怎样才能将其更改\beamer@startpageofframe为真实的 PDF 页码?(否则进度条会出现很大且突然的跳跃。)

(如果我需要提供更多信息,请评论,例如我的整个 LyX 文件。)

答案1

这里有一些可自定义的进度条(我正在开展的项目的一部分):

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

\definecolor{pbblue}{HTML}{0A75A8}% filling color for the progress bar
\definecolor{pbgray}{HTML}{575757}% background color for the progress bar

\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=\linewidth
\progressbar@pbht=1.5ex

% the progress bar
\def\progressbar@progressbar{%

    \progressbar@tmpcounta=\insertframenumber
    \progressbar@tmpcountb=\inserttotalframenumber
    \progressbar@tmpdim=\progressbar@pbwd
    \multiply\progressbar@tmpdim by \progressbar@tmpcounta
    \divide\progressbar@tmpdim by \progressbar@tmpcountb

  \begin{tikzpicture}[rounded corners=2pt,very thin]

    \shade[top color=pbgray!20,bottom color=pbgray!20,middle color=pbgray!50]
      (0pt, 0pt) rectangle ++ (\progressbar@pbwd, \progressbar@pbht);

      \shade[draw=pbblue,top color=pbblue!50,bottom color=pbblue!50,middle color=pbblue] %
        (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{%
             \pgfmathparse{\insertframenumber*100/\inserttotalframenumber}%
             \pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\%%
        }%
    };
  \end{tikzpicture}%
}

\addtobeamertemplate{headline}{}
{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=4ex,center,dp=1ex]{white}%
    \progressbar@progressbar%
  \end{beamercolorbox}%
}
\makeatother

\begin{document}

\begin{frame}
test
\end{frame}

\begin{frame}
test
\end{frame}

\begin{frame}
test
\end{frame}

\begin{frame}
test
\end{frame}

\end{document}

在此处输入图片描述

酒吧的特写图片:

在此处输入图片描述

两个小变化;首先使用圆圈作为进度指示器:

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

\definecolor{pbblue}{HTML}{0A75A8}% color for the progress bar and the circle

\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@rcircle % radius for the circle
\newdimen\progressbar@tmpdim % auxiliary dimension

\progressbar@pbwd=\linewidth
\progressbar@pbht=1pt
\progressbar@rcircle=2.5pt

% the progress bar
\def\progressbar@progressbar{%

    \progressbar@tmpcounta=\insertframenumber
    \progressbar@tmpcountb=\inserttotalframenumber
    \progressbar@tmpdim=\progressbar@pbwd
    \multiply\progressbar@tmpdim by \progressbar@tmpcounta
    \divide\progressbar@tmpdim by \progressbar@tmpcountb

  \begin{tikzpicture}
    \draw[pbblue!30,line width=\progressbar@pbht]
      (0pt, 0pt) -- ++ (\progressbar@pbwd,0pt);

    \filldraw[pbblue!30] %
      (\the\dimexpr\progressbar@tmpdim-\progressbar@rcircle\relax, .5\progressbar@pbht) circle (\progressbar@rcircle);

    \node[draw=pbblue!30,text width=3.5em,align=center,inner sep=1pt,
      text=pbblue!70,anchor=east] at (0,0) {\insertframenumber/\inserttotalframenumber};
  \end{tikzpicture}%
}

\addtobeamertemplate{headline}{}
{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=4ex,center,dp=1ex]{white}%
    \progressbar@progressbar%
  \end{beamercolorbox}%
}
\makeatother

\begin{document}

\begin{frame}
test
\end{frame}

\begin{frame}
test
\end{frame}

\begin{frame}
test
\end{frame}

\begin{frame}
test
\end{frame}

\end{document}

在此处输入图片描述

特写一下:

在此处输入图片描述

现在使用三角形作为进度指示器(受主题启发伊格纳西在他的回答中提到):

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

\definecolor{pbgray}{HTML}{575757}% background color for the progress bar

\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=\linewidth
\progressbar@pbht=1pt

% the progress bar
\def\progressbar@progressbar{%

    \progressbar@tmpcounta=\insertframenumber
    \progressbar@tmpcountb=\inserttotalframenumber
    \progressbar@tmpdim=\progressbar@pbwd
    \multiply\progressbar@tmpdim by \progressbar@tmpcounta
    \divide\progressbar@tmpdim by \progressbar@tmpcountb

  \begin{tikzpicture}[very thin]
    \draw[pbgray!30,line width=\progressbar@pbht]
      (0pt, 0pt) -- ++ (\progressbar@pbwd,0pt);
    \draw[draw=none]  (\progressbar@pbwd,0pt) -- ++ (2pt,0pt);

    \draw[fill=pbgray!30,draw=pbgray] %
       ( $ (\progressbar@tmpdim, \progressbar@pbht) + (0,1.5pt) $ ) -- ++(60:3pt) -- ++(180:3pt) ;

    \node[draw=pbgray!30,text width=3.5em,align=center,inner sep=1pt,
      text=pbgray!70,anchor=east] at (0,0) {\insertframenumber/\inserttotalframenumber};
  \end{tikzpicture}%
}

\addtobeamertemplate{headline}{}
{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=5ex,center,dp=1ex]{white}%
    \progressbar@progressbar%
  \end{beamercolorbox}%
}
\makeatother

\begin{document}

\begin{frame}
test
\end{frame}

\begin{frame}
test
\end{frame}

\begin{frame}
test
\end{frame}

\begin{frame}
test
\end{frame}

\end{document}

在此处输入图片描述

特写一下:

在此处输入图片描述

答案2

对于 ConTeXt,我编写了一个模块视觉计数器允许可视化任何 ConTeXt 计数器。它提供了一些预定义的可视化工具。

查看文档了解详情。基本用法是

\usemodule[visualcounter]


\definevisualcounter
  [pagevisualized] % visualizer
  [progressbar] % inherit from
  [counter=userpage]


\usevisualcounter{pagevisualizer}

其中第一个参数是您要定义的可视化工具的名称,第二个(可选)参数是可从中继承设置的预定义可视化工具,counter 是可视化工具应显示的计数器的名称。tests/有关详细示例,请参阅 github 上的子目录。

下图显示了四个用于页码和条目列出的可视化工具。

在此处输入图片描述

答案3

Sylvain Bouveret 已经为 beamer 开发了一个进度条主题。你可以在他的网页。这是一个“完整”(内部、外部、颜色、字体)主题,但这里有一个仅使用的小例子\useoutertheme{progressbar}。Bootom 三角形根据实际幻灯片在线下移动。

在此处输入图片描述

答案4

我的实现为您提供了导航和进度条:您可以通过单击某些导航框跳转到任何框架。

Beamer 主题 Mathz

首先保存以下代码为beamerouterthemeprogress.sty文件:

\makeatletter

\AtBeginSection[]{\frame{\sectionpage}}
\AtBeginSubsection[]{\frame{\subsectionpage}}

\newcommand{\my@bigsize}{9}
\newcommand{\my@medsize}{7}
\newcommand{\my@smallsize}{5}

\newlength{\my@tempsize}

\newcounter{my@sectnum}

\newcommand{\my@lastdigit}[1]{%
  \loop\ifnum\value{#1}>9\addtocounter{#1}{-10}\repeat
  \arabic{#1}%
}

\newcommand\my@fixedbox[2]{%
  \makebox[#1]{\rule[-1ex]{0pt}{3.25ex}#2}%
}

\newcommand\my@colorbox[3]{%
  {\setlength{\fboxsep}{0pt}\colorbox{#1}{\my@fixedbox{#2}{#3}}}%
}

\def\my@temptext{}

\newcommand{\my@navbox}[1][]{%
  \if\relax\detokenize{#1}\relax
    \def\my@tempbox{\my@fixedbox}%
  \else
    \def\my@tempbox{\my@colorbox{#1}}%
  \fi
  \ifx\my@box\my@bigbox
    \def\my@temptext{\my@lastdigit{my@sectnum}}%
  \fi
  \ifx\my@box\my@medbox
    \def\my@temptext{$\diamond$}%
  \fi
  \ifx\my@box\my@smallbox
    \def\my@temptext{$-$}%
  \fi
  \my@tempbox{\my@tempsize}{\my@temptext}%
}

\defbeamertemplate{navigation box}{home}{%
  \setlength{\my@tempsize}{\my@box@size pt}%
  \my@colorbox{teal!60}{\my@tempsize}{$\equiv$}%
}

\defbeamertemplate{navigation box}{done}{%
  \setlength{\my@tempsize}{\my@box@size pt}%
  \my@navbox[teal!60]%
}

\defbeamertemplate{navigation box}{todo}{%
  \setlength{\my@tempsize}{\my@box@size pt}%
  \my@navbox
}

\newcommand{\my@bigbox}{\global\let\my@box@size=\my@bigsize\usebeamertemplate{navigation box}}
\newcommand{\my@medbox}{\global\let\my@box@size=\my@medsize\usebeamertemplate{navigation box}}
\newcommand{\my@smallbox}{\global\let\my@box@size=\my@smallsize\usebeamertemplate{navigation box}}

\renewcommand{\sectionentry}[5]{\global\let\my@box=\my@bigbox\setcounter{my@sectnum}{#1}}
\renewcommand{\beamer@subsectionentry}[5]{\global\let\my@box=\my@medbox}

\renewcommand{\slideentry}[6]{%
  \def\my@temp@i{1/1}%
  \def\my@temp@ii{#4}%
  \ifx\my@temp@i\my@temp@ii % title page
    \setbeamertemplate{navigation box}[home]%
  \else
    \setbeamertemplate{navigation box}[done]%
  \fi
  \ifnum\c@section<#1%
    \setbeamertemplate{navigation box}[todo]%
  \else
    \ifnum\c@section=#1\ifnum\c@subsection<#2%
      \setbeamertemplate{navigation box}[todo]%
    \else
      \ifnum\c@subsection=#2\ifnum\c@subsectionslide<#3%
        \setbeamertemplate{navigation box}[todo]%
      \fi\fi
    \fi\fi
  \fi
  \ifx\my@temp@i\my@temp@ii % title page
    \beamer@link(#4){\my@bigbox}%
  \else
    \beamer@link(#4){\my@box}%
  \fi
  \global\let\my@box=\my@smallbox
}

\defbeamertemplate{footline}{progress}
{%
  {\color{teal}\hrule}\hbox{%
  \begin{beamercolorbox}[wd=.8\paperwidth,ht=2.25ex,dp=1ex,left]{footline}%
    \kern2em\dohead
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.2\paperwidth,ht=2.25ex,dp=1ex,right]{footline}%
    \insertframenumber{}/\inserttotalframenumber\kern2em
  \end{beamercolorbox}%
  }%
}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[progress]

\makeatother

然后,您可以创建一个 beamer 文件来测试这个外部主题(将其放在与beamerouterthemeprogress.sty文件):

\documentclass{beamer}

\useoutertheme{progress}
\setbeamercolor{background canvas}{bg=lightgray}

\begin{document}

\title{Beamer Theme Math}
\author{Author Name}

\begin{frame}
\titlepage
\end{frame}

\section{Name One}

\subsection{Subname One}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\subsection{Subname Two}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\subsection{Subname Three}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\section{Name Two}

\subsection{Subname One}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\subsection{Subname Two}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\subsection{Subname Three}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\section{Name Three}

\subsection{Subname One}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\subsection{Subname Two}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\subsection{Subname Three}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\begin{frame}{Frame Title}
Frame \insertframenumber
\end{frame}

\end{document}

相关内容