简体   繁体   English

如何在 R Markdown 到 pdf 中使用 flextable() 减少行间距?

[英]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.当编织到 html 时, flextable::line_spacing(space = 0) 符合预期,减少了行距。 When knitting to pdf, it does not.编织到 pdf 时,它不会。 See code below and screenprint.请参阅下面的代码和丝网印刷。 I am using flextable version 0.7.3.我正在使用 flextable 版本 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().因为我在我的真实数据中有条件格式,所以 flextable 比 kableExtra::column_spec() 更容易。 Anyone an idea how to get the pdf produced with flextable with actual reduced line spacing?任何人都知道如何获得 pdf 生产的 flextable 实际减少的行距? 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.是的,PDF output 不支持行间距。 There is a specific parameter for that, ft.arraystretch (height of each row relative to its default height - only for latex tables):有一个特定的参数, ft.arraystretch (每行的高度相对于其默认高度 - 仅适用于 Z25F7E525B5C0641E1EB1FB3BDEBEB15B5Z 表):

---
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")
```
 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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