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

后端 未结 7 1930
不知归路
不知归路 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:11

    The option that worked for me:

    In the .tex put at the beginning: \usepackage{float}.

    At the beginning of the Rmd: knitr::opts_chunk$set(fig.pos = 'H'). The H in upper case).

    And in every chunk with an image: fig.cap="lorem blabla" and out.extra='' (parameter value=empty string).

    No need to define: fig_caption: yes and keep_tex: yes in the yaml.

    These options make the image to keep their position, either for include_graphics and the plots generated by R code.

    I used them in the bookdown enviroment, generating the pdf and the html as expected :)

提交回复
热议问题