4

I am trying to change the font size of a paragraph using Officer but I am not able to do it. Can anyone tell me what I am doing wrong?

library(officer)
text_style <- fp_text(font.size = 12)

my_doc <- read_docx()
body_add_par(my_doc,"This is a test", style = text_style)
print(my_doc, target = "dummy.docx")
Bruno Guarita
  • 767
  • 10
  • 21
  • 1
    You are using a text style, but the `body_add_par` function requires a paragraph style (which you can create using `fp_par`). I don't see the font size as one of the properties you can set for the paragraph however. – Kerry Jackson Sep 04 '18 at 14:09

1 Answers1

8

Function body_add_par() is expecting a style name (taken from those existing in the original document).

If you want to add a paragraph made of formatted chunk of text, you will need to use body_add_fpar() as illustrated below .

library(officer)
text_style <- fp_text(font.size = 12)
par_style <- fp_par(text.align = "justify")
my_doc <- read_docx()
my_doc <- body_add_fpar(my_doc, fpar( ftext("This is a test", prop = text_style), fp_p = par_style ) )
print(my_doc, target = "dummy.docx")
David Gohel
  • 9,180
  • 2
  • 16
  • 34
  • 2
    David Gohel, thanks for your nice library Officer! In the example above: how can I align the text to "justify"? – Bruno Guarita Sep 04 '18 at 16:43
  • 1
    Hi @David Gohel, Thank you for your nice package. Can I use ftext in slip_in_text? I need to add some text with shadings into a existing paragraph. – Li Sun Feb 06 '20 at 21:15