1

Here is a simple qmd file.

---
title: "Untitled"
format: pdf
---

```{r, echo=FALSE}
library(gt)
exibble |>
  gt() |>
  tab_header(title = "title")
```

My output looks like this. Notice how the "title" text is repeated in brackets: [title]title and how the title appears to the left of the table.

Why is this happening? I am running:

  • R 4.5.0
  • gt 1.1.0.9000
  • quarto 1.8.26
  • quarto rendered the PDF using LuaHBTeX, Version 1.22.0 (TeX Live 2025)

screenshot of gt pdf quarto output

2
  • 1
    Please show the intermediate .tex file Commented Nov 14 at 19:38
  • 3
    Related open issue on Github. Commented Nov 14 at 19:44

1 Answer 1

3

I can reproduce it. The culprit seems to be * in \caption*. The tex given by

cat(exibble |>
   gt() |>
   tab_header(title = "Title") |>
   as_latex())

is

\begin{table}[t]
\caption*{
{\fontsize{20}{25}\selectfont  Title\fontsize{12}{15}\selectfont }
} 
\fontsize{12.0pt}{14.0pt}\selectfont
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}rlcrrrrll}
\toprule
num & char & fctr & date & time & datetime & currency & row & group \\ 
\midrule\addlinespace[2.5pt]
1.111e-01 & apricot & one & 2015-01-15 & 13:35 & 2018-01-01 02:22 & 49.950 & row\_1 & grp\_a \\ 
2.222e+00 & banana & two & 2015-02-15 & 14:40 & 2018-02-02 14:33 & 17.950 & row\_2 & grp\_a \\ 
3.333e+01 & coconut & three & 2015-03-15 & 15:45 & 2018-03-03 03:44 & 1.390 & row\_3 & grp\_a \\ 
4.444e+02 & durian & four & 2015-04-15 & 16:50 & 2018-04-04 15:55 & 65100.000 & row\_4 & grp\_a \\ 
5.550e+03 & NA & five & 2015-05-15 & 17:55 & 2018-05-05 04:00 & 1325.810 & row\_5 & grp\_b \\ 
NA & fig & six & 2015-06-15 & NA & 2018-06-06 16:11 & 13.255 & row\_6 & grp\_b \\ 
7.770e+05 & grapefruit & seven & NA & 19:10 & 2018-07-07 05:22 & NA & row\_7 & grp\_b \\ 
8.880e+06 & honeydew & eight & 2015-08-15 & 20:20 & NA & 0.440 & row\_8 & grp\_b \\ 
\bottomrule
\end{tabular*}
\end{table}

If you remove this star, the title appears where it should, see this test with Overfleaf. Although the prexif "Table x: " is present, which \caption* would have prevented. res

Also the table does overflow for the font-size, so you might want to reduce it or select fewer columns.

Fix 1 - use \caption instead of \caption*

---
title: "Untitled"
format: pdf
---

```{r, echo=FALSE, results='asis'}
library(gt)
cat(exibble |>
  gt() |>
  tab_header(title = "Title") |>
  tab_options(
    table.font.size = px(8)
  ) |>
  as_latex() |>
  gsub("caption\\**", "caption", x = _))
```

gives

res


Fix 2 - use \subcaption* instead of \caption*

I believed the issue was with the LaTeX package caption, which is needed to customize the table caption. If you specify keep-tex: true and use the resulting TEX in overleaf, it works just fine. Inspecting the log file of overleaf, it says:

Package caption Info: KOMA-Script document class detected. (/usr/local/texlive/2025/texmf-dist/tex/latex/caption/caption-koma.sto File: caption-koma.sto 2023/09/08 v2.0e Adaption of the caption package...

whereas lualatex, xelatex and my miktex give

Package caption Info: Unknown document class (or package), (caption) standard defaults will be used.

Unknown document class

While following this Package caption Warning: Unsupported document class-trace, I stumbled upon this post and this and another post led me to trying subcaption* instead of caption*. And this seems to work. It also does with xelatex and latexmk engines.

---
title: "Untitled"
pdf-engine: lualatex
format: 
  pdf:
    keep-tex: true
---

```{r, echo=FALSE, results='asis', warning=FALSE}
library(gt)
cat(exibble |>
  gt() |>
  tab_header(title = "Title") |>
  tab_options(
    table.font.size = px(8)
  ) |>
  as_latex()|> 
  gsub("caption\\**", "subcaption*", x = _)
)
```

gives

res

Explanation perhaps

I read in this post:

If you get such a compatibility warning but decide to use the caption package anyway, you should watch carefully what side-effects occur, usually the look and feel of your captions will change by just including the caption package without options, meaning they do not look like as intended by the author of the document class.

So I believe the document class of the resulting gt-tex is not supported.
What supports my suspicion further: If I use a supported document class like \documentclass{report} \caption* works just fine:

document class report works


keep .tex file

If you want to run your own tests, here is the faulty tex-file.

% Options for packages loaded elsewhere
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
%
\documentclass[
  letterpaper,
  DIV=11,
  numbers=noendperiod]{scrartcl}
\usepackage{xcolor}
\usepackage{amsmath,amssymb}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\usepackage{iftex}
\ifPDFTeX
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math} % this also loads fontspec
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
\usepackage{lmodern}
\ifPDFTeX\else
  % xetex/luatex font selection
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
% Make \paragraph and \subparagraph free-standing
\makeatletter
\ifx\paragraph\undefined\else
  \let\oldparagraph\paragraph
  \renewcommand{\paragraph}{
    \@ifstar
      \xxxParagraphStar
      \xxxParagraphNoStar
  }
  \newcommand{\xxxParagraphStar}[1]{\oldparagraph*{#1}\mbox{}}
  \newcommand{\xxxParagraphNoStar}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
  \let\oldsubparagraph\subparagraph
  \renewcommand{\subparagraph}{
    \@ifstar
      \xxxSubParagraphStar
      \xxxSubParagraphNoStar
  }
  \newcommand{\xxxSubParagraphStar}[1]{\oldsubparagraph*{#1}\mbox{}}
  \newcommand{\xxxSubParagraphNoStar}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\makeatother


\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\usepackage{graphicx}
\makeatletter
\newsavebox\pandoc@box
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
  \sbox\pandoc@box{#1}%
  \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
  \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
  \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
  \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
  \else\usebox{\pandoc@box}%
  \fi%
}
% Set default figure placement to htbp
\def\fps@figure{htbp}
\makeatother





\setlength{\emergencystretch}{3em} % prevent overfull lines

\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}



 


\KOMAoption{captions}{tableheading}
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\AtBeginDocument{%
\ifdefined\contentsname
  \renewcommand*\contentsname{Table of contents}
\else
  \newcommand\contentsname{Table of contents}
\fi
\ifdefined\listfigurename
  \renewcommand*\listfigurename{List of Figures}
\else
  \newcommand\listfigurename{List of Figures}
\fi
\ifdefined\listtablename
  \renewcommand*\listtablename{List of Tables}
\else
  \newcommand\listtablename{List of Tables}
\fi
\ifdefined\figurename
  \renewcommand*\figurename{Figure}
\else
  \newcommand\figurename{Figure}
\fi
\ifdefined\tablename
  \renewcommand*\tablename{Table}
\else
  \newcommand\tablename{Table}
\fi
}
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{Listing}
\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}
\makeatother
\makeatletter
\makeatother
\makeatletter
\@ifpackageloaded{caption}{}{\usepackage{caption}}
\@ifpackageloaded{subcaption}{}{\usepackage{subcaption}}
\makeatother
\usepackage{bookmark}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same}
\hypersetup{
  pdftitle={Untitled},
  colorlinks=true,
  linkcolor={blue},
  filecolor={Maroon},
  citecolor={Blue},
  urlcolor={Blue},
  pdfcreator={LaTeX via pandoc}}


\title{Untitled}
\author{}
\date{}
\begin{document}
\maketitle


\begin{table}
\caption*{    % ISSUE IS HERE
{\fontsize{20}{25}\selectfont  Title\fontsize{6}{8}\selectfont }
} 
\fontsize{6.0pt}{7.0pt}\selectfont
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}rlcrrrrll}
\toprule
num & char & fctr & date & time & datetime & currency & row & group \\ 
\midrule\addlinespace[2.5pt]
1.111e-01 & apricot & one & 2015-01-15 & 13:35 & 2018-01-01 02:22 & 49.950 & row\_1 & grp\_a \\ 
2.222e+00 & banana & two & 2015-02-15 & 14:40 & 2018-02-02 14:33 & 17.950 & row\_2 & grp\_a \\ 
3.333e+01 & coconut & three & 2015-03-15 & 15:45 & 2018-03-03 03:44 & 1.390 & row\_3 & grp\_a \\ 
4.444e+02 & durian & four & 2015-04-15 & 16:50 & 2018-04-04 15:55 & 65100.000 & row\_4 & grp\_a \\ 
5.550e+03 & NA & five & 2015-05-15 & 17:55 & 2018-05-05 04:00 & 1325.810 & row\_5 & grp\_b \\ 
NA & fig & six & 2015-06-15 & NA & 2018-06-06 16:11 & 13.255 & row\_6 & grp\_b \\ 
7.770e+05 & grapefruit & seven & NA & 19:10 & 2018-07-07 05:22 & NA & row\_7 & grp\_b \\ 
8.880e+06 & honeydew & eight & 2015-08-15 & 20:20 & NA & 0.440 & row\_8 & grp\_b \\ 
\bottomrule
\end{tabular*}
\end{table}



\end{document}
  • R 4.5.1 (2025-06-13 ucrt)
  • gt_1.1.0
  • quarto 1.7.32
Sign up to request clarification or add additional context in comments.

1 Comment

Great response. Adding documentclass: report to the yaml header works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.