-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specify width of LaTeX table #119
Comments
Thanks for the helpful comments here. Most of the options in The plan then is to create a compatibility table that states where the options are currently working. My thought is to add that a vignette that's focussed on table options or perhaps to a more development-focussed article. We should use some alternative to the Let's keep the discussion going on this. |
I really love the {gt} package so far, you've built a really nice interface! The only thing that keeps me from shipping a professional PDF doc out the door is the scaling issue, though. Has there been any progress on this? |
Just adding a comment in case it helps others. I also love For now we're doing something like: gt::gt() %>% gt::gtsave("~/junk/table.png")
# Then in Rmd file something like this
```{r, echo = FALSE, warning = FALSE, out.width="75%"}
knitr::include_graphics("~/junk/table.png")
|
Has anyone found a solution already to the scaling issue with the gt package knitting to a pdf ? I try to use table.width without success. (table.background.color) doesn't work either. The code works wonders in R , however the pdf output just completely ignores the formatting. Also I try to use the above suggestion : gt::gt(gt_tbl) %>% gt::gtsave("~/table.png") without success. My code: #show the gt table |
Anchors LaTeX longtable to match a width set by the user. Table width is achieved by changing the space between columns to produce a table that matches the specified width.
Inspired by an example shared by Andrew Heiss I wrote a wrapper function that I'm using to support specification of percent widths in LaTeX output tables. It currently requires passing column names as a character vector and you need to manually set your overall text width but otherwise it is working really well for me. I may update it so the columns are optional and you can get the column names from the boxhead element of the gt table but, obviously, if someone tackles this issue within perc <- function(x,
textwidth = 7.5,
dpi = 96,
unit = "in",
scale = TRUE,
use_pct = knitr::is_html_output()) {
if (scale && (x < 1)) {
x <- x * 100
}
if (use_pct) {
return(gt::pct(x))
}
paste0(textwidth * (x / dpi), unit)
} cols_width_ext <- function(data,
columns = NULL,
widths = NULL,
.list = NULL,
textwidth = 7.5,
dpi = 96,
unit = "in",
scale = TRUE) {
if (is.null(.list)) {
if (is.null(widths)) {
return(data)
}
if (rlang::is_named(widths)) {
columns <- columns %||% names(widths)
}
stopifnot(all(purrr::map_lgl(columns, is.character)))
.list <- lapply(
seq_along(widths),
\(i) {
rlang::new_formula(
columns[[i]],
perc(
widths[[i]],
textwidth = textwidth,
dpi = dpi,
unit = unit,
scale = scale
)
)
}
)
}
gt::cols_width(
data,
.list = .list
)
} Created on 2023-12-13 with reprex v2.0.2 |
Fixed in gt 0.11 #1465 |
The setting
tab_options(table.width = pct(100))
doesn't seem to be respected when rendering to LaTeX, see reprex below. Is this something you'd consider supporting?It seems that the
longtable
LaTeX environment is used to render all tables. The fairly newxltabular
package could be an option to render long tables with support for theX
column modifier, which could perhaps be applied to all columns that are left-aligned.Related: setting column width (#111).
Created on 2019-01-01 by the reprex package (v0.2.1.9000)
The text was updated successfully, but these errors were encountered: