I'm trying to fit a large table on one slide. I'm using kable.
I tried {.smaller}
but it's not quite enough so I thought I'd use a .css but it isn't working either.
I created a sample presentation to illustrate the problem. I tried knitting it and it shows up the same way as in my other presentation (which is quite long which is why I excluded it here)
My code:
---
title: "test"
author: "Test Author"
date: "5 Februar 2018"
output:
ioslides_presentation:
test: presentation.css
---
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
## Test slide
{r}
table <- data.frame(
index=1:10,
long_text=c("long text here: asdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf")
)
kable(table)
## Test slide css {.test}
{r}
table <- data.frame(
index=1:10,
long_text=c("long text here: asdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf")
)
kable(table)
And my .css:
.test{
font-size: 50%;
}
You can do this by modifying the css table
and td
attributes.
Example CSS and Code:
table.rmdtable td, table th {
font-size: 40%;
padding: 1em 0.5em;
line-height: 18px;
}
---
title: "test"
author: "Test Author"
date: "5 Februar 2018"
output:
ioslides_presentation:
css: presentation.css
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(knitr)
```
## Test slide
```{r}
table <- data.frame(
index=1:10,
long_text=c("long text here: asdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf")
)
kable(table)
```
## Test slide css {.test}
```{r}
table <- data.frame(
index=1:10,
long_text=c("long text here: asdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasfasdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf",
"long text here: asdfghhjoqweqwrqwrqwrasf")
)
kable(table)
```
My recommendation is you open the presentation in your browser, for example, chrome. Launch the development tools and play with the css
attributes. You can then build this into your presentation .css file.
Rather than modifying the overall slide deck formatting. I'd recommend you read up on applying css
formatting to specific slides. For example only your two test slides.
https://bookdown.org/yihui/rmarkdown/custom-css-1.html#slide-ids-and-classes
I hope this points you in the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With