R: how to center output in R markdown

The option for centering a plot you generated by R code in Rmd file and that for an existing figure from a file elsewhere is different.

For the figures you generated in R, I think fig.align="center" is sufficient, even if you want a PDF output.

For <center> <\center> to work, you can only use an HTML output. If you still want PDF output, I think you can use include_graphics(your_img.png) from knitr package, and then you can use chunk options like fig.align="center". If you also want to change the size of this figure, please use something like out.width="50%", but not fig.width.

For more details, I found this article really useful tips and tricks for working with images and figures in r markdown documents.


Hopefully it is not too late to add my answer.

You can use html tags in Rstudio Markdown documents.

To center a text you just need to:

<center> TEXT TO CENTER </center>

This works for me when knitting Rstudio Markdowns.


The following code worked for me.

\center Centered Text \center

And, if you need to put it in bold, as my case, you can use the underline (two at the beggining, two at the end):

\center __Centered Text__ \center

Tags:

R

R Markdown