# How to place a figure representing progress percentage in a custom progress bar?

In a progress bar, I would like to place a percentage figure representing the amount of progress. The original code I obtained for the bar is from Progress bar for latex-beamer. The image below shows what I am looking to get but the 85% here is placed manually.

After trying to solve it by myself and looking on previous question I learnt that the command used to calculate percent progress is

\newcommand{\progressframepercent}{
\pgfmathprintnumber[fixed,precision=2]{\pgfmathresult}\,\%}}
}


However, the percent indicator is still vertically centered. To solve this, the box must have the same height of the progress bar with the contents being vertically centered.

\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}
\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
\edef\widthProgressBar{\the\dimen0}
\leavevmode%
%
% The bar itself
\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

\newcommand{\progressframepercent}{
\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}

• If you are using luatex, there are certainly ways (that I don't master) to do it. Some examples of ConTeXt presentation introduce that kind of progress bar. You may dig into ConTeXt wiki to find them. – sztruks Mar 17 at 10:38
• tex.stackexchange.com/a/59749/134144 shows how to autmatically calculate the percentage and use it in combination with a progress bar. – leandriis Mar 17 at 11:08
• @lendriis. I have successfully done the calculation and will modify the code accordingly, but I still need to know how to center the content vertically – Al-Motasem Aldaoudeyeh Mar 17 at 11:17

To vertically centre the percentage indicator, you could put the text in a \raisebox. The value of 0.02cm used below is just a quick guess, if necessary you can fine tune it further.

\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}
\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
\edef\widthProgressBar{\the\dimen0}
\leavevmode%
%
% The bar itself
\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

\newcommand{\progressframepercent}{
\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}


• This should work for now, but it is just interesting to ask how we align the percentage text automatically to horizontal middle of the bar – Al-Motasem Aldaoudeyeh Mar 18 at 5:37