1

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?

Wawa
  • 73
  • 9
  • can you use `fpar` and set the text style in the `fp_p` or `fp_t` argument? – morgan121 Jul 23 '19 at 06:36
  • Welcome to [so]! Please read [ask] and give a [mre] in your question! – jogo Jul 23 '19 at 06:43
  • But currently im using ph_add_text. But after I add new text, the new text not justify at center. How to put fpar in ph_add_text? – Wawa Jul 23 '19 at 07:03

1 Answers1

1

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

J.Sabree
  • 2,280
  • 19
  • 48