Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying a Word style (table or paragraph) to flextable object

I'm trying to apply a Word style (table or paragraph) to a flextable object. My motivation is to find a way to stop a flextable from splitting across rows at a page break when outputted to a Word .docx document via knitr. For example, in the following code I've attempted to apply the "Table of Figures" paragraph style to a flextable in R markdown:

---
title: " "
output:
  word_document: default
---



<div custom-style = "Table of Figures">
```{r, echo = F, message = F}
library(flextable)
library(magrittr)

head(cars) %>%
  regulartable

```
</div>

However, this doesn't seem to work. Does anyone know how to apply table and/or paragraph styles to a flextable object?

like image 627
Owen Avatar asked Apr 13 '18 18:04

Owen


1 Answers

Sorry, that's not the way flextable are working. Formats and properties are managed by flextable functions (i.e. padding, align, etc.).

However, I modified the renderer so that rows won't be split across pages in Word document (you will need to update from Github devtools::install_github("davidgohel/flextable")).

like image 104
David Gohel Avatar answered Sep 27 '22 23:09

David Gohel