Notebooks
Quarto
Slides: RevealjS
Quarto can create slides using the RevealJS framework. Unfortunately, RevealJS does not include Bootstrap, so tinytable
will not be as pretty as in other HTML documents, and the font size will often be too big.
A good workaround is to use the theme_revealjs()
function. For a one time use:
```{r}
library(tinytable)
tt(head(iris)) |> theme_revealjs() ```
To style all tables in a slide show, use a global option:
```{r}
options(tinytable_tt_theme = "revealjs")
tt(head(iris)) ```
To select a specific font size, use the fontsize
argument:
# Slide title
This is a nice table:
```{r}
library(tinytable)
options(tinytable_tt_theme = \(x) theme_tt(x, "revealjs", fontsize = .5))
tt(head(iris)) ```
Custom crossref styles
In Quarto
, it is possible to create a custom crossref type for things like appendix tables. One challenge, is that LaTeX will not allow users to nest a tblr
environment, inside a table
environment, inside the new environment that Quarto
creates for the crossref. Therefore, when rendering a table to LaTeX/PDF, it is important to drop the \begin{table}
environment. This can be done using the theme_tt()
function.
In the example below, we call theme_tt()
explicitly for a single table, but the themes vignette shows how to set a global theme using the tinytable_tt_theme
option.
---
title: "Crossref Example"
format:
pdf: default
html: default
crossref:
custom:
- kind: float
key: apptbl
latex-env: apptbl
reference-prefix: Table A
space-before-numbering: false
latex-list-of-description: Appendix Table
apptbl-cap-location: top
---
See @apptbl-testing
::: {#apptbl-testing}
```{r}
library(tinytable)
tt(mtcars[1:5,]) |> theme_tt("tabular", style = "tabularray")
```
Caption goes here.
:::
Same table, different styles
In some cases, the user wants to print a single table multiple times with different styles in a single HTML document. This will sometimes cause issues, because the style_tt()
function inserts several javascript functions to modify the same table, thus creating conflicts. A simple solution is to change the unique ID of the table object manually.
Consider this RevalJS slideshow in which we sequentially highlight different rows of the data frame:
---
format: revealjs
---
## Page 1
```{r}
library(tinytable)
tab <- tt(head(iris))
tab
```
## Page 2
```{r}
tab@id <- "table_01"
tab |> style_tt(i = 3, background = "skyblue")
```
## Page 3
```{r}
tab@id <- "table_02"
tab |> style_tt(i = 5, background = "orange") ```
Typst
See the FAQ on Typst for important notes on using Typst in Quarto documents.
Rmarkdown
papaja
papaja
is a package to assist in the preparation of APA manuscripts. Cross-references can be a bit challenging to implement when using this package with tinytable
. When the target format is PDF, one workaround is to use raw LaTeX code to make renferences and labels.
For example:
---
output :
papaja::apa6_pdf:
latex_engine: xelatex
fig_caption: yes
keep_tex: false
header-includes :
- \usepackage{tabularray}
- \usepackage{graphicx}
- \UseTblrLibrary{booktabs}
- \UseTblrLibrary{siunitx}
- \newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
- \newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
- \NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
- \usepackage{caption,fixltx2e}
- \usepackage[table]{xcolor}
---
# tidytable
Table \ref{tab:tinytableref}
```{r}
library(tinytable)
tt(head(iris), caption = "\\label{tab:tinytableref} Hello world!") |>
style_tt(color = "blue")
``` ```{r}
Bookdown
Cross-references
The bookdown
package uses a special syntax to handle cross-references, and it does not recognize tinytable
objects as tables automatically. To include cross-references to tables, it is thus necessary to use the caption
argument of tinytable::tt()
, and to insert a bookdown
label in that caption. Here is an example:
Table \@ref(tab:tinytableref)
```{r}
library(tinytable)
tt(head(iris), caption = "(#tab:tinytableref) Hello world!") |>
style_tt(color = "blue") ```