R markdown ioslides - 使用 CSS 更改 kable 字体大小
R markdown ioslides - change kable font size with CSS
我想在一张幻灯片上放一张大 table。我正在使用电缆。
我尝试了 {.smaller}
但还不够,所以我想我会使用 .css 但它也不起作用。
我创建了一个示例演示文稿来说明问题。我试着编织它,它的显示方式与我的其他演示文稿相同(这很长,这就是我在这里排除它的原因)
我的代码:
---
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)
还有我的.css:
.test{
font-size: 50%;
}
您可以通过修改 css table
和 td
属性来做到这一点。
结果:
示例 CSS 和代码:
presentation.css
table.rmdtable td, table th {
font-size: 40%;
padding: 1em 0.5em;
line-height: 18px;
}
rmarkdownfile
---
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)
```
解释
我的建议是在浏览器中打开演示文稿,例如 chrome。启动开发工具并使用 css
属性。然后,您可以将其构建到您的演示文稿 .css 文件中。
推荐阅读:
而不是修改整个幻灯片格式。我建议您阅读有关将 css
格式应用于特定幻灯片的内容。例如只有你的两张测试幻灯片。
https://bookdown.org/yihui/rmarkdown/custom-css-1.html#slide-ids-and-classes
我希望这能为您指明正确的方向。
我想在一张幻灯片上放一张大 table。我正在使用电缆。
我尝试了 {.smaller}
但还不够,所以我想我会使用 .css 但它也不起作用。
我创建了一个示例演示文稿来说明问题。我试着编织它,它的显示方式与我的其他演示文稿相同(这很长,这就是我在这里排除它的原因)
我的代码:
---
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)
还有我的.css:
.test{
font-size: 50%;
}
您可以通过修改 css table
和 td
属性来做到这一点。
结果:
示例 CSS 和代码:
presentation.css
table.rmdtable td, table th {
font-size: 40%;
padding: 1em 0.5em;
line-height: 18px;
}
rmarkdownfile
---
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)
```
解释
我的建议是在浏览器中打开演示文稿,例如 chrome。启动开发工具并使用 css
属性。然后,您可以将其构建到您的演示文稿 .css 文件中。
推荐阅读:
而不是修改整个幻灯片格式。我建议您阅读有关将 css
格式应用于特定幻灯片的内容。例如只有你的两张测试幻灯片。
https://bookdown.org/yihui/rmarkdown/custom-css-1.html#slide-ids-and-classes
我希望这能为您指明正确的方向。