Gt: Specify width of LaTeX table

Created on 1 Jan 2019  Â·  2Comments  Â·  Source: rstudio/gt

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 new xltabular package could be an option to render long tables with support for the X column modifier, which could perhaps be applied to all columns that are left-aligned.

Related: setting column width (#111).

library(gt)

default_latex <-
  data.frame(a = 1, b = 2) %>%
  gt() %>%
  as_latex()

full_width_latex <-
  data.frame(a = 1, b = 2) %>%
  gt() %>%
  tab_options(table.width = pct(100)) %>%
  as_latex()

identical(default_latex, full_width_latex)
#> [1] TRUE

Created on 2019-01-01 by the reprex package (v0.2.1.9000)

[2] Intermediate [3] High [2] Medium ★ Enhancement

Most helpful comment

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?

All 2 comments

Thanks for the helpful comments here. Most of the options in tab_options() relate to HTML output but the goal is to make them largely independent of the output format (with style translation where necessary and perhaps warnings where there is no compatibility). Because LaTeX support came a bit later, it needs to catch up to HTML on these options (and RTF will need to do the same).

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 longtable LaTeX package. I tried (unsuccessfully) to use other LaTeX packages that have better options for tables and repeating headers across pages. I think it's worth experimenting with the other packages again because longtable is lean on options (and xltabular does appear to be much better). Using longtable was the safe choice at the start because it's an included package in a tinytex LaTeX installation. If I were to include a LaTeX dependency that's not available by default, I think I'd then need to include functions that support package management via tlmgr—which is not a bad/difficult thing at all, it just needs to be worked on.

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?

Was this page helpful?
0 / 5 - 0 ratings