Search code examples
rlatexrstudioquarto

Quarto html document displays undesired latex code on top


A Quarto report done in RStudio that was otherwise perfect started outputting the following text on top of the header:

\usepackage{booktabs} \usepackage{caption} \usepackage{longtable}

It seems like some Latex code is leaking, somehow. The only thing I modified was changing from html to pdf in the YAML specification (I was testing how the HTML document would look when rendered in PDF, and the answer was... awful), and adding the following Latex to try to render tables correctly (it didn't work):

\begingroup
\setlength{\LTleft}{0pt minus 500pt}
\setlength{\LTright}{0pt minus 500pt}
\fontsize{5pt}{7pt}\selectfont
\addtolength{\tabcolsep}{-3pt}

The YAML currently is as follows:

---
title: "Índice de Saturación de Destinos Turísticos"
date: today
lang: es
date-format: short
author-title: "Autoría"
published-title: "Fecha"
title-block-banner: "#846fc3"
title-block-banner-color: white
format:
  html:
    embed-resources: true
    toc: true
    toc-title: "Contenidos"
    toc-location: left
    toc-expand: 1
    toc-depth: 2
    number-sections: false
    page-layout: full
execute:
  cache: false
  echo: false
  warning: false
  error: false
---

Anybody has had this problem before?


Solution

  • Just figured it out. Adding table |> as_latex() to a {gt} table object inside knitr::knit_child (for producing Quarto chunks using purrr loops) has the side-effect of printing \usepackage{booktabs} \usepackage{caption} \usepackage{longtable} on top of your document.