Reputation: 11037
I need to create documents periodically for Word-using administrators. How can I centre an image using pandoc markdown? I see mention of div blocks, but I have no idea what they are.
![](myimage.png){.center}
With image code such as that above, and a command line such as:
pandoc -s test.md -o test.docx
or
pandoc -s test.md -o test.pdf
I always end up with left-aligned images in my document.
Upvotes: 27
Views: 19758
Reputation: 5384
This has been bugging me since forever; but if you use the markdown -> pandoc -> Latex -> PDF route, this should work:
```{=latex}
\begin{center}
```
![](folder/img.png){ height=30% }
```{=latex}
\end{center}
```
Note that without the {=latex}
wrapper (raw attribute), the above Latex commands will get interpreted as text in the final PDF. References:
Allow to center images without caption in Beamer · Issue #3995 · jgm/pandoc
Pandoc doesn't aim to be a layout engine, see http://pandoc.org/CONTRIBUTING.html#out-of-scope
However, you can change your LaTeX template or even write raw TeX (for both, see the MANUAL).
Raw LaTeX gets interpreted as text in a markdown document. · Issue #4646 · jgm/pandoc
For such complicated raw TeX you should probably use http://pandoc.org/MANUAL.html#extension-raw_attribute
Upvotes: 5
Reputation: 981
If you are using something such as pandoc-template that uses latex underneath, you can insert latex instructions, and they will be interprated.
\begin{center}
\includegraphics[]{./images/my_image.png}
\end{center}
Upvotes: 3
Reputation: 27
If you get the image to render as a figure, you can add styling to make it centered. There are two ways to make the image render as a figure:
Give it a caption:
![Caption](folder/img.png){ style="width: 70%; margin: auto;" }
For some reason, if you don't provide a caption, Pandoc won't create a figure. In that case you can do it manually:
<figure>![](folder/img.png){ style="width: 70%; margin: auto;" }</figure>
Upvotes: 1
Reputation: 424
For PDF output, using the implicit_figure option will automatically center image on page and allow you to display an title for images.
In the .md document:
![This is an image](path/to/image.png)
Run the following command to generate PDF from you .md
pandoc ./README.md \
-o ./README.pdf \
-f markdown+implicit_figures
Upvotes: 6