Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image centering with pandoc markdown

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.

like image 493
user2023370 Avatar asked Feb 15 '19 00:02

user2023370


People also ask

How do I center an image in RMD?

To center an image using the knitr::include_graphics() function, include it within an R code chunk that has the fig. align='center' option (and perhaps other options to control width, etc.). For example: Be sure to include the echo = FALSE chunk option to prevent the chunk source code from being printed.

Can Pandoc convert HTML to markdown?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.

What is Pandoc R?

pander: An R 'Pandoc' WriterContains some functions catching all messages, 'stdout' and other useful information while evaluating R code and other helpers to return user specified text elements (like: header, paragraph, table, image, lists etc.)

Where are Pandoc templates?

The default LaTeX template of Pandoc can be found at https://github.com/jgm/pandoc/tree/master/data/templates (named default. latex ).


2 Answers

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
like image 75
MCO System Avatar answered Sep 19 '22 12:09

MCO System


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:

  1. Give it a caption:

    ![Caption](folder/img.png){ style="width: 70%; margin: auto;" }

  2. 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>

like image 35
Warren Alphonso Avatar answered Sep 21 '22 12:09

Warren Alphonso