Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: how to center output in R markdown

Tags:

r

r-markdown

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?

like image 585
Adrian Avatar asked Nov 04 '16 02:11

Adrian


People also ask

How do I center a figure in R Markdown?

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.

How do I center an output in R?

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.

What does ## do in R Markdown?

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.

How do I hide the output of a chunk in R Markdown?

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.


2 Answers

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
like image 143
Juliano Condi Avatar answered Sep 30 '22 05:09

Juliano Condi


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.

like image 20
Alfonso Avatar answered Sep 30 '22 04:09

Alfonso