html - 使用 kable 垂直对齐列名并使用 rmarkdown 渲染到 html
问题描述
创建了下表,并希望在单元格的中心/中间垂直对齐单词“物种”。我RMarkdown
用来生成 HTML 而不是 LateX。有小费吗?
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE )
library( kableExtra )
options( scipen = 99 )
```
```{r iris}
tab_iris <- knitr::kable( iris , format = "html" , col.names = c( "Sepal<br>Length" , "Sepal<br>Width" , "Petal<br>Length" , "Petal<br>Width" , "Species" ) , align = "c" , escape = F ) %>% kable_styling(full_width = F , bootstrap_options = c( 'hover', 'condensed' , 'bordered'), position = 'left') %>% add_header_above( c('Kendal Iris Test' = 5) , bold = TRUE , background = '#0077c8' , color = 'white' )
```
`r tab_iris`
解决方案
您可以使用kableExtra::row_specs
及其extra_css
参数:
library(knitr)
library(kableExtra)
kable( head(iris) , format = "html" ,
col.names = c( "Sepal<br>Length" , "Sepal<br>Width" ,
"Petal<br>Length" , "Petal<br>Width" , "Species" ) ,
align = "c" , escape = F ) %>%
kable_styling(full_width = F , bootstrap_options = c( 'hover', 'condensed' , 'bordered'),
position = 'left') %>%
add_header_above( c('Kendal Iris Test' = 5) , bold = TRUE ,
background = '#0077c8' , color = 'white' ) %>%
kable_styling(full_width = T) %>%
row_spec(0 , bold = F, extra_css = 'vertical-align: middle !important;')
推荐阅读
- oracle - VarChar可以由什么组成?
- r - 如何在R中恢复反斜杠符号的形状
- xtext - 有没有办法在 xtext 中自定义 Content Assist?
- windows - CL.EXE 到 gcc 编译器
- python - 如何在 Python 中获取 Kibana 可视化 SVG
- python - 在 idp.generic 之后无法使用 python 打开 jupyter notebook
- sql - 仅当所有记录都满足条件时才对多条记录执行更新
- react-native - 使用密码反应本机加密文件
- c# - 获取与日期相关的到期日期
- android - 在 Database Inspector 中打开加密数据库