Centering image in RMarkdown for Word export

2019-09-14 01:56发布

问题:

I would like to include an image in a RMarkdown document and have it centered in the output Word.

Is this possible?

As suggested here, I have used:

<center>![My caption](myImage.png)</center>

without success.

回答1:

This is not fully satisfactory, but what I did in the end was to add a macro in my styles document:

Sub Center_All_Images()
'
' Center_All_Images Macro
'
'
For Each oILShp In ActiveDocument.InlineShapes
    oILShp.Select
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next

End Sub

I still need to run the macro manually. I wish it was run automatically when the document is created from the template.



标签: r-markdown