Centering image and text in R Markdown for a PDF report

后端 未结 9 1675
情深已故
情深已故 2020-12-28 12:10

I want to center an image and/or text using R Markdown and knit a PDF report out of it.

I have tried using:

->Text<-

->![](image1.jpg)<-         


        
9条回答
  •  抹茶落季
    2020-12-28 12:30

    None of the answers work for all output types the same way and others focus on figures plottet within the code chunk and not external images.

    The include_graphics() function provides an easy solution. The only argument is the name of the file (with the relative path if it's in a subfolder). By setting echo to FALSE and fig.align=center you get the wished result.

    ```{r, echo=FALSE, fig.align='center'}
    include_graphics("image.jpg")
    ```
    

提交回复
热议问题