0

For some reason, ![:scale 50%](image.jpg) does not work for me. Any solution to fix this?

My yaml heading is the following:

---
title: "Econ"
subtitle: "Orientation and Lecture 1"
author: "Teacher"
institute: "University"
date: "`r Sys.Date()`"
output: 
  xaringan::moon_reader:
    css: [default, metropolis, metropolis-fonts, "styles.css"]
    lib_dir: libs
    nature:
      highlightStyle: arta
      highlightLines: true
      countIncrementalSlides: false
      
---

jck21
  • 751
  • 4
  • 16

1 Answers1

1

To scale an image in xaringan slides (in R-markdown), a safe option is using knitr::include_graphics along with chunk options.


```{r echo=FALSE, out.width="50%"}
knitr::include_graphics("test_animal.jpg")
```

Update

If you want to fill the entire slide with an image you can use background-image and background-size option in xaringan slides to do that.

---
title: "Econ"
subtitle: "Lecture 1"
author: "Instructor"
institute: "College"
date: "`r Sys.Date()`"
output: 
  xaringan::moon_reader:
    css: [default, metropolis, metropolis-fonts, "styles.css"]
    lib_dir: libs
    nature:
      highlightStyle: arta
      highlightLines: true
      countIncrementalSlides: false
    
---

---
background-image: url(test_animal.jpg)
background-size: cover
shafee
  • 15,566
  • 3
  • 19
  • 47
  • thanks so much. I also add out.height="50%", out.width="150%", but in this case, out.height option does not work. I am trying to make image fill the entire slide using both options but I cannot use both option effective? Can you give me a tip? – jck21 Aug 05 '22 at 14:40
  • @joe, see my update. – shafee Aug 05 '22 at 14:51
  • thank you. I tried `{r, echo = FALSE, out.height="50%"}` but `out.height` option is not working. Why is it? Am I missing something here? – jck21 Aug 06 '22 at 13:48
  • No, I am not sure why its not working, `out.height`, `out.width` should work. – shafee Aug 06 '22 at 14:25