gt
gt copied to clipboard
Add options for specialized environments before and after LaTeX table code
This new issue is based on a comment from @kuriwaki from the closed issue https://github.com/rstudio/gt/issues/114.
xtable::print.xtable
has an argument floating
that either generates .tex with a float environment with captions \begin{table}...
(the default), or without the floating environment and starts directly with \begin{tabular}
(if set to FALSE
). Both options would be great to have with the file
export argument.
library(xtable)
library(ggplot2)
tab <- xtabs(~ cyl + drv, data = mpg)
xtbl <- xtable(tab)
print.xtable(xtbl, floating = TRUE)
#> % latex table generated in R 3.5.1 by xtable 1.8-3 package
#> % Sun Jan 13 15:28:24 2019
#> \begin{table}[ht]
#> \centering
#> \begin{tabular}{rrrr}
#> \hline
#> & 4 & f & r \\
#> \hline
#> 4 & 23 & 58 & 0 \\
#> 5 & 0 & 4 & 0 \\
#> 6 & 32 & 43 & 4 \\
#> 8 & 48 & 1 & 21 \\
#> \hline
#> \end{tabular}
#> \end{table}
print.xtable(xtbl, floating = FALSE)
#> % latex table generated in R 3.5.1 by xtable 1.8-3 package
#> % Sun Jan 13 15:28:24 2019
#> \begin{tabular}{rrrr}
#> \hline
#> & 4 & f & r \\
#> \hline
#> 4 & 23 & 58 & 0 \\
#> 5 & 0 & 4 & 0 \\
#> 6 & 32 & 43 & 4 \\
#> 8 & 48 & 1 & 21 \\
#> \hline
#> \end{tabular}
Created on 2019-01-13 by the reprex package (v0.2.1)
It would be great to control the floating of a table (as in LaTeX like \begin{table}[htbp]
) and not just automatically break it. Or at least control the floating environment (table
instead of lontable
).
I want to second this suggestion. I am in the process of switching over to gt
from kableExtra
and this is the one thing making that transition difficult. IMO, a floating environment should be the default for any latex output.
Hi! Just checking in on this, given advancements in Quarto. With Quarto it's possible to control figure position in PDF/LaTeX documents (see https://quarto.org/docs/authoring/figures.html#figure-position), with options like b
, h
, t
, etc.
With {gt} tables, though, it isn't possible yet, leading to tables that span multiple pages and the general inability to position tables as floats, like this issue/discussion here: https://github.com/quarto-dev/quarto-cli/discussions/7171