rr-markdownquarto

How to Adjust Font Sizes in Imported Table in a PDF Document Compiled from Quarto?


I'm using Quarto to generate a PDF document, and I want to adjust the font sizes, specifically in a table imported from an external file.

Here is a minimal reproducible example of what I need. The output should provide a way to define the font size of the table imported from tab.md

---
title: "My Document"
format: pdf
---

## Intro

I want to insert a table created with this code:

```{r}
#| message: false
library(modelsummary)
datasummary(hp + mpg ~ Factor(cyl) * mean, data = mtcars, output = "tab.md")
```

## Table

::: {#tbl-tab}

{{< include tab.md >}}

My Table
:::

How can I adjust the font sizes for Table 1 in my Quarto PDF document?


Solution

  • Use \AddToHookNext LaTeX statement like:

    ---
    title: "My Document"
    format: pdf
    ---
    
    ## Intro
    
    I want to insert a table created with this code:
    
    ```{r}
    #| message: false
    library(modelsummary)
    datasummary(hp + mpg ~ Factor(cyl) * mean, data = mtcars, output = "tab.md")
    ```
    \AddToHookNext{env/longtable/begin}{\Large}
    
    ## Table
    
    ::: {#tbl-tab}
    
    {{< include tab.md >}}
    
    My Table
    :::
    
    followed by next table:
    
    ## Table
    
    ::: {#tbl-tab}
    
    {{< include tab.md >}}
    
    My next Table in default font size.
    :::
    

    which produces:

    enter image description here

    More about hooks: https://ctan.math.illinois.edu/macros/latex/base/lthooks-doc.pdf. Or have a look on kable/kableExtra packages https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_pdf.pdf