Skip to content

Column spanners do not comply with widths set by cols_widths() for latex tables #1656

Closed
@bzkrouse

Description

@bzkrouse

Prework

Description

cols_width() works great for latex tables without any column spanners. The widths are set and text wrapping occurs as needed.
However when column spanners are introduced they do not inherit these defined widths, and any long spanner text does not wrap.
It seems the \multicolumn definitions may need their own widths specified in addition to the individual columns.
This can be observed by comparing the following tables rendered to pdf:

library(gt)
mytbl <- tibble::tribble(
  ~ "First column name", ~"Second column name", ~"Third column name", ~"Fourth column name", ~"Fifth column name",
  ~ "Sixth column name", ~"Seventh column name", ~"Eighth column name", ~"Ninth column name", ~"Tenth column name",
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10
) |>
  gt() |>
  cols_width(
    everything() ~ pct(10)
  ) 

# table without spanner
mytbl

# table with spanner
mytbl  |>
  tab_spanner(
    label = "A very long column spanner to go over the allotted width",
    columns = c(
      "First column name", "Second column name"
    )
  )

If i replace

\multicolumn{2}{c}{A very long column spanner to go over the allotted width} &  &  &  &  &  &  &  &  \\ 

with

\multicolumn{2}{p{0.2\linewidth}}{A very long column spanner to go over the allotted width} &  &  &  &  &  &  &  &  \\ 

in the resulting tex table, it seems to help. Thanks for the consideration!!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions