How do I make a reference to a figure in markdown using pandoc?

喜欢而已 提交于 2019-11-28 15:13:06

In pandoc you can even do:

![This is the caption\label{mylabel}](/url/of/image.png)
See figure \ref{mylabel}.

I've had a chat with Ryan Gray after reading his answer in a similar post. Actually his solution of using :

[image]: image.png "Image Title" 
![Alt text][image] 
A reference to the [image](#image).

is only adapted when using multimarkdown.

When it comes to pandoc, the only solution to make cross references is using directly latex keywords:

[image]: image.png "Image Title"
![Alt text \label{mylabel}][image]
See figure \ref{mylabel}.

You can use the pandoc-fignos filter for figure numbering and referencing. It works with any output format -- not just LaTeX.

Add a label to the image's attributes like this:

 ![Caption.](image.png) {#fig:description}

... and then reference the figure like this:

 @fig:description

Information on how to install and apply the pandoc-fignos filter is given on its Web page. There is also the pandoc-eqnos filter for doing the same kind of thing with equations.

ivotron

Pandoc supports referencing sections (via section identifiers prefixed by #).

Comments on this open issue describe how the following workaround leverages section identifiers for generating image references in LaTeX and HTML:

<div id="fig:lalune">
![A voyage to the moon\label{fig:lalune}](lalune.jpg)

</div>

[The voyage to the moon](#fig:lalune).

The empty line before </div> is required.

Assuming that you want PDF output of Pandoc at the end:

The best solution for inserting images and changing their attributes I found is:

\begin{figure}[H]
\includegraphics[width=0.25\textwidth, height=!]{images/path.png}
\centering
\caption{mycaption}
\end{figure}

and in my template.latex I have:

\usepackage{wrapfig}
\usepackage{float}

Other solutions cannot specify the image width or height, at least not in standard markdown. However it is often essential for something like a book or a paper to specify the dimensions of figures, except you want to configure output size of images before using them in your document. In that case you'd have to deal with different settings for those tools you use to create the images.

I recommend in case of Matplotlib to export to PDF and then use the code I posted. This will give the best image quality and highest flexibility in configuring what the image will look like in the output PDF, without having to worry about stuff.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!