When trying to include a gt inside of an Rmarkdown document being knit to pdf, the knitting fails if tab_header is specified without a subtitle.
.Rmd filetitle: "tab header test"
date: "2/25/2019"
```{r}
library(tidyverse)
library(gt)
```{r}
gtcars %>%
dplyr::select(mfr, model, msrp) %>%
dplyr::slice(1:5) %>%
gt() %>%
tab_header(
title = md("Data listing from **gtcars**")
# subtitle = md("`gtcars` is an R dataset")
)
````
! LaTeX Error: There's no line here to end.
Error: Failed to compile test-tab-header.tex. See test-tab-header.log for more info.
Execution halted
If you include the subtitle, the pdf knits correctly.
Thanks for posting this issue and that skipping subtitle is the problem. I had the same issue.
A workaround for me was to set subtitle to an empty space:
tab_header(title = md("Data listing from **gtcars**"), subtitle = md(" "))
Then there is a little space between the title and the table. For me that was OK.
I found this code the LaTeX generated by gt & knitr.
The \small \\ is there even when no subtitle is defined in tab_header.
If I remove it in the LaTeX, then it compiles well.
\begin{longtable}{rrrrrrrrrrr}
\caption*{
\large MT Cars\\
\small \\
} \\
A recent fix in the development version of the package fixes this. So, closing now.
Most helpful comment
Thanks for posting this issue and that skipping
subtitleis the problem. I had the same issue.A workaround for me was to set
subtitleto an empty space:tab_header(title = md("Data listing from **gtcars**"), subtitle = md(" "))Then there is a little space between the title and the table. For me that was OK.