How can I insert page number to rmarkdown beamer slides?
Asked Answered
S

4

18

How can I show page numbers (preferably like 4/10, 5/10 etc.) on an rmarkdown beamer presentation?

Severally answered 20/11, 2014 at 20:1 Comment(0)
P
21

In the front matter of the document, you can include a .tex file with extra commands as shown in RStudio's documentation here.

I created a new .tex file that I called "header_pagenrs.tex" which only includes the top 2 lines from @user4281727's answer:

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[page number]

Then I referenced this file at the top of my .Rmd file:

---
title: "Things and Stuff"
author: "Me"
output:
  beamer_presentation:
    includes:
      in_header: header_pagenrs.tex
---

If this still gives you errors, you might also be missing some required TeX packages (a separate problem from RStudio and rmarkdown).

Psychic answered 31/7, 2016 at 19:18 Comment(5)
Is it possible to remove the page number from the title page?Barranca
I'm afraid I don't know how!Psychic
@Psychic I have been using this script for well over a year now, but today it is failing... MAC OSX 10.13.6, R 3.5.2 RStudio 1.1.463. To clarify: same exact document, just recompiling. Now no page number outputs... the header_pagenrs.tex file seems to be causing the include: ... theme: output to malfunction as wellHousemaid
After updating all LaTeX packages, this is largely resolved. The theme I was using ("Malmoe") still has problems; but a switch to a new theme resolves.Housemaid
Glad to hear that updating packages helped. Unfortunately I have no ideas about how to fix the issue with your original theme.Psychic
N
4

Here's another option that worked for me. Didn't need to add a .tex file to my folder. Just included the following (based on above code from @civilstat) at the top of my Markdown doc.

---
title: 'Your Title'
author: "Your Name"
date: "July 4, 1776"
output:
  beamer_presentation(keep_tex = TRUE): default

header-includes:

- \setbeamertemplate{navigation symbols}{}
- \setbeamertemplate{footline}[page number]
---
Nsf answered 24/4, 2022 at 21:5 Comment(0)
S
2

If your beamer version is reasonable up to date (>= v3.48), you can adjust the format of the frame numbers while keeping the footline of your chosen beamer theme unchanged otherwise.

---
output: 
  beamer_presentation:
    theme: "Berlin"
    keep_tex: true
header-includes:
  - \setbeamertemplate{page number in head/foot}[totalframenumber]
---

test

enter image description here

Signatory answered 30/10, 2019 at 14:59 Comment(6)
Doesn't do a thing with pandoc. What am I missing?Emit
@Emit Is your beamer version new enough? (>=v3.48)Signatory
How do I check (beamer version) via command line? You ask a pertinent question.Emit
@Emit There should be a .log file in the same folder as the .tex file.This log file should include the version numberSignatory
There is no log file... I am using pandoc -t beamer foo.md -o foo.pdf.Emit
@Emit I don't know if this rmarkdown syntax with the header includes works for markdown. if yes the keep_tex option should make sure that the log file is also keptSignatory
B
0

Try to put the lines below into the template

\setbeamertemplate{navigation symbols}{}

\setbeamertemplate{footline}[page number]

~/Library/R/3.1/library/rmarkdown/rmd/beamer/default.tex
Bijouterie answered 22/11, 2014 at 12:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.