Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I center image in R markdown in knit word

Tags:

r

r-markdown

I want to center image in R markdown in knit word.

I search result almost is CSSor HTML code.

But I need center image in word.

This my code

![avatar](C:/Users/user/Desktop/picture1.jpg){ width=5cm }

Thanks!

like image 652
disney82231 Avatar asked Oct 16 '25 21:10

disney82231


1 Answers

I encountered the same problem and managed to solve it using a .docx file template that I declared at the beginning of the document:

---
output:
    word_document:
        reference_docx: template.docx
---

Just open your template file, select a figure, then press Ctrl + Shift + s to display the style panel for Microsoft Word. Change the alignment style of the text to "centered". Save your template.docx then knit your document as usual.

like image 122
Annesohie Avatar answered Oct 18 '25 10:10

Annesohie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!