Skip to content

Commit

Permalink
Use "t" as default float position instead of "!t"
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Feb 20, 2025
1 parent 355ba08 commit fb5379b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# gt (development version)

* The default table position in LaTeX is now "t" instead of "!t" (@AaronGullickson, #1935).

* Fixed an issue where cross-references would fail in bookdown::html_document2 (@olivroy, #1948)

* Significantly faster rendering of certain large tables, by optimizing the internal `rownum_translation()` utility. (@magnusdv, #1924)
Expand Down
2 changes: 1 addition & 1 deletion R/dt_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,5 @@ dt_options_tbl <-
"quarto_disable_processing", FALSE, "quarto", "logical", FALSE,
"quarto_use_bootstrap", FALSE, "quarto", "logical", FALSE,
"latex_use_longtable", FALSE, "latex", "logical", FALSE,
"latex_tbl_pos", FALSE, "latex", "value", "!t",
"latex_tbl_pos", FALSE, "latex", "value", "t",
)[-1, ]
9 changes: 5 additions & 4 deletions R/tab_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,11 @@
#'
#' *Specify latex floating position*
#'
#' The latex position indicator for a floating environment (e.g., `"!t"`,
#' `"H"`). It should be specified without square brackets. Quarto users should
#' instead set the floating position within the code chunk argument `tbl-pos`.
#' The output table will only float if `latex.use_longtable = FALSE`.
#' The latex position indicator for a floating environment (e.g., `"tb"`,
#' `"h"`). If not specified, latex position will default to `"t"``. It should be
#' specified without square brackets. Quarto users should instead set the
#' floating position within the code chunk argument `tbl-pos`. The output
#' table will only float if `latex.use_longtable = FALSE`.
#'
#' @return An object of class `gt_tbl`.
#'
Expand Down
6 changes: 2 additions & 4 deletions man/tab_options.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/as_latex.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
Code
gt_latex_styled
Output
[1] "\\begin{table}[!t]\n\\fontsize{12.0pt}{14.4pt}\\selectfont\n\\begin{tabular*}{\\linewidth}{@{\\extracolsep{\\fill}}l|rlcrrr}\n\\toprule\n & \\multicolumn{3}{c}{{\\itshape heading}} & & \\multicolumn{2}{c}{heading} \\\\ \n\\cmidrule(lr){2-4} \\cmidrule(lr){6-7}\n{$\\overline{\\mbox{stubhead}}$} & {NUM} & char & fctr\\textsuperscript{\\textit{1}} & time & {DATETIME} & currency \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\multicolumn{7}{l}{grp\\_a} \\\\[2.5pt] \n\\midrule\\addlinespace[2.5pt]\n{\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_1}}} & 0.1111 & apricot & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{one}} & 13:35 & {\\scriptsize 2018-01-01 02:22} & 49.95 \\\\ \n{\\slshape \\hspace{11.25pt}\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_2}}} & 2.2220 & {\\bfseries \\hspace{15pt}banana} & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{two}} & 14:40 & {\\scriptsize 2018-02-02 14:33} & 17.95 \\\\ \n{\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_3}}} & 33.3300 & coconut & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{three}} & \\textsuperscript{\\textit{2}}{\\fontsize{15}{18.75}\\selectfont \\underline{\\textcolor[HTML]{FF0000}{15:45}}} & {\\scriptsize 2018-03-03 03:44} & 1.39 \\\\ \n{\\slshape \\hspace{11.25pt}\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_4}}} & 444.4000 & {\\bfseries \\hspace{15pt}durian} & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{four}} & {\\fontsize{15}{18.75}\\selectfont \\underline{\\textcolor[HTML]{FF0000}{16:50}}} & {\\scriptsize 2018-04-04 15:55} & 65100.00 \\\\ \n\\midrule \nTotal & {\\cellcolor[HTML]{00FF00}{480.06}} & — & — & — & — & {\\cellcolor[HTML]{00FF00}{65,169.29}} \\\\ \nAvg & 120.02 & — & — & — & — & 16,292.32 \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\multicolumn{7}{l}{{\\bfseries \\cellcolor[HTML]{CCCCFF}{grp\\_b}}} \\\\[2.5pt] \n\\midrule\\addlinespace[2.5pt]\n{\\slshape \\hspace{11.25pt}\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_5}}} & 5550.0000 & {\\bfseries \\hspace{15pt}NA} & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{five}} & 17:55 & {\\scriptsize 2018-05-05 04:00} & 1325.81 \\\\ \n\\midrule \n\\midrule \n{\\bfseries Grand Total} & {\\cellcolor[HTML]{AAAAAA}{6,030.06}} & {\\cellcolor[HTML]{AAAAAA}{—}} & {\\cellcolor[HTML]{AAAAAA}{—}} & {\\cellcolor[HTML]{AAAAAA}{—}} & {\\cellcolor[HTML]{AAAAAA}{—}} & {\\cellcolor[HTML]{AAAAAA}{66,495.10}} \\\\ \n\\bottomrule\n\\end{tabular*}\n\\begin{minipage}{\\linewidth}\n\\textsuperscript{\\textit{1}}{\\bfseries This is a footnote in the column labels.}\\\\\n\\textsuperscript{\\textit{2}}{\\bfseries This is a footnote. With a second line.}\\\\\n{\\itshape \\fontsize{6}{7.5}\\selectfont NOTES: A mtcars example.\\\\\n}\\end{minipage}\n\\end{table}\n"
[1] "\\begin{table}[t]\n\\fontsize{12.0pt}{14.4pt}\\selectfont\n\\begin{tabular*}{\\linewidth}{@{\\extracolsep{\\fill}}l|rlcrrr}\n\\toprule\n & \\multicolumn{3}{c}{{\\itshape heading}} & & \\multicolumn{2}{c}{heading} \\\\ \n\\cmidrule(lr){2-4} \\cmidrule(lr){6-7}\n{$\\overline{\\mbox{stubhead}}$} & {NUM} & char & fctr\\textsuperscript{\\textit{1}} & time & {DATETIME} & currency \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\multicolumn{7}{l}{grp\\_a} \\\\[2.5pt] \n\\midrule\\addlinespace[2.5pt]\n{\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_1}}} & 0.1111 & apricot & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{one}} & 13:35 & {\\scriptsize 2018-01-01 02:22} & 49.95 \\\\ \n{\\slshape \\hspace{11.25pt}\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_2}}} & 2.2220 & {\\bfseries \\hspace{15pt}banana} & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{two}} & 14:40 & {\\scriptsize 2018-02-02 14:33} & 17.95 \\\\ \n{\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_3}}} & 33.3300 & coconut & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{three}} & \\textsuperscript{\\textit{2}}{\\fontsize{15}{18.75}\\selectfont \\underline{\\textcolor[HTML]{FF0000}{15:45}}} & {\\scriptsize 2018-03-03 03:44} & 1.39 \\\\ \n{\\slshape \\hspace{11.25pt}\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_4}}} & 444.4000 & {\\bfseries \\hspace{15pt}durian} & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{four}} & {\\fontsize{15}{18.75}\\selectfont \\underline{\\textcolor[HTML]{FF0000}{16:50}}} & {\\scriptsize 2018-04-04 15:55} & 65100.00 \\\\ \n\\midrule \nTotal & {\\cellcolor[HTML]{00FF00}{480.06}} & — & — & — & — & {\\cellcolor[HTML]{00FF00}{65,169.29}} \\\\ \nAvg & 120.02 & — & — & — & — & 16,292.32 \\\\ \n\\midrule\\addlinespace[2.5pt]\n\\multicolumn{7}{l}{{\\bfseries \\cellcolor[HTML]{CCCCFF}{grp\\_b}}} \\\\[2.5pt] \n\\midrule\\addlinespace[2.5pt]\n{\\slshape \\hspace{11.25pt}\\cellcolor[HTML]{AA0000}{\\textcolor[HTML]{FFFFFF}{\\hspace*{3.75pt} row\\_5}}} & 5550.0000 & {\\bfseries \\hspace{15pt}NA} & {\\fontsize{15}{18.75}\\selectfont \\textcolor[HTML]{0000FF}{five}} & 17:55 & {\\scriptsize 2018-05-05 04:00} & 1325.81 \\\\ \n\\midrule \n\\midrule \n{\\bfseries Grand Total} & {\\cellcolor[HTML]{AAAAAA}{6,030.06}} & {\\cellcolor[HTML]{AAAAAA}{—}} & {\\cellcolor[HTML]{AAAAAA}{—}} & {\\cellcolor[HTML]{AAAAAA}{—}} & {\\cellcolor[HTML]{AAAAAA}{—}} & {\\cellcolor[HTML]{AAAAAA}{66,495.10}} \\\\ \n\\bottomrule\n\\end{tabular*}\n\\begin{minipage}{\\linewidth}\n\\textsuperscript{\\textit{1}}{\\bfseries This is a footnote in the column labels.}\\\\\n\\textsuperscript{\\textit{2}}{\\bfseries This is a footnote. With a second line.}\\\\\n{\\itshape \\fontsize{6}{7.5}\\selectfont NOTES: A mtcars example.\\\\\n}\\end{minipage}\n\\end{table}\n"
attr(,"class")
[1] "knit_asis"
attr(,"knit_meta")
Expand Down
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.4pt}\\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\\fontsize{12.0pt}{14.4pt}\\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"
attr(,"class")
[1] "knit_asis"
attr(,"knit_meta")
Expand Down

0 comments on commit fb5379b

Please sign in to comment.