'Problems with excessive white space in Quarto document

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



Solution 1:[1]

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)

```

Solution 2:[2]

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}
---

Solution 3:[3]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 karel
Solution 2
Solution 3 jjallaire