简体   繁体   中英

How to reduce line spacing with flextable() in R Markdown to pdf?

When knitting to html, flextable::line_spacing(space = 0) does what is expected, reducing the line spacing. When knitting to pdf, it does not. See code below and screenprint. I am using flextable version 0.7.3. Setting the height has a similar effect, besides some of my real data runs on more lines, so setting an exact row height is not oke. Since I have conditional formatting in my real data, flextable is easier than for instance kableExtra::column_spec(). Anyone an idea how to get the pdf produced with flextable with actual reduced line spacing? Thanks!

Screenprint_code_and_outputs

---
output:
  pdf_document:
    latex_engine: xelatex
  html_document:
    df_print: paged
---

```{r, echo = FALSE, message = FALSE}
library(tidyverse)
cars %>%
  head(10) %>%
  flextable::flextable() %>%
  flextable::line_spacing(space = 0,
                          part = "body",
                          unit = "mm")
```
 

Yes, PDF output does not support line spacing. There is a specific parameter for that, ft.arraystretch (height of each row relative to its default height - only for latex tables):

---
output:
  pdf_document:
    latex_engine: xelatex
  html_document:
    df_print: paged
---

```{r, echo = FALSE, message = FALSE, ft.arraystretch = 1}
library(tidyverse)
cars %>%
  head(10) %>%
  flextable::flextable() %>%
  flextable::line_spacing(space = 0,
                          part = "body",
                          unit = "mm")
```
 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM