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

标签 css r markdown kable ioslides

我想在一张幻灯片上放一张大 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 tabletd 属性来做到这一点。

结果:

enter image description here

示例 CSS 和代码:

演示文稿.css

table.rmdtable td, table th {
    font-size: 40%;
    padding: 1em 0.5em;
    line-height: 18px;
}

rmarkdown文件

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

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

关于css - R markdown ioslides - 使用 CSS 更改 kable 字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48623591/

相关文章:

markdown - 批处理 docx 到 Markdown

php - Preg_replace 到 Preg_replace All

php - 将 markdown 列表转换为 PHP 中的 html 列表

javascript - 未捕获的类型错误 : Cannot read property 'startAngle'

jquery - 在移动屏幕上调整窗口大小后的空白矩形

html - 如何并排对齐 2 张图像,其中 1 张 float 在左侧,另一张 float 在右侧?

r - 在数据框的开头插入列

sql - dplyr 将列粘贴到远程数据库中

html - 如何为行标题和列标题创建单元格

没有名称的 rbind data.frames