quarto-dev / quarto-dev/quarto-cli

Hyphen in LaTeX label messes up table formatting

Open
#9,833 4 comments 0 reactions 1 assignee View on GitHub

@cscheid is already working on this.

Since Jun 1, 2024.

bug latex
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Bug description

When I use a package to generat LaTeX markup for a table and embed it "asis" in a Quarto document, the table formatting is messed up as soon as I use a hyphen in the label.

Steps to reproduce

Compile the following .qmd file:

---
title: "Untitled"
format: 
  pdf:
    keep-tex: true
    include-in-header:
      - text: |
          \usepackage{threeparttable}
---

```{r}
#| results: asis
#| echo: false
library(fixest)

mod <- feols(log(Euros) ~ dist_km | Year, 
             data = trade)

etable(
  mod,
  tex = TRUE,
  label = "tbl-test"
)

```

Expected behavior

The code above produces the correct LaTeX markup that should end up verbatim in the compiled document (or rather the .tex file):

\begin{table}[htbp]
   \caption{\label{tbl-test} no title}
   \centering
   \begin{tabular}{lc}
      \tabularnewline \midrule \midrule
      Dependent Variable: & log(Euros)\\  
      Model:              & (1)\\  
      \midrule
      \emph{Variables}\\
      dist\_km            & -0.0018$^{***}$\\   
                          & ($1.02\times 10^{-5}$)\\    
      \midrule
      \emph{Fixed-effects}\\
      Year                & Yes\\  
      \midrule
      \emph{Fit statistics}\\
      Observations        & 38,325\\  
      R$^2$               & 0.16039\\  
      Within R$^2$        & 0.15963\\  
      \midrule \midrule
      \multicolumn{2}{l}{\emph{Clustered (Year) standard-errors in parentheses}}\\
      \multicolumn{2}{l}{\emph{Signif. Codes: ***: 0.01, **: 0.05, *: 0.1}}\\
   \end{tabular}
\end{table}
Actual behavior

The markup for the table is messed up in the .tex file created by Quarto/Pandoc:

\begin{table}

\caption{\label{tbl-test} no title}

\centering{

[htbp]
   
   \centering
   \begin{tabular}{lc}
      \tabularnewline \midrule \midrule
      Dependent Variable: & log(Euros)\\  
      Model:              & (1)\\  
      \midrule
      \emph{Variables}\\
      dist\_km            & -0.0018$^{***}$\\   
                          & ($1.02\times 10^{-5}$)\\    
      \midrule
      \emph{Fixed-effects}\\
      Year                & Yes\\  
      \midrule
      \emph{Fit statistics}\\
      Observations        & 38,325\\  
      R$^2$               & 0.16039\\  
      Within R$^2$        & 0.15963\\  
      \midrule \midrule
      \multicolumn{2}{l}{\emph{Clustered (Year) standard-errors in parentheses}}\\
      \multicolumn{2}{l}{\emph{Signif. Codes: ***: 0.01, **: 0.05, *: 0.1}}\\
   \end{tabular}

}

\end{table}%

In this example, [htbp] ends up showing in the PDF:

image
Your environment
  • IDE: RStudio Version 2024.04.1+748 (2024.04.1+748)
  • OS: MacOS 14.5 (23F79)
Quarto check output
Quarto 1.4.552
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.4.552
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /Library/TeX/texbin
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.2
      Path: /Users/felix/.pyenv/versions/3.12.2/bin/python3
      Jupyter: 5.7.2
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.4.0
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
      knitr: 1.46
      rmarkdown: 2.27

[✓] Checking Knitr engine render......OK

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.