Fix table widths for latex tables and add unit testing#1867
Fix table widths for latex tables and add unit testing#1867rich-iannone merged 8 commits intorstudio:masterfrom snhansen:master
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. |
Summary
In the old code,
col_alignmentcontains the aligment of stub columns and visible columns, in that order. In the loopfor (i in seq_along(col_alignment)), theith row ofcolwidth_dfis referenced. However, there are multiple problems with that:colwidth_dfcontains hidden columns, so theith row of that data frame doesn't not necessarily correspond to theith item ofcol_alignment.colwidth_dfIn this PR,
create_colwidth_df_l()to include column alignments.create_table_start_l()to extract only the visible columns ofcolwidth_dfand we make sure the order of the rows incolwidth_df_visibleis"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.Rwithlatex.use_longtablebeing TRUE and FALSE in that order. When not using longtable, I've set thetable.widthmanually 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
testthatunit tests totests/testthatfor any new functionality.