alignment of a flextable on the page when rendering R Markdown to MS Word
Asked Answered
O

2

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?

Occam answered 17/9, 2018 at 21:51 Comment(5)
I know nothing of this, but body_add_flextable() has an align= argument. Does that work?Ulane
Unfortunately, no. body_add_flextable is not designed to be used inside an R Markdown document (as far as I can tell).Occam
@JDLong I have just added that functionality (in the github repo), add ft.align="left" in the chunk option part and voilà!Reflect
brilliant @DavidGohel! would you mind making that an answer so I can accept it?Occam
@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 centeredSandalwood
R
23

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)
```
Reflect answered 18/9, 2018 at 15:50 Comment(4)
This solution doesn't seem to work for html output. Is there a way to align flextables on the left site in html?Foulard
no, it does apply to word but i can extend that to html, no problemReflect
I would very much appreciate that, thanks in advance.Foulard
@Foulard this is now implemented with html output, you need to update the package from github to try it (it will go on cran later)Reflect
I
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.

Interrupter answered 14/8, 2019 at 21:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.