R markdown ioslides - 使用CSS更改kable字体大小

时间:2018-02-05 13:23:28

标签: css r markdown kable ioslides

我正试图在一张幻灯片上放一张大桌子。我正在使用kable。 我试过{.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%;
}

1 个答案:

答案 0 :(得分:2)

您可以通过修改css tabletd属性来做到这一点。

结果:

enter image description here

示例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文件中。

enter image description here

推荐读物:

而不是修改总体幻灯片格式。我建议您阅读将css格式应用于特定幻灯片的内容。例如,只有两个测试幻灯片。

https://bookdown.org/yihui/rmarkdown/custom-css-1.html#slide-ids-and-classes

我希望这可以为您指明正确的方向。