3

I'd like to use subfigures in org-mode files. In MS Word, this could be easily done by inserting the subfigures of a figure into a table with invisible borders. Then the size of each subfigure can be adjusted as you like.

Is there a way to use subfigures like this in Org-mode?

I tried to set size with e.g. #+ATTR_ORG: :width 400, and it only works on a single figure.

So, this works with the intended figure size:

#+CAPTION: Test Figure 
#+NAME: fig:test0
#+ATTR_ORG: :width 400
[[file:build/test.png]]

But when put into a table, the specified figure size (width) is ignored. (And the actual size of the sub-figure is used, which is way too large).

#+CAPTION: Test Figure 
#+NAME: fig:test
#+ATTR_ORG: :width 400
| [[file:build/test.png]] | [[file:build/test.png]] |

I have (setq org-image-actual-width nil) in my init.el. And this is under Emacs 26, Ubuntu 20.04, and Org mode version 9.3.7 (9.3.7-8-g3ed035-elpaplus). I am interested in exporting the org file to multiple targets including ODT. (So, I am looking for a generic solution.)

If the above usage is wrong, what is the correct usage to get properly sized subfigures?

-- Update --

This blog about extending org link syntax seems relevant. I guess I am looking for an extended way of specifying the image size as part of the link, with something like this:

[[file:build/test.png :width 300]]

as in

#+CAPTION: Test Figure 
#+NAME: fig:test
| [[file:build/test.png :width 300]] | [[file:build/test.png :width 300]] |

Is this doable in org?

1
  • I don't think there is any facility in Org mode to do that for every export backend. You can probably do it for LaTeX/PDF and HTML with a back-end-specific macro, but it is not going to be simple or pretty.
    – NickD
    Commented Aug 18, 2020 at 13:11

2 Answers 2

1

If you can live without captions on subfigures this seem to work:

#+CAPTION: Two subfigures
#+NAME:   fig:twofigures
\begin{figure}
     \centering
     \begin{subfigure}
    \centering
        \includegraphics[width=0.47\textwidth]{image}
     \end{subfigure}
     \begin{subfigure}
    \centering
        \includegraphics[width=0.47\textwidth]{image}
     \end{subfigure}
\end{figure}

Reference to Figure [[fig:twofigures]].
1
  • This only works for the LaTeX export backend in case that isn't obvious. Do note that you can have captions on the subfigures by using the LaTeX caption command, just as you would if you were writing LaTeX rather than org mode. Also note that this requires #+latex_header: \usepackage{subcaption} in the header. Commented Sep 29, 2021 at 7:31
1

In case this is still relevant at all, there is this post describing a possible implementation using a new link type.

I think a preferable implementation for latex would use the subcaption environment like...

(org-link-set-parameters
 "subfig"
 :follow (lambda (file) (find-file file))
 ;; :face '(:foreground "white" :weight bold :underline t)
 :display 'full
 :export
 (lambda (file desc backend)
   (when (eq backend 'latex)
     (if (string-match ">(\\(.+\\))" desc)
         (concat
          "\\subcaptionbox{" (replace-regexp-in-string "\s+>(.+)" "" desc) "}"
          "{\\includegraphics" "[" (match-string 1 desc) "]" "{" file "}}\n\\quad\n")
       (format "\\begin{subfigure}\\includegraphics{%s}\\end{subfigure}" desc file)))))

I am not sure about HTML. Also, this runs into issues if you have org-export-preserve-breaks t

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.