简体   繁体   中英

Text align in officer package

I couldn't find any argument to adjust the text alignment in ph_add_text to justify. Im using officer to make slide from r. Or any suggestions to make slide from r that have text alignment argument. Can anyone help me?

This is a year and half later, but here's what I did. First, I make the text I want into it's own object with any properties that I might have. For simplicity, I won't add any properties, like font color, etc.

my_text <- ftext("I wish this were centered!")

Next, I make another object that contains the formatting of the paragraph that the text will be in (or text box in PowerPoint) using officer's fp_par() function:

my_format <- fp_par(text.align = "center")

Now, I can put it together--here's how it could go in a slide:

slide <- ph_with(slide_object, value = fpar(my_text, fp_p = my_format), location = ph_location(left = 4.90, top = 2.3))

The trick is, within the fpar argument, to have your text first and then, within the fp_p argument, to specify for fp_par() formatting as its own object.

Here's also more information on the function in case you're interested:

https://davidgohel.github.io/officer/reference/fp_par.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM