Search code examples
rlatexr-markdownmarkdownbeamer

Insert the number of slides up to a final slide in a rmarkdown::beamer_presentation


In a beamer presentation generated with rmarkdown::beamer_presentation, I currently have \insertframenumber/\inserttotalframenumber which shows the current page and the total number of slides in the presentation.

How to insert the number of slides up to a "final slide" in the footer instead of the overall "total number of slides"?

Note: I would like to refrain from having to add {.noframenumbering} to all slides in the appendix.

MWE

Preamble.tex

\setbeamertemplate{footline}{
    \leavevmode%
    \hfill
        \hyperlinkappendixstart{\insertframenumber/\inserttotalframenumber}
}

Presentation.Rmd

---
title: "Slide counter ends at specific slide"
output:
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    latex_engine: lualatex
    toc: false
    slide_level: 2
header-includes:
  - \input{files_beamer/preamble}
---

## Slide 1

## Slide 2

## Slide Final
==> count up to this slide

``` {=latex}
\insertframeendpage
```

## Additional Slide 1 (not counted)

## Additional Slide 2 (not counted)

Solution

  • If your beamer version is up-to-date, you can use the \setbeamertemplate{page number in head/foot}[appendixframenumber] template. No need for additional packages.

    ---
    title: "Slide counter ends at specific slide"
    output:
      bookdown::pdf_book:
        base_format: rmarkdown::beamer_presentation
        latex_engine: lualatex
        toc: false
        slide_level: 2
        keep_tex: true
    header-includes: |
      \makeatletter\beamer@ignorenonframefalse\makeatother
    
      \setbeamertemplate{page number in head/foot}[appendixframenumber]
    
      \setbeamertemplate{footline}{%
        \leavevmode%
        \hfill
        \hyperlinkappendixstart{%
          \usebeamertemplate{page number in head/foot}%
        }
      }
    
    ---
    
    ## Slide 1
    
    ## Slide 2
    
    ## Slide Final
    ==> count up to this slide
    
    ``` {=latex}
    \end{frame}
    \appendix
    \begin{frame}
    \frametitle{Additional Slide 1 (not counted)}
    ```
    
    ## Additional Slide 2 (not counted)
    

    enter image description here