Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical Align in Cell for Latex #425

Closed
matton2 opened this issue Sep 13, 2019 · 2 comments
Closed

Vertical Align in Cell for Latex #425

matton2 opened this issue Sep 13, 2019 · 2 comments

Comments

@matton2
Copy link

matton2 commented Sep 13, 2019

Hello and thank you for this package!!

I would like to vertically align my text in the cell without using collapse_row since it is just a single cell.

The code below creates a table where the first column is top vertical aligned; it would be great if I could choose to have it vertical aligned 'middle'.

image

Thank for any help you can provide,
matt

---
title: "Untitled"
author: "M. Onimus"
date: "9/13/2019"
output: pdf_document
---

```{r setup, include=FALSE}
library(kableExtra)
knitr::opts_chunk$set(echo = TRUE)
```

```{r, include=FALSE}
testDataFrame <- data.frame(col1 = c('something', 'something'), col2 = c('something that is much longer and i would like the first col to be veritcal aligned, this probably needs to be even longer to get my point across', 'something that is much longer and i would like the first col to be veritcal aligned'), stringsAsFactors = FALSE)
```

```{r}

kable(
  testDataFrame,
  format = 'latex',
  longtable = T,
  align = 'c'
) %>% 
  kable_styling(latex_options = c("repeat_header"), repeat_header_text = "Previous Table Continued", font_size = 9) %>% 
  column_spec(1, width = "8em", ) %>% 
  column_spec(c(-1), paste0(45/round(NCOL(testDataFrame),1),"em")) %>% 
  row_spec(0, bold = TRUE) 

```

@haozhu233
Copy link
Owner

@matton2 Just added a new option latex_valign for column_spec. However I don't fully understand how it works. It seems that the only way to middle align the first column is to specify "m" at the second column. 🧐

If anyone can find out a fix, that would be great!

kable(
  testDataFrame,
  format = 'latex',
  longtable = T,
  align = 'c') %>% 
  kable_styling(latex_options = c("repeat_header"), repeat_header_text = "Previous Table Continued", font_size = 9) %>% 
  column_spec(1, width = "8em", bold = T) %>% 
  column_spec(2, "10em", latex_valign = "m") %>% 
  row_spec(0, bold = TRUE) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants