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?
To center an image using the knitr::include_graphics() function, include it within an R code chunk that has the fig. align='center' option (and perhaps other options to control width, etc.). For example: Be sure to include the echo = FALSE chunk option to prevent the chunk source code from being printed.
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.
headers - Place one or more hashtags at the start of a line that will be a header (or sub-header). For example, # Say Hello to markdown . A single hashtag creates a first level header. Two hashtags, ## , creates a second level header, and so on.
You use results="hide" to hide the results/output (but here the code would still be displayed). You use include=FALSE to have the chunk evaluated, but neither the code nor its output displayed.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With