Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove `\centering` tag from a figure block in LaTeX generated from pandoc?

When generating a PDF from markdown using pandoc, the markdown is converted into LaTeX. I am using a customized template to style my PDF.

When I create an image link:

![Alt text](image.png)

the following LaTeX is generated.

\begin{figure}[htbp]
\centering
\includegraphics{image.png}
\caption{Alt text}
\end{figure}

The image is, not surprisingly, centered on the PDF.

How do I prevent the \centering tag from being generated?

like image 651
w8s Avatar asked Nov 29 '25 02:11

w8s


1 Answers

Probably you can't, but if your document does not use \centering for any other purpose, you can redefine it at as "void" (\relax) before it is used. You can do this in several ways:

  • Include the line \def\centering{\relax} at the beginning of your pandoc document. Pandoc passes all latex code "as is" to the resulting .tex file.
  • Modify your latex template and include the definition of \centering at the appropiate point (for example, just before \begin{document}
  • If you are using pandoc's standard template, you can still insert code into it at compile-time, using pandoc's --variable option to define the variable header-includes. For example:

    pandoc -s --variable:header-includes="\\def\\centering{\\relax}" yourdoc.markdown -o yourdoc.tex
    
like image 159
JLDiaz Avatar answered Dec 02 '25 04:12

JLDiaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!