Skip to content

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

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

Closed
2 tasks done
bzkrouse opened this issue May 8, 2024 · 0 comments · Fixed by #1716
Closed
2 tasks done

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

bzkrouse opened this issue May 8, 2024 · 0 comments · Fixed by #1716
Assignees
Milestone

Comments

@bzkrouse
Copy link

bzkrouse commented May 8, 2024

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!!

kbrevoort pushed a commit to kbrevoort/gt that referenced this issue Jun 17, 2024
When available, assign an explicit width to multicolumn statements to comply with user-specified column widths.
@olivroy olivroy added this to the v0.11.0 milestone Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants