在进度条中,我想放置一个百分比数字来表示进度量。我获得的进度条原始代码来自latex-beamer 的进度条。下图显示了我想要得到的东西,但这里的 85% 是手动放置的。
在尝试自己解决这个问题并查看了之前的问题后,我了解到用于计算进度百分比的命令是
\newcommand{\progressframepercent}{
{\textnormal{\pgfmathparse{\insertframenumber*100/\inserttotalframenumber}%
\pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\%}}
}
但是,百分比指示器仍是垂直居中的。要解决这个问题,框必须具有与进度条相同的高度,并且内容垂直居中。
\documentclass[aspectratio=169, xcolor={x11names}]{beamer}
\usecolortheme{rose}
\setbeamercolor{itemize item}{fg=black}
\useoutertheme{miniframes}
\useinnertheme{inmargin}
\setbeamersize{text margin left=2mm, text margin right=2mm}
\newlength{\sidebarWidth}
\setlength{\sidebarWidth}{0.2\paperwidth}
\setbeamersize{sidebar width left=\sidebarWidth, sidebar width right=0cm}
\usefonttheme{structurebold}
\usepackage{tikz}
\usetikzlibrary{calc}
% Custom progress bar
% BEGIN_FOLD
\setbeamercolor{progress bar progress}{use=progress bar,bg=progress bar.fg}
\newlength{\heightNavigationSymbol}
\setlength{\heightNavigationSymbol}{2.5mm} % around 2.5mm or 7.1pt
\newlength{\widthProgressBarFull}
\setlength{\widthProgressBarFull}{\sidebarWidth}
\newcommand{\totalslideinframe}{0}
\defbeamertemplate{footline}{progress bar}{
% Calculate bars widths
\dimen0=\widthProgressBarFull
\multiply\dimen0 by \insertframenumber
\divide\dimen0 by \inserttotalframenumber
\edef\widthProgressBar{\the\dimen0}
\leavevmode%
%
% The bar itself
\begin{beamercolorbox}[wd=\widthProgressBarFull, ht=\heightNavigationSymbol, dp=1ex]{progress bar}
\begin{beamercolorbox}[wd=\widthProgressBar, ht=\heightNavigationSymbol, dp=1ex]{progress bar progress}
\end{beamercolorbox}%
\end{beamercolorbox}%
{\hspace{-\widthProgressBarFull}\color{white} \adjustbox{minipage={\sidebarWidth}, frame}{\hspace*{\fill} $\progressframepercent$ \hspace*{\fill}}}%
}
\setbeamertemplate{footline}[progress bar]
\setbeamercolor{progress bar}{fg=DodgerBlue3,bg=PeachPuff3}
% END_FOLD
\usepackage{adjustbox}
\newcommand{\progressframepercent}{
{\textnormal{\pgfmathparse{\insertframenumber*100/\inserttotalframenumber}%
\pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\%}}
}
\begin{document}
\begin{frame}
Some contents
\end{frame}
\begin{frame}
Some contents
\end{frame}
\begin{frame}
Some contents
\end{frame}
\begin{frame}
Some contents
\end{frame}
\begin{frame}
Some contents
\end{frame}
\end{document}
答案1
要使百分比指示器垂直居中,您可以将文本放在 中\raisebox
。下面使用的 值0.02cm
只是一个快速猜测,如有必要,您可以进一步微调它。
\documentclass[aspectratio=169, xcolor={x11names}]{beamer}
\usecolortheme{rose}
\setbeamercolor{itemize item}{fg=black}
\useoutertheme{miniframes}
\useinnertheme{inmargin}
\setbeamersize{text margin left=2mm, text margin right=2mm}
\newlength{\sidebarWidth}
\setlength{\sidebarWidth}{0.2\paperwidth}
\setbeamersize{sidebar width left=\sidebarWidth, sidebar width right=0cm}
\usefonttheme{structurebold}
\usepackage{tikz}
\usetikzlibrary{calc}
% Custom progress bar
% BEGIN_FOLD
\setbeamercolor{progress bar progress}{use=progress bar,bg=progress bar.fg}
\newlength{\heightNavigationSymbol}
\setlength{\heightNavigationSymbol}{2.5mm} % around 2.5mm or 7.1pt
\newlength{\widthProgressBarFull}
\setlength{\widthProgressBarFull}{\sidebarWidth}
\newcommand{\totalslideinframe}{0}
\defbeamertemplate{footline}{progress bar}{
% Calculate bars widths
\dimen0=\widthProgressBarFull
\multiply\dimen0 by \insertframenumber
\divide\dimen0 by \inserttotalframenumber
\edef\widthProgressBar{\the\dimen0}
\leavevmode%
%
% The bar itself
\begin{beamercolorbox}[wd=\widthProgressBarFull, ht=\heightNavigationSymbol, dp=1ex]{progress bar}
\begin{beamercolorbox}[wd=\widthProgressBar, ht=\heightNavigationSymbol, dp=1ex]{progress bar progress}
\end{beamercolorbox}%
\end{beamercolorbox}%
\raisebox{0.02cm}{\hspace{-\widthProgressBarFull}\color{white} \adjustbox{minipage={\sidebarWidth}, frame}{\hspace*{\fill} $\progressframepercent$ \hspace*{\fill}}}%
}
\setbeamertemplate{footline}[progress bar]
\setbeamercolor{progress bar}{fg=DodgerBlue3,bg=PeachPuff3}
% END_FOLD
\usepackage{adjustbox}
\newcommand{\progressframepercent}{
{\textnormal{\pgfmathparse{\insertframenumber*100/\inserttotalframenumber}%
\pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\%}}
}
\begin{document}
\begin{frame}
Some contents
\end{frame}
\begin{frame}
Some contents
\end{frame}
\begin{frame}
Some contents
\end{frame}
\begin{frame}
Some contents
\end{frame}
\begin{frame}
Some contents
\end{frame}
\end{document}