16

I need to solve a recent problem placing images side by side in the center of a PDF that is generated by org-mode via LaTeX.

I recently opened some .org-files from a year ago and tried to generate new PDFs from them. There have been significant updates to emacs, org-mode, and the relevant LaTeX packages I use, so some parts of the source had to be changed. Mostly, everything is working now except for generating PDFs with centered, side by side images.

Here is what used to work:

#+BEGIN_center
#+ATTR_LaTeX: :height 0.2\textwidth
[[image1.png]]
#+ATTR_LaTeX: :height 0.2\textwidth
[[image2.png]]
#+END_center

I am currently using emacs 26.0.50, orgmode 9.0.3, with TeX Live 2016 on Debian and the example above results in images that are stacked on top of each other. When I examine the TeX source, this is the result:

\begin{center}
\begin{center}
\includegraphics[height=0.2\textwidth]{image1.png}
\end{center}
\begin{center}
\includegraphics[height=0.2\textwidth]{image2.png}
\end{center}
\end{center}

I assume this is related to recent change in org-mode where images are centered by default. However, the following change to the org source does not solve the problem.

#+ATTR_LaTeX: :height 0.2\textwidth
[[image1.png]]
#+ATTR_LaTeX: :height 0.2\textwidth
[[image2.png]]

The images are still stacked on top of each other (although the outer "\center" calls are no longer present in resulting tex source):

\begin{center}
\includegraphics[height=0.2\textwidth]{image1.png}
\end{center}
\begin{center}
\includegraphics[height=0.2\textwidth]{image2.png}
\end{center}

I am able to get the images side by side if I disable org-mode's automatic centering:

#+ATTR_LaTeX: :height 0.2\textwidth :center
[[image1.png]]
#+ATTR_LaTeX: :height 0.2\textwidth :center
[[image2.png]]

But how can I get side by side images centered? Perhaps the answer is very simple and obvious, but I have tried many other changes and been unable to accomplish this.

1 Answer 1

22

After trying a few more things, I managed to solve it myself:

#+BEGIN_center
#+ATTR_LaTeX: :height 0.2\textwidth :center
[[image1.png]]
#+ATTR_LaTeX: :height 0.2\textwidth :center
[[image2.png]]
#+END_center

Leave the #+ _center keywords that surround the images to be centered, but then disable org-mode's new automatic centering by adding :center for each image. This also means there is no need to remove existing markup.

Resulting LaTex output looks as it should:

\begin{center}
\includegraphics[height=0.2\textwidth]{image1.png}
\includegraphics[height=0.2\textwidth]{image2.png}
\end{center}

If anyone has a simpler or more elegant solution than adding :center to each instance, please post. Until then, the solution above at least works.

3
  • +1 (but it would be even better if you posted the resulting LaTeX output).
    – jon
    Jan 13, 2017 at 3:54
  • 2
    @jon Updated answer to include it
    – noob
    Jan 14, 2017 at 13:59
  • 6
    How about using this with captions?
    – serv-inc
    Nov 7, 2018 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .