I have an issue that just 'popped up' yesterday in knitting rmarkdown files with tables using kable and longtable.
The issue in question is when I set 'longtable=TRUE' in the kable function with a "label: tbl-foo". Note that the label is 'label: tbl-x'. Compiling this gives an error (via tlmgr):
Rendering PDF
running xelatex - 1
This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode
updating tlmgr
updating existing packages
ERROR:
compilation failed- error
Missing } inserted.
<inserted text>
}
l.291 \end{longtable}
If I change longtable to FALSE in the kable(...) call, the code compiles but the bottom of the table is cutoff rather than going to the next page. If I change the label to "label: tab-x", everything is fine. What's also interesting is that this behavior started after a successful compile with no changes to labels in the quarto code. This behavior is also there with straight R markdown. Is this expected behavior (I ask because the examples in the Quarto.org guide has table chunk labels that are "label: tbl-foo") without any caveats I could find. Here's my MWEx.:
MWEx:
---
title: Intro
format:
pdf: default
include-in-header:
text:
\usepackage{booktabs}
\usepackage{longtable}
---
```{r}
#| echo: false
#| include: true
#| message: false
#| label: tbl-x
#| tbl-cap: "My table w/ math"
require(knitr)
require(kableExtra)
fmt <- 'latex'
knitr::opts_knit$set(kable.force.latex = TRUE)
# prepare a long table
tab.df <- data.frame('Term' = 1:100,'Description' = rep('Desc',100),
'Units'= rep('mg/L',100),'Chapter' = paste0('Ch ',1:100))
tab.df %>% kable(format=fmt,escape=F, booktabs=T, align='clcl', longtable=T) %>%
kable_styling(font_size=10) %>%
column_spec(c(1,4),width='.5in') %>%
column_spec(2,width='2.75in') %>%
column_spec(3,width='0.75in')