FAQ

LaTeX

setspace

Some users have encountered unexpected spacing behavior when generating tables that are not wrapped in a \begin{table} environment (ex: multipage or raw tblr).

One issue stems from the fact that the \begin{table} environment resets any spacing commands in the preamble or body by default, such as:

\usepackage{setspace}
\doublespacing

This means that when using theme_tt("multipage") —which does not wrap the table in a table environment— the spacing is not reset, and tables are double spaced. This is not a bug, since double-spacing is in fact what the user requested. Nevertheless, the behavior can seem surprising for those used to the automagical table environment spacing reset.

One workaround is to add the following to the document preamble when using multipage/longtblr:

\usepackage{etoolbox}
\AtBeginEnvironment{longtblr}{\begin{singlespacing}}
\AtEndEnvironment{longtblr}{\end{singlespacing}}

Example Quarto doc:

---
title: longtblr and setspacing
format:
  pdf:
    include-in-header:
      - text: |
         % Tinytable preamble
         \usepackage{tabularray}
         \usepackage{float}
         \usepackage{graphicx}
         \usepackage{codehigh}
         \usepackage[normalem]{ulem}
         \UseTblrLibrary{booktabs}
         \UseTblrLibrary{siunitx}
         \newcommand{\tinytableTabularrayUnderline}[1]{\underline
         {#1}}
         \newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
         \NewTableCommand{\tinytableDefineColor}[3]{\definecolor{
         #1}{#2}{#3}}
         % Spacing Commands
         \usepackage{setspace}
         \doublespacing
         % Fix Spacing in longtblr
         \usepackage{etoolbox}
         \AtBeginEnvironment{longtblr}{\begin{singlespacing}}
         \AtEndEnvironment{longtblr}{\end{singlespacing}}
---

```{=latex}
\begin{longtblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]},
}                     %% tabularray inner close
\toprule
foo & bar & baz \\
foo & bar & baz \\
foo & bar & baz \\
\bottomrule
\end{longtblr}
```

Beamer

Due to a bug in the upstream package rmarkdown, Quarto or Rmarkdown presentations compiled to Beamer cannot include adequate package loading commands in the preamble automatically. This bug prevents tinytable::usepackage_latex() from modifying the preamble. Here’s a workaround.

Save this LaTeX code as preamble.tex:

\RequirePackage{tabularray}
\RequirePackage{booktabs}
\RequirePackage{float}
\usepackage[normalem]{ulem}
\usepackage{graphicx}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{siunitx}
\NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
\newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
\newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}

Then, load preamble.tex in your YAML header:

---
output: 
  beamer_presentation:
    includes:
      in_header: preamble.tex
---

With these changes, the table should appear with colors as expected.

Typst

Captions and labels

Due to a quirk in Quarto reported here, captions in Typst and Quarto documents need to be specified using both the tbl-cap and the label chunk option:

```{r}
#| tbl-cap: "blah blah blah"
#| label: tbl-blah
tinytable::tt(head(iris, 5))
```

Multi-page long tables

The Typst tables created by tinytable are automatically broken across pages with repeated headers. However, in Quarto documents, the Quarto software wraps tables in an non-breakable #figure environment. This can break the display of long tables. One solution is to use a raw Typst code block to set Figures to be breakable:

---
format: typst
---

```{=typst}
#show figure: set block(breakable: true)
```

```{r}
#| tbl-cap: "blah blah blah"
#| label: tbl-blah
library(tinytable)
tt(head(iris, 50))
```