四分之一文档中空白过多空间的问题

发布于 2025-01-20 12:41:00 字数 1419 浏览 3 评论 0原文

我有一个四开本(RMarkdown)文档,它应该显示一个显示任务完成情况的表格。该代码运行良好,但显示了过多的空白,以至于表格显示在第 2 页上,其中单页就足够了,而第 1 页主要是空白。如何使表格适合一页?代码如下:

---
title: "Debug"
author: "Data Kilimba"
format: pdf
editor: visual
---

## FAAB Market Survey Task Completion


```{r setup}
#| include: false
library(tidyverse)

monthly_submissions = tibble::tribble(
  ~Year, ~Month,               ~FAAB, ~Submissions,
  2022L,     3L,      "Simon",           0L,
  2022L,     3L,  "Kabula",           0L,
  2022L,     3L,  "Innocent",           0L,
  2022L,     3L, "Renatus",           0L,
  2022L,     3L,  "Staphord",           2L,
  2022L,     3L, "Salome",           0L,
  2022L,     3L, "Imani",           0L,
  2022L,     3L,       "Petro",          10L,
  2022L,     3L,   "Mihayo",           0L,
  2022L,     3L,     "Baraka",           0L,
  2022L,     3L,     "Swaum",           0L
  )


```

```{r}
#| label: tbl-stats
#| tbl-cap: "FAAB Market Survey Task completion"
#| echo: false

monthly_submissions %>% 
  kableExtra::kable(escape = FALSE,format = "latex", booktabs = T) %>% 
  kableExtra::kable_styling(latex_options="scale_down",font_size = 2)

```

更新:: 按照卢卡斯的建议编辑文档后,我添加了 YAML 标头,但似乎存在某种语法错误...... `在此处输入图像描述

I have a Quarto (RMarkdown) document which is supposed to display a table showing task completion. The code works well but there is excessive white space displayed, to the point where the table is displayed on page 2 where a single page would have sufficed and page 1 is mostly white space. How can I make the table fit on one page? The code is as below:

---
title: "Debug"
author: "Data Kilimba"
format: pdf
editor: visual
---

## FAAB Market Survey Task Completion


```{r setup}
#| include: false
library(tidyverse)

monthly_submissions = tibble::tribble(
  ~Year, ~Month,               ~FAAB, ~Submissions,
  2022L,     3L,      "Simon",           0L,
  2022L,     3L,  "Kabula",           0L,
  2022L,     3L,  "Innocent",           0L,
  2022L,     3L, "Renatus",           0L,
  2022L,     3L,  "Staphord",           2L,
  2022L,     3L, "Salome",           0L,
  2022L,     3L, "Imani",           0L,
  2022L,     3L,       "Petro",          10L,
  2022L,     3L,   "Mihayo",           0L,
  2022L,     3L,     "Baraka",           0L,
  2022L,     3L,     "Swaum",           0L
  )


```

```{r}
#| label: tbl-stats
#| tbl-cap: "FAAB Market Survey Task completion"
#| echo: false

monthly_submissions %>% 
  kableExtra::kable(escape = FALSE,format = "latex", booktabs = T) %>% 
  kableExtra::kable_styling(latex_options="scale_down",font_size = 2)

```

UPDATE:: After editing the document as suggested by Lucas, I add the YAML header and yet there seem to be syntax errors of some kind ... `enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

染年凉城似染瑾 2025-01-27 12:41:00

导致错误的 YAML 标头不应该发生——在这种情况下,Quarto 在验证过程中对其过于挑剔。我们刚刚进行了更改,允许在此处使用 header-includes 的多个值:https://github.com/quarto-dev/quarto-cli/commit/5a685aee484f4d5914e7a899968f654584e24904

The YAML header causing an error shouldn't be occurring -- Quarto was in this case being too picky about it during validation. We've just made a change to permit use of multiple values for header-includes here: https://github.com/quarto-dev/quarto-cli/commit/5a685aee484f4d5914e7a899968f654584e24904

掀纱窥君容 2025-01-27 12:41:00

我已经达到了一个解决方案,尽管我不得不说,关于我的yaml有一些奇怪的事情。有两个问题。

  1. 这是我的yaml(这起作用)

      ------
    标题:“调试”
    作者:“数据kalimba”
    格式:PDF
    编辑:Visual
    标题包括:
       \ usepackage {float}
       \ floatPlacement {table} {h}
    ---
     

您可以看到,

header-includes:
   - \usepackage{float}
   - \floatplacement{table}{H}

...不仅是在@lucas上工作的,而且是在线上无数的其他示例(请在后斜线之前注意减去标志)。但是,对我来说,这导致了以下屏幕截图中的错误。 做了的工作正在删除减号。

但这还不够...

  1. 其次是kable_styling's lastx_option中的规范。卢卡斯建议的是

kableExtra :: kable_styling(latex_options =“ scale_down”,font_size = 2,position =“ float_left”)

,但我发现工作的是float> float_leat_let_let_left参数参数参数参数在latex_options参数列表中,因此以下修正案有效:

kableExtra::kable_styling(latex_options=c("scale_down","float_left"),font_size = 2)

因此,整个(工作)代码是:

---
title: "Debug"
author: "Data Kilimba"
format: pdf
editor: visual
header-includes:
   \usepackage{float}
   \floatplacement{table}{H}
---
  
## FAAB Market Survey Task Completion
  
  
```{r setup}
#| include: false
library(tidyverse)

monthly_submissions = tibble::tribble(
  ~Year, ~Month,               ~FAAB, ~Submissions,
  2022L,     3L,      "Simon",           0L,
  2022L,     3L,  "Kabula",           0L,
  2022L,     3L,  "Innocent",           0L,
  2022L,     3L, "Renatus",           0L,
  2022L,     3L,  "Staphord",           2L,
  2022L,     3L, "Salome",           0L,
  2022L,     3L, "Imani",           0L,
  2022L,     3L,       "Petro",          10L,
  2022L,     3L,   "Mihayo",           0L,
  2022L,     3L,     "Baraka",           0L,
  2022L,     3L,     "Swaum",           0L
)


```

```{r}
#| label: tbl-stats
#| tbl-cap: "FAAB Market Survey Task completion"
#| echo: false

monthly_submissions %>% 
  kableExtra::kable(escape = FALSE,format = "latex", booktabs = T) %>% 
  kableExtra::kable_styling(
    # Change happens in YAML and here, float_left argument is WITHIN 
    # latex_options arguments, 
    latex_options=c("scale_down","float_left"),font_size = 2)

```

I have arrived at a solution, although I have to say there are some weird goings-on with regards to my YAML. There were two issues.

  1. This is my YAML (this worked)

    ---
    title:"Debug"
    author: "Data Kalimba"
    format: pdf
    editor: visual
    header-includes:
       \usepackage{float}
       \floatplacement{table}{H}
    ---
    

As you can see...

header-includes:
   - \usepackage{float}
   - \floatplacement{table}{H}

is what shoul have worked according not only to @Lucas, but countless other examples online (notice the minus signs before the backslashes). However this for me resulted in the errors in the below screenshot. What did work was removing the minus signs.

enter image description here.

But this was not enough...

  1. Secondly was the specification within kable_styling's latex_option. What Lucas had suggested was

kableExtra::kable_styling(latex_options="scale_down",font_size = 2,position = "float_left")

However what I found to work was the float_left argument WITHIN the latex_options argument list, so the below amendment worked:

kableExtra::kable_styling(latex_options=c("scale_down","float_left"),font_size = 2)

So, the entire (working) code is:

---
title: "Debug"
author: "Data Kilimba"
format: pdf
editor: visual
header-includes:
   \usepackage{float}
   \floatplacement{table}{H}
---
  
## FAAB Market Survey Task Completion
  
  
```{r setup}
#| include: false
library(tidyverse)

monthly_submissions = tibble::tribble(
  ~Year, ~Month,               ~FAAB, ~Submissions,
  2022L,     3L,      "Simon",           0L,
  2022L,     3L,  "Kabula",           0L,
  2022L,     3L,  "Innocent",           0L,
  2022L,     3L, "Renatus",           0L,
  2022L,     3L,  "Staphord",           2L,
  2022L,     3L, "Salome",           0L,
  2022L,     3L, "Imani",           0L,
  2022L,     3L,       "Petro",          10L,
  2022L,     3L,   "Mihayo",           0L,
  2022L,     3L,     "Baraka",           0L,
  2022L,     3L,     "Swaum",           0L
)


```

```{r}
#| label: tbl-stats
#| tbl-cap: "FAAB Market Survey Task completion"
#| echo: false

monthly_submissions %>% 
  kableExtra::kable(escape = FALSE,format = "latex", booktabs = T) %>% 
  kableExtra::kable_styling(
    # Change happens in YAML and here, float_left argument is WITHIN 
    # latex_options arguments, 
    latex_options=c("scale_down","float_left"),font_size = 2)

```

一口甜 2025-01-27 12:41:00

乳胶的放置可能很棘手。一种选择是告诉 kable_stylingposition 参数:

kableExtra::kable_styling(latex_options="scale_down",font_size = 2,position = "float_left")

另外我也不确定 yaml 标头。以下对我有用:

---
title: "Debug"
author: "Data Kilimba"
output: pdf_document
header-includes:
   - \usepackage{float}
   - \floatplacement{table}{H}
---

The latex placement can be tricky. One option is to tell kable_styling the position argument:

kableExtra::kable_styling(latex_options="scale_down",font_size = 2,position = "float_left")

Also I am not sure about the yaml header. The following works for me:

---
title: "Debug"
author: "Data Kilimba"
output: pdf_document
header-includes:
   - \usepackage{float}
   - \floatplacement{table}{H}
---
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文