pagedown icon indicating copy to clipboard operation
pagedown copied to clipboard

Separate figure numbering for appendix/supplemental section?

Open paulcbauer opened this issue 2 years ago • 3 comments

We are currently writing up our first pagedown manuscript for submission. Is there a possibility to separate figure numbering for the appendix/supplemental section? Something analog to the question/answer in this discussion for latex: https://stackoverflow.com/questions/50223141/rmarkdown-bookdown-separate-figure-numbering-for-supplemental-section

paulcbauer avatar Jan 31 '22 18:01 paulcbauer

I am searching for something analog to...

.reset-counters {
  counter-reset: page 1;
}

# Appendix {.reset-counters}

...but not only for pages but also for figures and tables.

paulcbauer avatar Feb 01 '22 17:02 paulcbauer

Hi Paul,

I came across you post while adding an issue myself... I'm not sure how much I can help you, but I have tried to do something similar for a report generated using a customized pagedreport template. I have ended up creating separate documents for my appendices, but some of the things I've done might be helpful.

I have a file, setup.Rmd, that I run at the beginning of my code that (re)sets the figure and counters (note this is for my Appendix "B"):

  ###   Set Table, Figure and Equation Counters
  setCounters()
  options(table_counter=FALSE)
  options(table_num_str = "B%d") # Prepend Appendix Letter when using tblNum()
  options(table_counter_str = paste0("**Table ", "B", "%s:**")) # "**Table A%s:**" LETTERS[appendix.number]
  options(fig_num_str = "B%d") # Prepend Appendix Letter when using figNum()
  options(fig_caption_no_sprintf = paste0("**Figure ", "B", "%d:** %s")) # "**Figure A%d:** %s"

The setCounters function is just a little helper function that could probably just be included in the above:

`setCounters` <- function(tbl.counter=0, fig.counter=0, eqn.counter=0) {
  options("table_number" = tbl.counter)
  options("fig_caption_no" = fig.counter)
  options("equation_counter" = eqn.counter)
}

This may not work if you reset the counters before your appendix section(s).

For a standalone Appendix file I had to set up my own pagedown report (html) template and a specific css file to change the page numbers (e.g., "B-1", "B-2", etc. Here's the CSS I used to change the page numbers, but I don't think I was ever able to update/change the counter that page is based on:

@page maincontent {
  @bottom-center {
      content: var(--appendix-prefix, "A") " - " counter(page);
      color: #279F27;
      margin-top: 1.8cm;
      margin-bottom: 1cm;
      font-size: 9pt;
      font-weight: bold;
  }
}

That's set up to read in some meta-data (--appendix-prefix) so you might want to change it to content: "B - " counter(page);. But I think adding that in the middle of a single document would probably either change the whole document page numbering or cause worse problems...

FYI, the default css for pagedown is here, and you can see some of the customizations I've done (borrowing from others) here for the appendices.

Hope that helps in some way!

adamvi avatar Mar 17 '22 17:03 adamvi

Hi both of you,

@adamvi thanks so much for all your insights! And for sharing your customized css file - so valuable! I was trying to test your above ideas in one of my pagedown documents but haven’t gotten too far :-/

Especially your first solution is of interest to me - I right now don’t want to manipulate the page numbers, but the figure/table numberings only. So I think your first solution via the setCounters() function might be of help. But unfortunately it does not seem to work for me. Maybe you have some further ideas/insights..

  • Do you know for what kind of tables your setCounters function applies? For instance, I use kable functions, maybe there are there other option parameters I have to use (e.g. besides of table_num_str)?
  • Also, you said you run a file at the beginning of your code. I simply tried to include a code chunk with the function and your code above at the very beginning of my .rmd - however without success - nothing changed (e.g., no change in numbering and no appending of a „B“ etc.)

Of course it also didn’t work when I tried to include it only before the appendix section (unfortunately I am interested in a single PDF containing main text and appendix).

Thanks so much! & sorry for only asking even more questions haha!

clandesv avatar Mar 24 '22 11:03 clandesv