Skip to content

Commit 38a4c85

Browse files
Set col widths for tables; fix issue with extra-wide tables
1 parent 1340050 commit 38a4c85

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

R/create_tables_doc.R

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ load(file.path(tables_dir, '", stringr::str_remove(tab, "_split"), "'))\n
181181
if (tbl_class == "reg_reg") {
182182
tables_doc_plot_setup2 <- paste0(
183183
add_chunk(
184-
glue::glue("{tab_shortname}_table"),
184+
glue::glue("{tab_shortname}_table |>\n",
185+
" gt::cols_width(\n",
186+
" everything() ~ pct(20)\n",
187+
" ) \n"
188+
),
185189
label = glue::glue("tbl-{tab_shortname}"),
186190
# add_option = TRUE,
187191
chunk_option = c(
@@ -208,10 +212,10 @@ load(file.path(tables_dir, '", stringr::str_remove(tab, "_split"), "'))\n
208212
" gt::tab_options(\n",
209213
" table.width = pct(100),\n",
210214
" table.layout = 'auto'\n",
211-
" ) \n"#|>,
212-
# " gt::cols_width(\n",
213-
# " everything() ~ px(144)\n",
214-
# " )"
215+
" ) |>\n",
216+
" gt::cols_width(\n",
217+
" everything() ~ pct(20)\n",
218+
" ) \n"
215219
),
216220
label = glue::glue("tbl-{tab_shortname}"),
217221
# add_option = TRUE,
@@ -231,7 +235,7 @@ load(file.path(tables_dir, '", stringr::str_remove(tab, "_split"), "'))\n
231235
}
232236

233237
## add table if it is long enough to be shown on >1 portrait ("reg_long") OR landscape ("wide_long") page
234-
### only difference: latter has landscape braces
238+
### only differences: latter has landscape braces and narrower cols
235239
if (tbl_class == "reg_long" | tbl_class == "wide_long") {
236240
# identify number of tables in rda
237241
load(fs::path(tables_dir, "tables", tab))
@@ -259,8 +263,9 @@ load(file.path(tables_dir, '", stringr::str_remove(tab, "_split"), "'))\n
259263
" table.width = pct(100),\n",
260264
" table.layout = 'auto'\n",
261265
" ) |>\n",
262-
# " gt::cols_width(\n",
263-
# " everything() ~ px(144)) |>\n",
266+
" gt::cols_width(\n",
267+
" everything() ~ pct(20)\n",
268+
" ) \n",
264269
" gt::gt_split(row_every_n = ", max_rows, ") |>\n",
265270
" gt::grp_pull(", i, ")\n"
266271
),
@@ -296,6 +301,11 @@ load(file.path(tables_dir, '", stringr::str_remove(tab, "_split"), "'))\n
296301
plot_name = tab,
297302
essential_columns = 1
298303
)
304+
305+
# identify number of split tables
306+
tab <- gsub("table", "table_split", tab)
307+
load(fs::path(tables_dir, "tables", tab))
308+
split_tables <- length(table_list)
299309
}
300310

301311
# add a chunk to import split tables
@@ -333,10 +343,10 @@ load(file.path(tables_dir, '", stringr::str_remove(tab, "_split"), "'))\n
333343
" gt::tab_options(\n",
334344
" table.width = pct(100),\n",
335345
" table.layout = 'auto'\n",
336-
" ) \n"#|>,
337-
# " gt::cols_width(\n",
338-
# " everything() ~ px(144)\n",
339-
# " ) \n"
346+
" ) |>\n",
347+
" gt::cols_width(\n",
348+
" everything() ~ pct(20)\n",
349+
" ) \n"
340350
),
341351
label = glue::glue("tbl-{tab_shortname}", i),
342352
add_option = TRUE,
@@ -374,6 +384,11 @@ load(file.path(tables_dir, '", stringr::str_remove(tab, "_split"), "'))\n
374384
plot_name = tab,
375385
essential_columns = 1
376386
)
387+
388+
# identify number of split tables
389+
tab <- gsub("table", "table_split", tab)
390+
load(fs::path(tables_dir, "tables", tab))
391+
split_tables <- length(table_list)
377392
}
378393
# identify number of tables that each split table must be further split
379394
# into, with different rows per table
@@ -417,8 +432,9 @@ load(file.path(tables_dir, '", stringr::str_remove(tab, "_split"), "'))\n
417432
" table.width = pct(100),\n",
418433
" table.layout = 'auto'\n",
419434
" ) |>\n",
420-
# " gt::cols_width(\n",
421-
# " everything() ~ px(144)) |>\n",
435+
" gt::cols_width(\n",
436+
" everything() ~ pct(20)\n",
437+
" ) \n",
422438
" gt::gt_split(row_every_n = ", max_rows, ") |>\n",
423439
" gt::grp_pull(", j, ")\n"
424440
),

0 commit comments

Comments
 (0)