Long gt table pdf output breaks at the end of the page

Viewed 101

I'm trying to generate a summary table which is quite long in a pdf format. But the table is breaking down at the end of the page (See the image below). I guess it is something to do with page margin.

enter image description here

I have checked the online documentation. It has argument page.margin.bottom in tab_options() to work with a RTF format. Is there any workaround for pdf format. The following example closely mimics my problem. But table is not breaking at the end. However, it is very close to the page margin.

library(gt)
library(tidyverse)
d = iris %>% gt() 
d
gtsave(d, filename = "long_table.pdf", zoom = 0.7)

Thanks.

1 Answers

I have a solution using RMarkdown that converts it into a PDF. Knit (Cntrl+Shift+K) the Rmd file in RStudio to create the pdf file in your working directory.

Normally, RMarkdown uses 3 backticks (e.g. ```{r codechunk}) to create and end a code chunk. Since stackoverflow also uses 3 backticks to create a codeblock, I will swap out the Rmd codechunk 3 backticks for *** instead.

Output screenshot: https://prnt.sc/vhO5Px59mWYQ

---
title: "test_pdf"
output: pdf_document
---

***{r setup, include=FALSE}
library(tidyverse)
library(gt)
tinytex::install_tinytex() #install this if you have not already
knitr::opts_chunk$set(echo = TRUE)
***

***{r iris2, echo=F}
dfA <- iris 
dfB <- iris
df <- bind_rows(dfA, dfB)
d <- df %>% gt()
d
 
***
Related