r-markdownxaringan

Xaringan: image resize option does not work for me


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
      
---


Solution

  • 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