Flextable's automatic row height adjustment (hrule) not working for PDF output
16:23 29 Apr 2020

I'm trying to display several tables where the column widths are the same but the row heights vary with the amount of data in the cells in a PDF document generated from an .Rmd file. Despite explicitly setting the column widths and font sizes, and using hrule(rule="auto", part="all") to let the row heights vary, the output changes the widths and font sizes to keep the row heights the same.

Contents of the .Rmd:

---
output: pdf_document
---

```{r, echo=FALSE, collapse=TRUE, include=FALSE}
# Load libraries
#webshot::install_phantomjs() # needed for flextable. Don't need to load it as a package.
library(dplyr) # data management
library(flextable) # produce tables
library(OpenRepGrid) # generate random words

# Build data
table1Df <- data_frame(item = paste0(1:5, "."),
                       labels = c(randomSentence(10),
                                  randomSentence(10),
                                  randomSentence(10),
                                  randomSentence(10),
                                  randomSentence(10)
                                  ),
                       score = 11:15
                       )

table2Df <- data_frame(item = paste0(1:5, "."),
                       labels = c(randomSentence(15),
                                  randomSentence(15),
                                  randomSentence(15),
                                  randomSentence(15),
                                  randomSentence(15)
                                  ),
                       score = 16:20
                       )

# Function to build flextable
flexPrintFun <- function(df){
  flextable(df) %>%
    width(j=1, width=0.25) %>%
    width(j=2, width=3) %>%
    width(j=3, width=0.5) %>%
    hrule(rule="auto", part="all") %>%
    fontsize(part="header", size=20) %>%
    fontsize(part="body", size=15) 
}
```

```{r, echo=FALSE}
flexPrintFun(table1Df)
flexPrintFun(table2Df)
```

Here's what it ends up looking like (after zooming in quite a bit because the columns get crushed way down):

enter image description here

The final document will have the tables stacked on top of each other, so it's important that the column widths line up, font sizes are consistent, etc.

I've looked into the documentation about hrule here: https://davidgohel.github.io/flextable/reference/hrule.html and while it states that it works in Word and HTML but not PowerPoint outputs, it says nothing about PDF.

I've looked into kable and kableExtra but those don't quite do everything I need with some other features I don't discuss here.

r pdf r-markdown r-flextable