longtable=T incompatible with full_width=T when knitting to PDF
Source file:
---
title: "Title Here"
output: pdf_document
---
## Title
```{r}
rm(list=ls(all.names = TRUE))
library(kableExtra)
kbl(mtcars, longtable=T) %>% kable_styling(full_width = T)
```
Error when knitting to PDF:
output file: test_kable2.knit.md
! Dimension too large.
\LT@max@sel #1#2->{\ifdim #2=\wd \tw@
#1\else \number \c@LT@chunks \fi }{\th...
l.208 \end{longtabu}
Error: LaTeX failed to compile test_kable2.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test_kable2.log for more info.
Execution halted
Notice that knitting to HTML file works, as well as running the code in the console works.
It looks like the intermediate LaTeX file is invalid.
I have a one cell table like the following:
my_tbl <- tibble(Title = paste(paste(lorem:::ipsum(paragraphs = 20),
collapse = " NEXT "), " *** END ***"))
Producing the pdf table with kbl(), if I do not add %>% kable_styling(full_width = T), a single line extending out of the page margin is printed.
If I specify %>% kable_styling(full_width = T) and omit longtable = T, the printout is truncated.
With:
kbl(my_tbl, longtable = T) %>% kable_styling(full_width = T)
I get your same error.
Hope someone can help!
Many thanks
This looks to me like a problem in the longtable LaTeX package, not in the code that kableExtra is producing. Do you have a suggestion to fix the LaTeX code that kableExtra should be using?
Actually I do not have any suggestion at that level.
Okay. I'll leave this issue open for now, but I don't think we can address it.
I will try to share a commented Quarto file to understand and reproduce the problem.
---
title: "Untitled"
format: pdf
editor: visual
---
```{r}
library(tidyverse)
library(kableExtra)
my_tbl <- tibble(Title = paste(paste(lorem:::ipsum(paragraphs = 20),
collapse = " NEXT "), " *** END ***"))
# kbl(my_tbl, longtable = T) %>% kable_styling(full_width = T)
# The line above produces the following error:
# ** compilation failed- error
# ** Dimension too large.
# ** \LT@max@sel #1#2->{\ifdim #2=\wd \tw@
# ** #1\else \number \c@LT@chunks \fi }{\th...
# ** l.260 \end{longtabu}
kbl(my_tbl) %>% kable_styling(full_width = T)
# The line above produces a table but, obviously,
# the printout continues beyond the page margin!
Is the problem clear?
I don't use Quarto, so I'll leave this for someone else.