tinytable uses the tabularray package from your LaTeX distribution to draw tables. tabularray, in turn, provides special tblr, talltblr, and longtblr environments to display tabular data.
When rendering a document from Quarto or Rmarkdown directly to PDF, tinytable will populate the LaTeX preamble automatically with all the required packages (except when code chunks are cached). For standalone LaTeX documents, these commands should be inserted in the preamble manually:
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_latex(environment="tabular") —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:
In some contexts, users may want create cells with LaTeX or markdown code that spans multiple lines. This usually works well for HTML tables. But sometimes, in LaTeX, multi-line content with special environments must be wrapped in a minipage environment.
In the example that follows, we create a Markdown list using asterisks. Then, we call litedown::mark() to render that list as bullet points (an itemize environment in LaTeX). Finally, we define a custom function called minipage to wrap the bullet point in an environment.
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.
With these changes, the table should appear with colors as expected.
Label and caption position
In LaTeX, we can use tabularray options in the preamble or the table to change the location of the label and caption. The example below shows a Quarto document with caption at the bottom.
The theme_latex() function includes placement control over the positioning of the table in LaTeX documents, using floating parameters like H (from the float LaTeX package) to specify where the table should appear.
The multipage theme is designed for LaTeX documents to allow long tables to continue across multiple pages. This theme ensures that tables are not truncated and that all data is presented clearly.
tmp<-rbind(mtcars, mtcars)[, 1:6]cap<-"A long 80\\% width table with repeating headers."tt(tmp, width =.8, caption =cap)|>theme_latex(multipage =TRUE, rowhead =1)