Skip to content

Incorrect modification of \begin{table} environment with labeled table in LaTeX #12085

@jkrumbiegel

Description

@jkrumbiegel

Bug description

SummaryTables.jl can create latex output and I noticed that tables don't look quite right when using quarto's table label feature. It seems like quarto tries to splice its own code into the \begin{table} environment but misses the [!ht] parameters, which are then left dangling, leading to this kind of output:

Image

Steps to reproduce

This doc just returns some raw latex with the correct MIME type, it should work with any similar latex output:

---
engine: julia

format:
    pdf:
        include-in-header:
            - text: |
                \usepackage{threeparttable}

keep-tex: true
---

```{julia}
#| label: tbl-test
struct Latex
    s::String
end

Base.show(io::IO, m::MIME"text/latex", l::Latex) = print(io, l.s)

Latex(raw"""
\begin{table}[!ht]
\setlength\tabcolsep{0pt}
\centering
\begin{threeparttable}
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
\toprule
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
\midrule
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
""")
```

Actual behavior

The .tex file output contains this section, notice how some code was spliced into the \begin{table} environment, leaving the [!ht] on its own line:

\begin{table}

\caption{\label{tbl-test}}

\centering{

[!ht]
\setlength\tabcolsep{0pt}
\centering
\begin{threeparttable}
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
\toprule
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
\midrule
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
\bottomrule
\end{tabular}
\end{threeparttable}

}

\end{table}%

Expected behavior

No response

Your environment

No response

Quarto check output

quarto check
Quarto 1.6.32
[✓] Checking environment information...
      Quarto cache location: /Users/krumbiegel/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.6.32
      Path: /Applications/quarto/bin

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

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/krumbiegel/Library/TinyTeX/bin/universal-darwin
      Version: 2024

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

[✓] Checking Python 3 installation....OK
      Version: 3.12.2 (Conda)
      Path: /Users/krumbiegel/miniconda3/bin/python
      Jupyter: 5.5.0
      Kernels: julia-1.11, julia-1.10, julia-1.8, julia-1.7, python3

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

[✓] Checking R installation...........OK
      Version: 4.3.2
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
      knitr: 1.45
      rmarkdown: 2.26

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcrossreflatexLaTeX engines related libraries and technologiestablesIssues with Tables including the gt integration

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions