knitr - Figure captions above

后端 未结 1 699
无人共我
无人共我 2020-12-17 00:27

Is there a way, in knitr to move the fig.cap above the figure? I need them above so that when the list-of-figure\'s hyperlink is selected for a certain table it navigates t

相关标签:
1条回答
  • 2020-12-17 01:12

    Maybe too late, but I think Yihui answered this.

    You can change the knit hook for all figures to have the caption above the figure. For example, here is a version of a chunk from an .Rmd document. If you tell knitr to change the option for figure to have the document look first at and then at the actual .

    ```{r setup}
    library(knitr)
    knit_hooks$set(plot = function(x, options) {
      paste('<figure><figcaption>', options$fig.cap, '</figcaption><img src="',
            opts_knit$get('base.url'), paste(x, collapse = '.'),
            '"></figure>',
            sep = '')
    })
    ```
    
    0 讨论(0)
提交回复
热议问题