Skip to content

Commit

Permalink
theme_revealjs()
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Nov 5, 2024
1 parent 099e835 commit 14db172
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
45 changes: 45 additions & 0 deletions R/theme_revealjs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
theme_revealjs <- function(x,
fontsize = get_option("tinytable_theme_revealjs_fontsize", default = 0.8),
fontsize_caption = get_option("tinytable_theme_revealjs_fontsize_caption", default = 1)) {

css <- "
// tables
.reveal table {
// height: auto; /* Adjust table width to fit content up to the available slide space */
margin: auto;
border-collapse: collapse;
border-spacing: 0;
}
.reveal table th,
.reveal table td {
border: none;
padding: .23em;
font-weight: lighter;
font-size: %sem;
}
/* Adds a bottom border to the table header row for distinction */
.reveal table thead th,
.reveal .slides table tr:last-child td,
.reveal .slides table {
border-bottom: 2px solid #D3D3D3;
}
/* Make column headers bold */
.reveal table thead th {
/* font-weight: bold; */
}
/* Styling table captions */
.reveal table caption {
color: #666666; /* Dark grey color for the caption */
font-size: %emem;
}
"
css <- sprintf(css, fontsize, fontsize_caption)
x <- style_tt(x, bootstrap_css_rule = css)
return(x)
}

1 change: 1 addition & 0 deletions R/theme_zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ theme_dictionary <- list(
"grid" = theme_grid,
"multipage" = theme_multipage,
"placement" = theme_placement,
"revealjs" = theme_revealjs,
"resize" = theme_resize,
"rotate" = theme_rotate,
"spacing" = theme_spacing,
Expand Down
2 changes: 1 addition & 1 deletion man/initialize-tinytable-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/tt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions vignettes/notebooks.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,42 @@

## Quarto

### Slides: RevealjS

Quarto can create slides using [the RevealJS framework](https://revealjs.com/). 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:

````{verbatim}
```{r}
library(tinytable)
tt(head(iris)) |> theme_revealjs()
```
````

To style all tables in a slide show, use a global option:

````{verbatim}
```{r}
options(tinytable_tt_theme = "revealjs")
tt(head(iris))
```
````

To select a specific font size, use the `fontsize` argument:

````{verbatim}
# 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.
Expand Down

0 comments on commit 14db172

Please sign in to comment.