Pandoc Markdown to PDF image position

你说的曾经没有我的故事 提交于 2020-05-08 06:29:58

问题


When converting a Markdown document to PDF with pandoc, my images are not placed in the same position I put them in the source code. I believe this is due to the conversion through LaTeX, but I'm not sure how to remedy this in the Markdown source.

If I use a placeholder image with several paragraphs of sample text and strategically place the image in the source, it becomes too big to fit on the page in the place where I've put it, so the LaTeX layout engine kindly places it on the next page. However, I'd rather this didn't happen because it means the image isn't where I expect and is harder to reference.

I can include an example if necessary, but it's trivial to reproduce and the source needs to be somewhat extensive to fill an entire page.


回答1:


Did you try to deactivate the implicit_figures as in

pandoc -f markdown-implicit_figures -t pdf myfile.md

To solve the size problem you could also try to fix the size within the markdown file with an attribute. Something like that can do the trick:

![Caption text](/path/to/image){ width=50% }



回答2:


Although Bruno's solution for forcing the figures into the specified position works, it also removes the captions specified in the .md file from the resulting .pdf.

To prevent the floating of figures but keep the captions:

1. Create a .tex file with the following content:

\usepackage{float}
\let\origfigure\figure
\let\endorigfigure\endfigure
\renewenvironment{figure}[1][2] {
    \expandafter\origfigure\expandafter[H]
} {
    \endorigfigure
}

This will prevent LaTeX from floating the figures.

2. Adapt the pandoc call

Assuming you have named the newly created .tex file disable_float.tex, just add the -H disable_float.tex to your pandoc call:

pandoc -H disable_float.tex input.md -o output.pdf

Props to this answer on SO and this comment on github.



来源:https://stackoverflow.com/questions/49482221/pandoc-markdown-to-pdf-image-position

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