Pandoc Markdown to PDF image position

后端 未结 2 1642
时光取名叫无心
时光取名叫无心 2021-01-03 21:23

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

2条回答
  •  执笔经年
    2021-01-03 21:49

    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.

提交回复
热议问题