20

I know I can set fig.align = 'center' if I want to center my figure. But what if I want to center my output in a pdf document?

Adrian
  • 9,229
  • 24
  • 74
  • 132

3 Answers3

14

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
Juliano Condi
  • 300
  • 5
  • 9
4

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.

Alfonso
  • 644
  • 7
  • 17
2

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.

Community
  • 1
  • 1
Phoenix Mu
  • 648
  • 7
  • 12