-
Notifications
You must be signed in to change notification settings - Fork 207
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
Fix table widths for latex tables and add unit testing #1867
Conversation
Add tests for setting table widths for latex tables
Hi @snhansen! Thanks for working on this! We will try to review soon. But first, please use |
@olivroy: Of course! Should be done now. |
I didn't notice before, but it seems like your changes affect other tests https://github.com/rstudio/gt/actions/runs/10629794644/job/29475689750. You'd have to review and accept those if they make sense! |
@olivroy: Thanks, the tests did indeed reveal a mistake on my part. I think it should be good now though. Could you press the button to run tests again? 🤞 |
I unfortunately don't have that power, but we will review soon! from what I can see, it looks pretty good. The testing seems thorough and the explanations are clear. (All tests also pass locally for me)
If you wish to change that, feel free to open a new PR!
Agreed. Full widths tables were never a thing before in gt. See this comment about that #1588 (comment)
It would be great if there was a Quarto div for this. quarto-dev/quarto-cli#8705 (comment) is a solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Summary
In the old code,
col_alignment
contains the aligment of stub columns and visible columns, in that order. In the loopfor (i in seq_along(col_alignment))
, thei
th row ofcolwidth_df
is referenced. However, there are multiple problems with that:colwidth_df
contains hidden columns, so thei
th row of that data frame doesn't not necessarily correspond to thei
th item ofcol_alignment
.colwidth_df
In this PR,
create_colwidth_df_l()
to include column alignments.create_table_start_l()
to extract only the visible columns ofcolwidth_df
and we make sure the order of the rows incolwidth_df_visible
is"row_group", "stub", "default"
. The loop is then taken over the rows ofcolwidth_df_visible
.test-l_cols_width.R
. We test five different tables where we test whethercol_widths()
works correctly in different scenarios, e.g. when merging columns, when using stubs with/without row groups as a column.Screenshots
Below are some before and after screenshots of the five examples in
test-l_cols_width.R
withlatex.use_longtable
being TRUE and FALSE in that order. When not using longtable, I've set thetable.width
manually in the screenshots, otherwise the resulting table will be a full-width table from which the column widths can't really be judged.Table 1
Table 2
Table 3
Table 4
Table 5
Additional comments:
Related GitHub Issues and PRs
cols_width()
not working when usingcols_merge()
for PDF output #1837Checklist
testthat
unit tests totests/testthat
for any new functionality.