Gt: knit to pdf fails when tab_header is specified without a subtitle

Created on 25 Feb 2019  路  3Comments  路  Source: rstudio/gt

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 file

````

title: "tab header test"
date: "2/25/2019"

output: pdf_document

```{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")
  )

````

Error

! 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.

[2] Intermediate [2] Medium [3] High 鈽癸笌 Bug

Most helpful comment

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rich-iannone picture rich-iannone  路  5Comments

jenniferp96 picture jenniferp96  路  4Comments

r2evans picture r2evans  路  5Comments

TuSKan picture TuSKan  路  6Comments

Torvaney picture Torvaney  路  3Comments