简体   繁体   中英

errors in figure caption in r markdown caption outside float

I tried to put the plot objects in r markdown. The fig.cap worked well in the first r chunk. However problems occurred when I tried to put the second figure. Please see the code below.

The YAML looks like this

output:
  bookdown::pdf_document2:
    toc: no
header-includes:
- \usepackage{setspace}\doublespacing
- \usepackage{float}
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{amsmath}
- \usepackage{multicol}
- \usepackage{threeparttable}
- \usepackage{caption}

The code in r chunk is

{r trend_1, echo=F, fig.cap='The air pollution trend of different groups',out.width='50%',message=F, fig.show='hold'}

The code for plotting is (these are two plot objects)

state.con.oz
state.con.pm

I got an error : Package caption Error. \caption outside float. : Package caption Error. \caption outside float. Any ideas?

BTW, I wonder how to create a figure footnote in r markdown?

Thanks in advance.

Try to name your R code chunk without underlines

```{r trend1, echo=F, fig.cap='The air pollution trend of different groups',out.width='50%',message=F, fig.show='hold'}

your_plot
```

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM