-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1495 from kbrevoort/issue-1465
Issue 1465
- Loading branch information
Showing
4 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
test_that("Table width correctly output in LaTeX", { | ||
|
||
gt_latex_width_1 <- | ||
gt(exibble) %>% | ||
tab_options(table.width = pct(90)) %>% | ||
as_latex() | ||
|
||
start_pt <- regexpr("begin\\{longtable", gt_latex_width_1) | ||
|
||
expect_gt(start_pt, 0) # Verifies the long table command appears in the text | ||
|
||
end_pt <- regexpr("end\\{longtable", gt_latex_width_1) | ||
|
||
expect_gt(end_pt, 0) | ||
|
||
# Verify that the holdLTleft and holdLTright variables are defined and set | ||
latex_prefix <- substr(gt_latex_width_1, 1L, start_pt) | ||
|
||
expect_match(latex_prefix, "\\\\newlength\\\\holdLTleft") | ||
|
||
expect_match(latex_prefix, "\\\\newlength\\\\holdLTright") | ||
|
||
expect_match(latex_prefix, "\\\\setlength\\\\holdLTleft\\{\\\\LTleft\\}\\\\relax") | ||
|
||
expect_match(latex_prefix, "\\\\setlength\\\\holdLTright\\{\\\\LTright\\}\\\\relax") | ||
|
||
# Verify that LTleft and LTright are correctly specified | ||
expect_match(latex_prefix, "\\\\setlength\\\\LTleft\\{0.05\\\\linewidth\\}") | ||
|
||
expect_match(latex_prefix, "\\\\setlength\\\\LTright\\{0.05\\\\linewidth\\}") | ||
|
||
# Verify that after the longtable environment, the LTleft and LT right are | ||
# changed back to their previous values | ||
latex_suffix <- substr(gt_latex_width_1, end_pt, nchar(gt_latex_width_1)) | ||
|
||
expect_match(latex_suffix, "\\\\setlength\\\\LTleft\\{\\\\holdLTleft\\}") | ||
|
||
expect_match(latex_suffix, "\\\\setlength\\\\LTright\\{\\\\holdLTright\\}") | ||
|
||
# Test specification of a table width in pixels | ||
gt_latex_width_2 <- | ||
gt(exibble) %>% | ||
tab_options(table.width = '600px') %>% | ||
as_latex() | ||
|
||
expect_match(gt_latex_width_2, "\\\\setlength\\\\LTleft\\{\\\\dimexpr\\(0.5\\\\linewidth - 225pt\\)\\}") | ||
|
||
expect_match(gt_latex_width_2, "\\\\setlength\\\\LTright\\{\\\\dimexpr\\(0.5\\\\linewidth - 225pt\\)\\}") | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters