Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R xaringan construct footer to include title/author automatically

Tags:

r

xaringan

I use xaringan to create a presentation (with a footer). The footer should include the title, and probably also the author of the presentation automatically.

To get the current slide number, I can use %current%, but %title% or %author$ fails. I know I can access the metadata like so in R rmarkdown::metadata$title, but I fail to construct the slideNumberFormat using R. I.e., r cat('<div class = "remark-slide-number-left">', rmarkdown::metadata$title, '</div>') does not work.

Any ideas?

MWE:

---
title: "Minimal Presenation"
author: "The Author"
output:
  xaringan::moon_reader:
    nature:
      slideNumberFormat: '<div class = "remark-slide-number-left"> %title% - %current%</div>'

---

# Hello World

here %title% does not work, the intended output format would be "Minimal Presentation".

The alternative (which also does not work) would be to construct the footer using R similar to this

slideNumberFormat: "`r cat('<div class = \"remark-slide-number-left\">', rmarkdown::metadata$title, ' - %current% </div>')`"
like image 574
David Avatar asked Jan 26 '26 07:01

David


2 Answers

With the help of some non-SO people, I was able to find this answer. The only drawback is, that it does not construct the footer in one element, but internally constructs two footers... Nonetheless, it allows the reuse of the author and title and other YAML elements.

The css style of the footer can (and should be) written to a css file similar to what @persephone did.

---
title: "Minimal Presentation"
author: "The Author"
output:
  xaringan::moon_reader:
    css: ["default"]
    nature:
      slideNumberFormat: "%current%"
---
layout: true
<div style="position: absolute;left:60px;bottom:11px;color:gray;">`r rmarkdown::metadata$author` - `r rmarkdown::metadata$title`</div>

---

# Hello World

First content slide

---
class: inverse, center, middle

# Section Header

---

# Foo Bar

Second content slide

like image 54
David Avatar answered Jan 27 '26 23:01

David


In general, I am not a huge fan of footers in presentations (they are mostly useless IMO/add unnecessary visual cluttering). However, some co-authors prefer to have them in conference presentations.

I also fiddled around with automatization but didn't find a perfect solution without putting much work into it.

Thus, my approach was to leave the slide numbering as is and just hardcode an extra footer with Authors/etc.

Add to a custom .css/style file/tweak to your needs:

div.footer {
    background-color: #5c6266;
    position: absolute;
    bottom: 10px;
    left: 0px;
    height: 25px;
    width: 20%;
}
div.footer span {
    font-size: 13pt; /*  */ 
    color: #f6f3f2;
    position: absolute;
    left: 15px;
    bottom: 1px;
}

Source it in your YAML:

css: ["default", custom.css"]

Add/Tweak this just before the 1st slide you want to include your footer in (e.g. after your title slide):

---
layout:true
<div class="footer"><span>John Doe et al.</span></div>
---

This is hacky but does not break the slide numbering and was the fastest solution I came up with in my context.

like image 28
persephone Avatar answered Jan 27 '26 23:01

persephone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!