morgan121
morgan121

Reputation: 2253

Align cells vertically to be at the bottom flextable

When I print a flextable to a word document the cell alignment vertically is defaulted to centered, but I'm wondering if there's a way to make the text sit at the bottom of the cell.

I am aware of the flextable::align() function, but it only applies to horizontal alignment. Does anyone know a way of changing the default vertical alignment?

Sample code:

 read_docx() %>% 
   body_add_flextable(value = iris %>% regulartable()) %>%
   print("Test.docx")

Upvotes: 1

Views: 423

Answers (1)

David Gohel
David Gohel

Reputation: 10695

You need to use function style, there is no shortcut for that property.

library(flextable)
library(magrittr)
library(officer)

ft <- iris %>% 
  regulartable() %>% 
  style(pr_c = fp_cell(vertical.align = "bottom")) %>% 
  theme_booktabs() %>% # as style will replace all existing style...
  height_all(height = .5) # make height bigger to see the bottom alignt.

read_docx() %>% 
  body_add_flextable(value = ft ) %>%
  print("Test.docx") 

Upvotes: 2

Related Questions