简体   繁体   中英

How to center figure caption in R markdown

I am using knitR to import my image into my rmarkdown and I wrote captions using fig.cap. My image is already centered but my caption is always left-aligned. Is there anyway to also align my caption under my image?

```{r, echo=FALSE, fig.align='center', fig.cap="tmap with multiple data classification methods and classes"}
knitr::include_graphics("tmap01.png")

编织图像

Inspecting the document shows that the caption is in a p tag with class caption , and there's no CSS associated to this class. So you can set some CSS properties to the caption class, by adding this CSS chunk (eg at the beginning of the document):

```{css}
.caption {
  margin: auto;
  text-align: center;
}
```

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