Open m4ttsch opened 4 years ago
@m4ttsch
\begin{center} %your image or figure here \end{center}
Yes thank you, a quick google search answered that question for me. Where should I put that in this file? https://github.com/Wandmalfarbe/pandoc-latex-template/blob/master/eisvogel.tex
@m4ttsch I'll let you know when I submit my pull-request
@m4ttsch the file you referenced is very busy. Your stating commands which are typically left in the preamble very far into the document. You might do better to make a separate sty and/or cls file(s) to make your code more manageable. Your reference to figures seems limited to whether or not your employing the float [H] to place the figure, but nothing more. perhaps an environment could be used to handle your float and centering of figures. The code strikes me as unorthodox, so I'd probably make major changes to your project that you may not feel comfortable with.
This ... is not my project. I didn't write this template. I'm using it to format some of my own markdown and I was hoping that someone (the author, most likely) could point me in a direction that could help me center images in my outputted PDF file.
@m4ttsch Please share your repository or code so I can be of assistance.
you could try https://tex.stackexchange.com/questions/262380/how-to-automatically-center-images, i.e. you would need to redefine the \includegraphics
command which is generated by the latex writer in pandoc.
you could put the lines in a center.tex
file and add it using -H center.tex
...
you also could add a class to your markdown image like ![](myimage.png){.center}
and add the proposed \begin{center}
and \end{center}
for all images with class center
using a simple lua filter ...
This solution works for me:
https://stackoverflow.com/questions/24677642/centering-image-and-text-in-r-markdown-for-a-pdf-report
The simple solution given by Jonathan works with a modification to cheat Pandoc. Instead of direct Latex commands such as
\begin{center}
Text
\end{center}
you can define your own commands in the YAML header:
header-includes:
- \newcommand{\bcenter}{\begin{center}}
- \newcommand{\ecenter}{\end{center}}
And then you use:
\bcenter
Text and more
\ecenter
This works for me for centering a whole document with many code chunks and markdown commands in between.
It's also possible to center all images with lua filter script.
-- center-images.lua
function Image (elem)
-- Surround all images with image-centering raw LaTeX.
return {
pandoc.RawInline('latex', '\\hfill\\break{\\centering'),
elem,
pandoc.RawInline('latex', '\\par}')
}
end
pandoc src/*.md -o paper.pdf --lua-filter=center-images.lua
Currently, my images stretch horizontally to fill the page. This is too large, so I rescaled the images by 50%. Unfortunately, when they get burned into the PDF, they are left-aligned. What can I edit in the template to center-align images? I am quite new to Latex.