Getting automatic table captions for expss tables in rmarkdown

34 Views Asked by At

I have been trying to get automatic table numbering for tables generated through expss package in R Markdown. I can see that kable and huxtables are giving me automatic numbering but not tables generated in expss. I want to keep expss format as I like the format for html outputs.

The examples of an expss table for which I am not able to get it auto numbered, as 'Table 1.1: ...'.

m1 |>
 tab_cells(country, job_title, divison) |>
 tab_stat_cases() |>
 tab_pivot() |>
 tab_caption("Country, job-functions, and department of respondents")

however, if I convert this to a huxtable, I get it auto-captioned

table1 <- as_hux(tabb1) |>
 set_all_padding(2) |>
 set_outer_padding(0) |>
 set_number_format(0) |>
 set_bold(row = everywhere, col = 1) |>
 set_bottom_border(col = 1, row = everywhere) |>
 set_width(1) |>
 set_col_width(rep(c(.15, .5, .05))) |>
 set_right_border(everywhere, 1, brdr(3, "double", "grey")) |>
 set_left_border(everywhere, 1, brdr(3, "double", "grey")) |>
 set_all_borders(brdr(0.4, "solid", "lightgrey")) |>
 set_caption("Country, job-function, and department of respondents")

So, what could be the solution to still do expss tables and get them auto captioned?

I tried to give captions to expss tables as I have given to kable and huxtables. I was still not able to get expss table auto-numbered in the body of rmarkdown but this was not the case for kable and huxtable tables.

1

There are 1 best solutions below

0
Gregory Demin On

expss uses htmlTable for default knitr output. As I can see in the manual for htmlTable, htmlTable has autonumbering function. You can use the following code:

options(table_counter = TRUE)
options(table_counter_str = "Table 1.%s: ")

Perhaps, you need to adjust string for table_counter_str in the beginning of each document section.