GeneralBeamer: Add the frame number to the footer

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
YuGiOhJCJ
Posts: 4
Joined: Tue Jul 20, 2021 9:21 am

Beamer: Add the frame number to the footer

Post by YuGiOhJCJ »

Hello,

With beamer, I would like to add the frame number to the footer.
I am using texlive 20200327.

Here is my code:

Code: Select all

\documentclass{beamer}
\usetheme{Warsaw}
\title{Beamer Example}

% https://texblog.net/latex-archive/uncategorized/beamer-footline-frame-number/
\newcommand*\oldmacro{}%
\let\oldmacro\insertshorttitle%
\renewcommand*\insertshorttitle{%
  \oldmacro\hfill%
  \insertframenumber\,/\,\inserttotalframenumber}

\begin{document}
	\begin{frame}
		\titlepage
	\end{frame}
	\section{First section}
	\begin{frame}
		abc
	\end{frame}
\end{document}
There is a problem in the output:
beamer.png
beamer.png (37.66 KiB) Viewed 18283 times
The frame number "1 / 2" at the bottom is not aligned to the right of the page.

How to fix that please?

Thank you.
Best regards.
Last edited by Stefan Kottwitz on Tue Jul 20, 2021 11:00 am, edited 1 time in total.
Reason: code marked, image uploaded

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Beamer: Add the frame number to the footer

Post by Bartman »

Please link your crossposts.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

Beamer: Add the frame number to the footer

Post by Stefan Kottwitz »

Hi,

welcome to the forum!

The footline template of the split theme contains this code:

Code: Select all

\insertshorttitle\nobreak\hfill
Because of the \hfill, there's empty space at the right. To remove that space and so getting the frame numbers right aligned, you could use the \@gobbletwo command that ignores the next two commands \nobreak\hfill:

Code: Select all

\makeatletter
\renewcommand*\insertshorttitle{%
  \oldmacro\hfill%
  \insertframenumber\,/\,\inserttotalframenumber\@gobbletwo}
\makeatother
As compilable document:

Code: Select all

\documentclass{beamer}
\usetheme{Warsaw}
\title{Beamer Example}

% https://texblog.net/latex-archive/uncategorized/beamer-footline-frame-number/
\newcommand*\oldmacro{}%
\let\oldmacro\insertshorttitle%
\makeatletter
\renewcommand*\insertshorttitle{%
  \oldmacro\hfill%
  \insertframenumber\,/\,\inserttotalframenumber\@gobbletwo}
\makeatother
\begin{document}
	\begin{frame}
		\titlepage
	\end{frame}
	\section{First section}
	\begin{frame}
		abc
	\end{frame}
\end{document}
It's a quick hack though. One could or should redefine the footline template with some more effort, but it works for now.

Stefan
LaTeX.org admin
samcarter
Posts: 3
Joined: Sat Feb 21, 2015 6:01 pm

Beamer: Add the frame number to the footer

Post by samcarter »

Let beamer do it for you:

Code: Select all

\documentclass{beamer}
\usetheme{Warsaw}
\title{Beamer Example}
\setbeamertemplate{page number in head/foot}[totalframenumber]
\begin{document}
\begin{frame}
abc
\end{frame}
\end{document}
document.png
document.png (18.89 KiB) Viewed 18273 times
Last edited by samcarter on Tue Jul 20, 2021 11:40 am, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

Beamer: Add the frame number to the footer

Post by Stefan Kottwitz »

The definition by samcarter is the best. Why it works - that's the footline template code:

Code: Select all

\defbeamertemplate*{footline}{split theme}
{%
  \leavevmode%
  \hbox{\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex,leftskip=.3cm plus1fill,rightskip=.3cm]{author in head/foot}%
    \usebeamerfont{author in head/foot}\insertshortauthor
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=1.125ex,leftskip=.3cm,rightskip=.3cm plus1fil]{title in head/foot}%
    \usebeamerfont{title in head/foot}\insertshorttitle\nobreak\hfill\usebeamercolor[fg]{page number in head/foot}\usebeamerfont{page number in head/foot}\usebeamertemplate{page number in head/foot}
  \end{beamercolorbox}}%
  \vskip0pt%
}
You can see that command at the end:

Code: Select all

\usebeamertemplate{page number in head/foot}
And that's what samcarter defined above.

Stefan
LaTeX.org admin
YuGiOhJCJ
Posts: 4
Joined: Tue Jul 20, 2021 9:21 am

Beamer: Add the frame number to the footer

Post by YuGiOhJCJ »

Bartman, sorry I forgot to link my crossposts.
Stefan Kottwitzn, thanks your solution with \@gobbletwo is working.
Samcarter, thanks your solution with \setbeamertemplate is working too.

I found the footline template definition in this file: /usr/share/texmf-dist/tex/latex/beamer/beamerouterthemesplit.sty.
In this file we can see \insertshorttitle\nobreak\hfill.

I was not aware that I was using the split theme.
Is it part of the Warsaw theme?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10321
Joined: Mon Mar 10, 2008 9:44 pm

Beamer: Add the frame number to the footer

Post by Stefan Kottwitz »

Beamer main themes are a combination of
  • inner themes: for elements, such as lists and blocks,
  • outer themes: for frame layout, such as footline and headline,
  • color themes: for color combinations,
  • font themes: with font settings.
Warsaw is basically

Code: Select all

\useinnertheme[shadow=true]{rounded}
\useoutertheme{shadow}
\usecolortheme{orchid}
\usecolortheme{whale}
\setbeamerfont{block title}{size={}}
And the shadow theme uses the split theme, where that definition is.

Similar with the other main presentation themes. To see what's actually used, we can take a look into the file or into the .log file to see which files are loaded.

Here you can click the "Run LaTeX here" button to get the log file:

Code: Select all

%!TeX log
\documentclass{beamer}
\usetheme{Warsaw}
\begin{document}
\begin{frame}
abc
\end{frame}
\end{document}
Here is the place starting line 666 in the log file where we can see the loaded theme files:

Code: Select all

...
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamerbasethemes.sty))
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamerthemedefault.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamerfontthemedefault.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamercolorthemedefault.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamerinnerthemedefault.sty
\beamer@dima=\dimen282
\beamer@dimb=\dimen283
)
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamerouterthemedefault.sty)))
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamerthemeWarsaw.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamerinnerthemerounded.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamerouterthemeshadow.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamerouterthemesplit.sty))
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamercolorthemeorchid.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/beamer/beamercolorthemewhale.sty))
Stefan
LaTeX.org admin
Post Reply