如何在自訂進度欄中放置表示進度百分比的數字?

如何在自訂進度欄中放置表示進度百分比的數字?

在進度條中,我想放置一個代表進度的百分比數字。我獲得的酒吧原始代碼來自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}

在此輸入影像描述

相關內容