制作 beamer 进度条,可以指引讲演者或者是听者更加容易了解到整个 beamer 的进展和进度,下面是五个制作的进度条的样例,大家可以通过修改参数来自定义进度条的颜色、宽度、高度等属性。
第一个:
\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}
第三款,放在 beamer 底部的进度指示,颜色更加清晰:
\documentclass{beamer}
\usetheme{Darmstadt}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{xifthen}
\makeatletter
\newcommand{\Progressbar@LabelColor}{black}
\newcommand{\Progressbar@LabelText}{Label}
\newcommand{\Progressbar@LabelWidth}{5}
% Farbe, Text, Breite des Labels
\newcommand{\Progressbar@BarWidth}{10}
\newcommand{\Progressbar@BarHeight}{1}
\newcommand{\Progressbar@BarColor}{yellow}
\newcommand{\Progressbar@BarBorder}{black}
% Breite, Höhe, Schriftfarbe des Prozentsatzes, Rahmenfarbe des Fortschrittbalkens
\newcommand{\Progressbar@TodoA}{gray}
\newcommand{\Progressbar@TodoB}{black}
% Farbe 1 und 2 für den unerledigten Teil
\newcommand{\Progressbar@DoneA}{red}
\newcommand{\Progressbar@DoneB}{blue}
% Farbe 1 und 2 für den erledigten Teil
\newcommand{\Progressbar@Direction}{LTR}
% Modus links nach rechts oder umgekehrt; umgekehrt ist buggy (no support yet)
\newcommand{\Progressbar@Completion}{50}
% Fertigstellung in Prozent
\define@key{Progressbar}{LabelColor}[\Progressbar@LabelColor]{\renewcommand{\Progressbar@LabelColor}{#1}}
\define@key{Progressbar}{LabelText}[\Progressbar@LabelText]{\renewcommand{\Progressbar@LabelText}{#1}}
\define@key{Progressbar}{LabelWidth}[\Progressbar@LabelWidth]{\renewcommand{\Progressbar@LabelWidth}{#1}}
\define@key{Progressbar}{BarWidth}[\Progressbar@BarWidth]{\renewcommand{\Progressbar@BarWidth}{#1}}
\define@key{Progressbar}{BarHeight}[\Progressbar@BarHeight]{\renewcommand{\Progressbar@BarHeight}{#1}}
\define@key{Progressbar}{BarColor}[\Progressbar@BarColor]{\renewcommand{\Progressbar@BarColor}{#1}}
\define@key{Progressbar}{BarBorder}[\Progressbar@BarBorder]{\renewcommand{\Progressbar@BarBorder}{#1}}
\define@key{Progressbar}{TodoA}[\Progressbar@TodoA]{\renewcommand{\Progressbar@TodoA}{#1}}
\define@key{Progressbar}{TodoB}[\Progressbar@TodoB]{\renewcommand{\Progressbar@TodoB}{#1}}
\define@key{Progressbar}{DoneA}[\Progressbar@DoneA]{\renewcommand{\Progressbar@DoneA}{#1}}
\define@key{Progressbar}{DoneB}[\Progressbar@DoneB]{\renewcommand{\Progressbar@DoneB}{#1}}
\define@key{Progressbar}{Direction}[\Progressbar@Direction]{\renewcommand{\Progressbar@Direction}{#1}}
\define@key{Progressbar}{Completion}[\Progressbar@Completion]{\renewcommand{\Progressbar@Completion}{#1}}
\newcommand{\Progressbar}[1]%
{ \setkeys{Progressbar}{#1}
% Progress Bars --------------------------------------------------
\begin{tikzpicture}[overlay, remember picture,shift={($(current page.south west)+(0.1,0.1)$)}]
\ifthenelse{ \( \Progressbar@Completion = 0 \) \or \( \Progressbar@Completion = 100 \) }
{ \newcommand{\TCA}{\Progressbar@TodoA}
\newcommand{\TCB}{\Progressbar@TodoB}
\newcommand{\DCA}{\Progressbar@DoneA}
\newcommand{\DCB}{\Progressbar@DoneB}
}
{ \newcommand{\TCA}{\Progressbar@TodoB !\Progressbar@Completion !\Progressbar@TodoA}
\newcommand{\TCB}{\Progressbar@TodoB}
\newcommand{\DCA}{\Progressbar@DoneA}
\newcommand{\DCB}{\Progressbar@DoneB !\Progressbar@Completion !\Progressbar@DoneA}
}
\ifthenelse{\equal{\Progressbar@Direction}{LTR}}
{ \shade[left color=\DCA,right color=\DCB]%
(0,0) rectangle (\Progressbar@Completion * \Progressbar@BarWidth / 100,\Progressbar@BarHeight);
\shade[left color=\TCA,right color=\TCB]%
(\Progressbar@Completion * \Progressbar@BarWidth / 100,0)%
rectangle (\Progressbar@BarWidth,\Progressbar@BarHeight);
}
{ \shade[left color=\TCB,right color=\TCA]%
(0,0) rectangle (\Progressbar@Completion * \Progressbar@BarWidth / 100,\Progressbar@BarHeight);
\shade[left color=\DCB,right color=\DCA]%
(\Progressbar@Completion * \Progressbar@BarWidth / 100,0)%
rectangle (\Progressbar@BarWidth,\Progressbar@BarHeight);
}
\draw (0,0) rectangle (\Progressbar@BarWidth,\Progressbar@BarHeight);
\node[color=\Progressbar@BarColor] at%
(\Progressbar@BarWidth / 10,\Progressbar@BarHeight / 2) {\Progressbar@Completion \%};
\draw[color=white] (- \Progressbar@LabelWidth,0) -- %
node[anchor=west,color=\Progressbar@LabelColor,text width=\Progressbar@LabelWidth]%
{\Progressbar@LabelText} (- \Progressbar@LabelWidth,\Progressbar@BarHeight) ;
% \typeout{todo c1 = \TCA}
% \typeout{todo c2 = \TCB}
% \typeout{done c1 = \DCA}
% \typeout{done c2 = \DCB}
\end{tikzpicture}
}
\makeatother
\logo { \pgfmathsetmacro{\wid}{\the\paperwidth/28.45276-0.2}
\pgfmathtruncatemacro{\prog}{100*\insertpagenumber/\insertdocumentendpage}
\Progressbar{ LabelColor=yellow,%
LabelText=,%
LabelWidth=0,%
BarWidth=\wid,%
BarHeight=0.3,%
BarColor=green,%
BarBorder=black,%
TodoA=orange!20!gray,%
TodoB=orange!80!gray,%
DoneA=blue!80!cyan,%
DoneB=blue!20!cyan,%
Completion=\prog%
}
}
\begin{document}
\begin{frame}
\only<1>{Sha la la.}
\only<2>{Shu bi du.}
\only<3>{Tri Tra.}
\only<4>{Trullala.}
page - frame - totalpages : \insertpagenumber\ - \insertframenumber\ - \insertdocumentendpage
\end{frame}
\begin{frame}
\only<1>{One.}
\only<2>{Zwei.}
\only<3>{Tri.}
\only<4>{Quattro.}
\only<5>{Cinq.}
\only<6>{Seis.}
\only<7>{Siedem.}
\only<8>{Kahdeksan.}
page - frame - totalpages : \insertpagenumber\ - \insertframenumber\ - \insertdocumentendpage
\end{frame}
\end{document}
第四款,为进度条增加不同几何形状的点缀,显得进度条更加有质感。
\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
上面的内容放在一个 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}
第五款,更加简易的进度条设置
代码如下:
\setbeamercolor{progress bar progress}{use=progress bar,bg=progress bar.fg}
\defbeamertemplate{footline}{progress bar}{
\dimen0=\paperwidth
\multiply\dimen0 by \insertframenumber
\divide\dimen0 by \inserttotalframenumber
\edef\progressbarwidth{\the\dimen0}
\leavevmode%
\begin{beamercolorbox}[wd=\paperwidth,ht=1.75ex,dp=1ex]{progress bar}
\begin{beamercolorbox}[wd=\progressbarwidth,ht=1.75ex,dp=1ex]{progress bar progress}
\end{beamercolorbox}%
\end{beamercolorbox}%
}
使用的 时候,直接这样调用。
\setbeamertemplate{footline}[progress bar]
\setbeamercolor{progress bar}{fg=blue!50!black,bg=white!50!black}
选自:https://tex.stackexchange.com/questions/59742/progress-bar-for-latex-beamer