Search code examples
rr-markdownknitrkableioslides

RMarkdown: How to resize a table to be displayed into a ioslides presentation?


I'm creating a presentation with RMarkdown to be displayed in ioslides. That being said, I'm having some trouble when it comes to display tables into slides, as they appear in there way smaller than I'd desire.

My code looks like follows:

library(kableExtra)
x <- data.frame(a = c("x", "y", "z"), b = c(1, 2, 3))
x %>% 
  kable() %>%
  kable_styling("striped", full_width = FALSE) %>%
  column_spec(2, bold = TRUE) %>%
  row_spec(1, color = "blue", background = "lightblue", bold = TRUE) %>%
  row_spec(2, color = "orange", background = "navajowhite", bold = TRUE) %>%
  row_spec(3, color = "red", background = "lightsalmon", bold = TRUE)

Here's a screenshot with the output I get when I knit it to ioslides:

enter image description here

I wish to expand this table so it fits better the room available into the slide and become more eye-friendly than now it is. I'd like also to center the subtitle as well.


Solution

  • What is eye-friendly is certainly in the eye of the beholder ;-). It may help to format the font size and print the header bold.

    To make the table wider, use the width argument in col_spec().

    I assume that you have created subtitle using markdown syntax (## subtitle). This is included in the HTML output as <h3>Subtitle</h3>. You can also use HTML and center it in the rmd file: <center><h3>subtitle</h3></center>. (Note that kable() also has the argument caption).

    x %>% 
     kable() %>%
     kable_styling("striped", full_width = F) %>%
     column_spec(2, width = "20em") %>%
     row_spec(0, bold = TRUE, font_size = 24) %>%
     row_spec(1, color = "blue", background = "lightblue", bold = TRUE) %>%
     row_spec(2, color = "orange", background = "navajowhite", bold = TRUE) %>%
     row_spec(3, color = "red", background = "lightsalmon", bold = TRUE)
    

    enter image description here