Vertical align kable's column name

2019-05-24 10:05发布

Suppose the next example:

library(knitr)
library(kableExtra)

df <- data.frame(a = letters[1:10], b = 1:10)

names(df) <- c("This is a looooooong title, I don't know how to handle this... Also, I'm trying to extend this title even more... This column name will be used to compute vertical space","I want to align vectically this column name")

df %>% kable(format = 'latex', linesep = "", align = 'c') %>% kable_styling(full_width = T)

enter image description here

How can align vertically the second column name?

1条回答
淡お忘
2楼-- · 2019-05-24 10:15

I am not sure if there is an easier way, but you can go with the multirow package:

---
title: "Test Book"
header-includes:
  - \usepackage{multirow}
author: "therimalaya"
output: 
  pdf_document:
    keep_tex: yes
---

# Hello World


```{r, error = TRUE, echo = T}
library(knitr)
library(kableExtra)

df <- data.frame(a = letters[1:10], b = 1:10)
names(df) <- c("This is a looooooong title, I don't know how to handle this... Also, I'm trying to extend this title even more... This column name will be used to compute vertical space","\\multirow{1}{*}[0pt]{I want to align vectically this column name}")

df %>% kable(format = 'latex', linesep = "", align = 'c', escape = F) %>% kable_styling(full_width = T)
```
查看更多
登录 后发表回答