Closed alan-y closed 4 years ago
No, the function to do that is autofit()
but it has never been called systematically.
You can read more about flextable here: https://davidgohel.github.io/flextable/
and the function autofit
is documented here: https://davidgohel.github.io/flextable/reference/autofit.html
I have tried autofit()
but the height always seems to stay the same and it only adjusts the width
This is what I get with the code adapted from your repex:
library(tidyverse)
library(flextable)
z_df <- iris %>%
as_tibble() %>%
rename(Sepal.Length.lets.make.this.very.long = Sepal.Length)
flextable(z_df) %>%
width(j = 1, width = 1) %>%
height(height = 3, part = "header") %>%
print(preview = "docx")
flextable(z_df) %>%
autofit() %>%
print(preview = "docx")
Don't you have the same results??
Yeah I get the same results. Sorry I think the confusion is that I want to keep the width as 1 but stretch the height to fit the text, keeping the width fixed This is because sometimes autofit will make the width stretch beyond the dimensions of the page
p.s. in a previous version of flextable, if I set the width to be 1, the height would automatically adjust to fit the text without running autofit()
or having to manually adjust with height()
- this is what I mean.
Ah ok. This has never been a functionality I think :) There is no implemented option for the functionality you are after, sorry
hmm maybe it used to do this but was unintended? I know it used to do this because I'm writing up a paper and just had to write code to adjust the heights after updating the package... I'll try to generate some screenshots along with a reprex (maybe in the next couple of days).
Anyway if it was never intended to adjust the heights, then that's ok but just interesting!
So sorry!
I just went through some of the recent changes and yes, there has been a change. It's related to #151. I will implement an option to allow the choice....
No problem - thanks for looking into this 👍
Hi all,
Same "feature" here after updating the package, I need to manually adjust the height of each table... I am not sure to clearly undestand #151 , but an option would be great!
Best, David
I too would request that this be Fixed. Going through the thread, I realize that the functionality that row heights would automatically adjust to fit content was accidental, but it was crucial to some scenarios, especially those that I encounter.
I would also request if you could suggest a quick workaround till this is fixed.
Thanks so much for your wonderful work. Regards
Hi all,
I'm having the same issue - a solution and/or workaround would be much appreciated 👍
Thanks, Alice
+1
I have created a new function named hrule
to let users select rule to apply to row height.
Argument rule
specifies the meaning of the height. Possible values are "atleast" (height should be at least the value specified), "exact" (height should be exactly the value specified), or the default value "auto" (height is determined based on the height of the contents, so the value is ignored).
The following code will produce the following outputs :
library(officer)
library(tidyverse)
library(flextable)
z_df <- iris %>%
as_tibble() %>%
rename(Sepal.Length.lets.make.this.very.long = Sepal.Length)
z <- flextable(z_df) %>%
autofit() %>%
width(j = 1, width = 1) %>%
height(i = 1, height = 0.5, part = "header") %>%
hrule(rule = "auto", part = "all") # this is the default option so that command is not really useful
print(z, preview = "html")
print(z, preview = "docx")
print(z, preview = "pptx")
If using hrule(rule = "exact", part = "all")
you would get:
Setting rule to exact
will have no effect on pptx output. On html output, text overflow is hidden but in word text overflow let break words.
fantastic, sounds great, thanks David!
Great!! Thanks so much David!!
Brilliant - thanks so much 👍
Thanks all, I am closing the issue then!
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.
flextable used to automatically adjust the height of cells in tables outputted to MS Word to accomodate the amount of text but does not seem to anymore.
Now need to explicitly adjust the height with e.g.
Here is my session info for completeness. I am also using MS Word 2007 in case that may be an issue.