title: Formatting tables in R Marksdown using expss
body: <p>I am having some troubles in formatting some tables using <code>expss</code> in an <code>R Markdown</code>. The output is a pdf file. <code>knitr</code> options are:</p>
  
  <pre><code>knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
  </code></pre>
  
  <p>Following the vignette on <code>expss</code> (available here <a href="https://cran.r-project.org/web/packages/expss/vignettes/tables-with-labels.html" rel="noreferrer">https://cran.r-project.org/web/packages/expss/vignettes/tables-with-labels.html</a>),  I have written the following code:</p>
  
  <pre><code>sl_expss_long %&gt;%  # the tibble
    calc_cro_cpct(
      cell_vars = list(br, cl, cm, fgm, vd), # rows
      col_vars = list(total(), area) # columns
    ) %&gt;% 
    set_caption("Table 1")
  </code></pre>
  
  <p>This code works just fine in <code>R Studio</code>, and produces this table:</p>
  
  <pre><code> Table 1                                                                                    
   |                                      |              |  #Total |   Area |        |
   |                                      |              |         |  Rural |  Urban |
   | ------------------------------------ | ------------ | ------- | ------ | ------ |
   |                   Birth registration |        FALSE |    64.4 |   61.6 |   70.9 |
   |                                      |         TRUE |    35.6 |   38.4 |   29.1 |
   |                                      | #Total cases |  8207.0 | 5732.0 | 2475.0 |
   |                         Child labour |        FALSE |    50.5 |   47.0 |   64.2 |
   |                                      |         TRUE |    49.5 |   53.0 |   35.8 |
   |                                      | #Total cases |  5136.0 | 4085.0 | 1051.0 |
   |                       Child marriage |        FALSE |    98.8 |   98.6 |   99.2 |
   |                                      |         TRUE |     1.2 |    1.4 |    0.8 |
   |                                      | #Total cases | 12158.0 | 7827.0 | 4331.0 |
   | Female genitale mutilation / cutting |        FALSE |     8.2 |    7.6 |    9.3 |
   |                                      |         TRUE |    91.8 |   92.4 |   90.7 |
   |                                      | #Total cases |  9203.0 | 6144.0 | 3059.0 |
   |             Violent child discipline |        FALSE |     9.9 |   10.4 |    8.9 |
   |                                      |         TRUE |    90.1 |   89.6 |   91.1 |
   |                                      | #Total cases | 11547.0 | 7818.0 | 3729.0 |
  </code></pre>
  
  <p>Similarly, it works in <code>R Studio</code> with the following code:</p>
  
  <pre><code>sl_expss_long %&gt;% 
    tab_cells(br, cl, cm, fgm, vd) %&gt;%
    tab_cols(total(), area) %&gt;% 
    tab_stat_cpct() %&gt;%
      tab_pivot() %&gt;% 
    set_caption("Table with summary statistics and significance marks.")
  </code></pre>
  
  <p>However, when I put the code into my <code>R Markdown</code>, I get the following result:</p>
  
  <pre><code>Table with summary statistics
  National
  Area
  Rural
  Urban
  Birth registration
  FALSE
  64.4
  61.6
  70.9
  TRUE
  35.6
  38.4
  29.1
  #Total cases
  8207
  
  etc.
  </code></pre>
  
  <p>My table is just one column wide and three pages long.</p>
  
  <p>I temporarily fixed it using <code>pander</code>, <code>kable</code> and <code>kableExtra</code>></p>
  
  <pre><code>sl_expss_long %&gt;% 
    tab_cells(br, cl, cm, fgm, vd) %&gt;%
    tab_cols(total(label = " National| |"), area) %&gt;% 
    tab_stat_cpct() %&gt;%
    tab_pivot() %&gt;% 
    set_caption("Table with summary statistics") %&gt;% 
    split_table_to_df() %&gt;% 
    kable(caption = "Table with summary statistics") %&gt;% 
    kable_styling(bootstrap_options = c("striped"),
                 latex_options = "hold_position") %&gt;% 
    row_spec(1:2, bold = TRUE)
  </code></pre>
  
  <p>and get this result:</p>
  
  <p><img src="https://i.stack.imgur.com/ni3xW.png" alt="output table from the previous code"></p>
  
  <p>As you can see, the table from <code>R Markdown</code> has added a row at the beginning of the table, and the word "area" is supposed to be on top of both "Rural" and Urban". This is based on my understanding from the vignette is that using <code>expss</code> in a <code>R Markdown</code> would produce the table that we can see in the vignette.</p>
  
  <p><img src="https://i.stack.imgur.com/UQc9Q.png" alt="expss table example from vignette"></p>
  
  <p>Any help on what I might be missing?</p>
  
  <p>Many thanks in advance</p>
  
  <p>Manolo</p>