Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Update latex Unicode conversions to be optional (default to TRUE) as well as make them work in-line (@thebioengineer, #2037, #2041)

* Tables output to HTML and LaTeX now respect the document/browser default font sizes, only changing the size if the user sets the `table.font.size` option. (@capnrefsmmat, #1937)

# gt 1.1.0

## New features
Expand Down
2 changes: 1 addition & 1 deletion R/dt_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ dt_options_tbl <-
"table_background_color", TRUE, "table", "value", "#FFFFFF",
"table_additional_css", FALSE, "table", "values", character(0L),
"table_font_names", FALSE, "table", "values", default_fonts_vec,
"table_font_size", TRUE, "table", "px", "16px",
"table_font_size", TRUE, "table", "px", NA_character_,
"table_font_weight", TRUE, "table", "value", "normal",
"table_font_style", TRUE, "table", "value", "normal",
"table_font_color", TRUE, "table", "value", "#333333",
Expand Down
2 changes: 1 addition & 1 deletion R/render_as_i_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ render_as_ihtml <- function(data, id) {
style = list(
`font-family` = font_family_str,
#1693
fontSize = table_font_size
fontSize = if (is.na(table_font_size)) NULL else table_font_size
),
tableStyle = list(
borderTopStyle = column_labels_border_top_style,
Expand Down
5 changes: 5 additions & 0 deletions R/utils_render_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,11 @@ parse_vjust <- function(vjust) {
# setting the font relative to the 'gt_table' font size.
parse_fontsize <- function(size, base) {

# if fontsize is not set by the user, it will be NULL here; use the base fontsize
if (is.null(size)) {
return(base)
}

new_size <- rep(base[1], length(size))

# Parse percentages relative to base
Expand Down
6 changes: 6 additions & 0 deletions R/utils_render_latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,12 @@ create_fontsize_statement_l <- function(data) {

size <- dt_options_get_value(data, "table_font_size")

# if font size is left unset, use the document's font at this point instead of
# emitting a font size change
if (is.na(size)) {
return("")
}

fs_fmt <- "\\fontsize{%3.1fpt}{%3.1fpt}\\selectfont\n"
if (grepl(pattern = "^[[:digit:]]+(\\%|in|cm|emu|em|pt|px)$", size)) {
font_size <- parse_font_size_l(size)
Expand Down
4 changes: 3 additions & 1 deletion inst/css/gt_styles_default.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
margin-left: $table_margin_left; // table.margin.left
margin-right: $table_margin_right; // table.margin.right
color: font-color($table_background_color);
font-size: $table_font_size; // table.font.size
@if variable-exists("table_font_size") {
font-size: $table_font_size; // table.font.size
}
font-weight: $table_font_weight; // table.font.weight
font-style: $table_font_style; // table.font.style
background-color: $table_background_color; // table.background.color
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/_snaps/as_latex.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/cols_width.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
as_latex(gt_tbl)
Output
[1] "\\begin{table}[t]\n\\fontsize{12.0pt}{14.0pt}\\selectfont\n\\begin{tabular*}{\\linewidth}{@{\\extracolsep{\\fill}}>{\\raggedright\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}|>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}}\n\\toprule\n & & \\multicolumn{2}{>{\\centering\\arraybackslash}m{\\dimexpr 114.00pt -2\\tabcolsep-1.5\\arrayrulewidth}}{Another long spanner that needs to wrap even more than the other} & & \\\\ \n\\cmidrule(lr){3-4}\n & \\multicolumn{2}{>{\\centering\\arraybackslash}m{\\dimexpr 114.00pt -2\\tabcolsep-1.5\\arrayrulewidth}}{Spanner with a long title that should be wrapped} & & \\multicolumn{2}{>{\\centering\\arraybackslash}m{\\dimexpr 114.00pt -2\\tabcolsep-1.5\\arrayrulewidth}}{Spanner2} \\\\ \n\\cmidrule(lr){2-3} \\cmidrule(lr){5-6}\n & y & z & m & n & w \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\multicolumn{6}{>{\\raggedright\\arraybackslash}m{342pt}}{Only row group label} \\\\[2.5pt] \n\\midrule\\addlinespace[2.5pt]\na & 0.114 & 0.640 & 0.694 & 0.837 & 0.317 \\\\ \nb & 0.622 & 0.009 & 0.545 & 0.286 & 0.303 \\\\ \n\\midrule \nmean & 0.3680014 & 0.3249032 & 0.6192831 & 0.5617595 & 0.3096529 \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\multicolumn{6}{>{\\raggedright\\arraybackslash}m{342pt}}{\\rule{0pt}{0pt}} \\\\[-3.2ex] \n\\midrule\\addlinespace[2.5pt]\nc & 0.609 & 0.233 & 0.283 & 0.267 & 0.159 \\\\ \nd & 0.623 & 0.666 & 0.923 & 0.187 & 0.040 \\\\ \ne & 0.861 & 0.514 & 0.292 & 0.232 & 0.219 \\\\ \n\\bottomrule\n\\end{tabular*}\n\\end{table}\n"
[1] "\\begin{table}[t]\n\\begin{tabular*}{\\linewidth}{@{\\extracolsep{\\fill}}>{\\raggedright\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}|>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}>{\\raggedleft\\arraybackslash}p{\\dimexpr 57.00pt -2\\tabcolsep-1.5\\arrayrulewidth}}\n\\toprule\n & & \\multicolumn{2}{>{\\centering\\arraybackslash}m{\\dimexpr 114.00pt -2\\tabcolsep-1.5\\arrayrulewidth}}{Another long spanner that needs to wrap even more than the other} & & \\\\ \n\\cmidrule(lr){3-4}\n & \\multicolumn{2}{>{\\centering\\arraybackslash}m{\\dimexpr 114.00pt -2\\tabcolsep-1.5\\arrayrulewidth}}{Spanner with a long title that should be wrapped} & & \\multicolumn{2}{>{\\centering\\arraybackslash}m{\\dimexpr 114.00pt -2\\tabcolsep-1.5\\arrayrulewidth}}{Spanner2} \\\\ \n\\cmidrule(lr){2-3} \\cmidrule(lr){5-6}\n & y & z & m & n & w \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\multicolumn{6}{>{\\raggedright\\arraybackslash}m{342pt}}{Only row group label} \\\\[2.5pt] \n\\midrule\\addlinespace[2.5pt]\na & 0.114 & 0.640 & 0.694 & 0.837 & 0.317 \\\\ \nb & 0.622 & 0.009 & 0.545 & 0.286 & 0.303 \\\\ \n\\midrule \nmean & 0.3680014 & 0.3249032 & 0.6192831 & 0.5617595 & 0.3096529 \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\multicolumn{6}{>{\\raggedright\\arraybackslash}m{342pt}}{\\rule{0pt}{0pt}} \\\\[-3.2ex] \n\\midrule\\addlinespace[2.5pt]\nc & 0.609 & 0.233 & 0.283 & 0.267 & 0.159 \\\\ \nd & 0.623 & 0.666 & 0.923 & 0.187 & 0.040 \\\\ \ne & 0.861 & 0.514 & 0.292 & 0.232 & 0.219 \\\\ \n\\bottomrule\n\\end{tabular*}\n\\end{table}\n"
attr(,"class")
[1] "knit_asis"
attr(,"knit_meta")
Expand Down
Loading