8

I've been having great luck with customizing flextable tables in my R Markdown documents. However, I am struggling to change the location of a table on the page. It seems the tables are centered on the page by default. I'd like one of my tables aligned to the left margin. How do I do that?

JD Long
  • 59,675
  • 58
  • 202
  • 294
  • I know nothing of this, but `body_add_flextable()` has an `align=` argument. Does that work? – thelatemail Sep 17 '18 at 22:00
  • Unfortunately, no. `body_add_flextable` is not designed to be used inside an R Markdown document (as far as I can tell). – JD Long Sep 18 '18 at 10:21
  • 1
    @JDLong I have just added that functionality (in the github repo), add `ft.align="left"` in the chunk option part and voilà! – David Gohel Sep 18 '18 at 14:46
  • brilliant @DavidGohel! would you mind making that an answer so I can accept it? – JD Long Sep 18 '18 at 15:28
  • @DavidGohel Is it possible to also add a similar functionality in `save_as_docx`? I usually have a list of flextables and want to save them directly in a .docx file. The resulting docx file has all tables centered – Lefkios Paikousis Feb 23 '20 at 15:59

2 Answers2

22

I have just added an option to enable that. Now you can use chunk option ft.align

---
output: word_document
---

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


```{r ft.align="left"}
library(flextable)
regulartable(cars)
```
David Gohel
  • 9,180
  • 2
  • 16
  • 34
0

I ran into the same problem and the solution worked just fine after updating "flextable" from 0.5.4 and 0.5.5 to get this to work.