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?
Asked
Active
Viewed 4,862 times
8

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 Answers
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
-
1This solution doesn't seem to work for html output. Is there a way to align flextables on the left site in html? – jhvdz May 19 '19 at 15:42
-
2no, it does apply to word but i can extend that to html, no problem – David Gohel May 20 '19 at 14:04
-
-
3@jhvdz this is now implemented with html output, you need to update the package from github to try it (it will go on cran later) – David Gohel May 22 '19 at 15:42
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.

Lionel Duarte
- 121
- 6