Tan*_*a94 4 html r r-markdown kableextra
我正在使用posterdownR 中的包生成 HTML 海报并将其呈现为 PDF。
我的 Rmd 文件中有一个表格,但标题非常小。有没有办法增加标题的大小?
其次,我还想将标题中的标题和从属关系稍微向下移动(以便它更位于标题的中心。有没有办法做到这一点?
这是我的 Rmd 文件的片段
---
title: Here is my title
author:
- name: Name and Surname
affiliation:
address: Department, University
column_numbers: 3
logoright_name: https://raw.githubusercontent.com/brentthorne/posterdown/master/images/betterhexlogo.png
logoleft_name: https://raw.githubusercontent.com/brentthorne/posterdown/master/images/betterhexlogo.png
output:
posterdown::posterdown_html:
self_contained: false
knit: pagedown::chrome_print
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
# Intro
```{r table1, echo = FALSE, warning = FALSE, message = FALSE, results = 'asis', fig.pos='!h'}
library(tidyverse)
library(kableExtra)
col_1 <- c(1,2,3)
col_2 <- c(4,5,6)
col_3 <- c(7,8,9)
data.frame(col_1, col_2, col_3) %>%
kable(format='html',booktabs=TRUE, caption = "This is the caption", escape=F) %>%
kable_styling(font_size = 45)
```
`````
Run Code Online (Sandbox Code Playgroud)
对于标题,您有多种选择。<br>最简单的当然是在文档顶部的 YAML 标题前插入。这将在标题前插入一行回车符。
或者,您可以插入 CSS 块来更改标签的样式h1:
```{css, echo=FALSE}
h1 {
padding-top: 40px
}
```
Run Code Online (Sandbox Code Playgroud)
原则上,您应该能够包含这种 CSS 块来更改任何 HTML 元素的样式。然而,kableExtra似乎对字体大小进行了硬编码并忽略 CSS,因此该解决方案仅适用于某些样式元素。gsub一种巧妙的解决方案是使用或其他类似机制手动替换原始 HTML 中的字体大小:
```{css, echo=FALSE}
.table caption {
color: red;
font-weight: bold;
}
```
```{r table1, echo = FALSE, warning = FALSE, message = FALSE, results = 'asis', fig.pos='!h'}
library(kableExtra)
col_1 <- c(1,2,3)
col_2 <- c(4,5,6)
col_3 <- c(7,8,9)
data.frame(col_1, col_2, col_3) %>%
kbl(format = 'html',
escape = FALSE,
caption = "This is the caption") %>%
kable_styling(font_size = 45) %>%
gsub("font-size: initial !important;",
"font-size: 45pt !important;",
.)
```
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3349 次 |
| 最近记录: |