How to hold figure position with figure caption in pdf output of knitr?

后端 未结 7 1948
不知归路
不知归路 2020-11-29 18:45

I am using knitr (1.9.5 and 1.9.17) and rmarkdown (0.5.3.1), and would like to hold figure position in the pdf output. The generated pdf file is working fine when chunk opti

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 19:06

    The code from Figure position in markdown when converting to PDF with knitr and pandoc helps me, help anyone else find it useful.

    ---
    title: "Example"
    author: "Martin"
    output: pdf_document
    ---
    
    ```{r}
    knitr::knit_hooks$set(plot = function(x, options)  {
      knitr::hook_plot_tex(x, options)
    })
    ```
    
    
    ```{r myplot, echo=FALSE, results='hide', fig.cap='Test', fig.pos='h'}
    library(ggplot2)
    ggplot(mtcars, aes(mpg, drat)) + geom_point()
    ```
    

提交回复
热议问题