Skip to content

Commit

Permalink
theme_spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Nov 4, 2024
1 parent 9e630f7 commit 46cbed7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: tinytable
Type: Package
Title: Simple and Configurable Tables in 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', and 'Typst' Formats
Description: Create highly customized tables with this simple and dependency-free package. Data frames can be converted to 'HTML', 'LaTeX', 'Markdown', 'Word', 'PNG', 'PDF', or 'Typst' tables. The user interface is minimalist and easy to learn. The syntax is concise. 'HTML' tables can be customized using the flexible 'Bootstrap' framework, and 'LaTeX' code with the 'tabularray' package.
Version: 0.5.0.4
Version: 0.5.0.5
Imports:
methods
Depends:
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

Misc:

* `theme_tt("spacing")`: Change the row and column spacing to create more compact or airy tables. LaTeX and HTML only. Thanks to @statzhero for feature request #353.
* Major refactor of the style internals. HTML, LaTeX, and Typst documents should be much more concise and efficient.
* `style_tt()`: the `i` and `j` indices are now consistent in all formats. They refer to rows *after* the insertion of row groups.
* `save_tt()` respects `options(tinytable_save_overwrite=TRUE)`
Expand Down
40 changes: 40 additions & 0 deletions R/theme_spacing.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
theme_spacing <- function(x,
rowsep = get_option("tinytable_theme_spacing_rowsep", 0.1),
colsep = get_option("tinytable_theme_spacing_colsep", 0.5),
...) {

# placement
fn <- theme_placement_factory(
horizontal = get_option("tinytable_theme_default_horizontal", "c"),
latex_float = get_option("tinytable_theme_placement_latex_float", default = NULL))
x <- style_tt(x, finalize = fn)

# rules
if (isTRUE(x@output %in% c("html", "typst"))) {
bc <- if (length(x@bootstrap_class) == 0) "table table-borderless" else x@bootstrap_class
x <- style_tt(x,
bootstrap_class = bc,
i = nrow(x) + x@ngroupi,
line = "b",
line_color = "#d3d8dc",
line_width = 0.1)
x <- style_tt(x,
bootstrap_class = bc,
i = 0,
line = "bt",
line_color = "#d3d8dc",
line_width = 0.1)
}

# spacing
x <- style_tt(x,
tabularray_inner = sprintf("rowsep={%sem}, colsep = {%sem}", rowsep, colsep))
x <- style_tt(x,
tabularray_inner = sprintf("rowsep={%sem}, colsep = {%sem}", rowsep, colsep))
x <- style_tt(x, j = seq_len(ncol(x) - 1),
bootstrap_css = sprintf("padding-right: %sem;", colsep))
x <- style_tt(x, i = -5:(nrow(x) - 1),
bootstrap_css = sprintf("padding-bottom: %sem;", rowsep))

return(x)
}
9 changes: 5 additions & 4 deletions R/theme_zzz.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
theme_dictionary <- list(
"default" = theme_default,
"bootstrap" = theme_bootstrap,
"grid" = theme_grid,
"resize" = theme_resize,
"multipage" = theme_multipage,
"placement" = theme_placement,
"resize" = theme_resize,
"rotate" = theme_rotate,
"spacing" = theme_spacing,
"striped" = theme_striped,
"void" = theme_void,
"bootstrap" = theme_bootstrap,
"tabular" = theme_tabular
"tabular" = theme_tabular,
"void" = theme_void
)


Expand Down

0 comments on commit 46cbed7

Please sign in to comment.