org-mode-ox-odt icon indicating copy to clipboard operation
org-mode-ox-odt copied to clipboard

Feature request: keep figure caption with the figure

Open QiangF opened this issue 3 years ago • 2 comments

By adjusting the lines between the two list table, you can always reach a point that the caption and the second figure is splited on two pages.

#+options:  toc:nil author:nil tex:t latex:t :H 10
#+caption: Org unicorn
#+attr_odt: :category "figure" :list-table t
-
  -
    #+attr_odt: :width 7.1
    [[./org-mode-unicorn.png]]

  -
    #+attr_odt: :width 7.1
    [[./org-mode-unicorn.png]]


Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.
#+caption: Org unicorn
#+attr_odt: :category "figure" :list-table t
-
  -
    #+attr_odt: :width 7.1
    [[./org-mode-unicorn.png]]

  -
    #+attr_odt: :width 7.1
    [[./org-mode-unicorn.png]]

img_2022_02_14__20_48_31

QiangF avatar Feb 14 '22 12:02 QiangF

The solution is here https://ask.libreoffice.org/t/keep-caption-with-table/55701

The caption is an ordinary text paragraph. Make sure there isn’t another paragraph between the caption and the table, and enable the TextFlow property Keep with next paragraph for the caption.

If you prefer to have the caption below the table (as I do) you need to enable the mentioned property for the table itself.

Where the text flow property goes depends on how the caption is positioned. So, I may have to choose different styles based on where the caption is positioned.

Simpler solution would be for you to roll your own caption style or table style, AFTER deciding whether you want to position your caption before or after.

Paragraph property to look for is fo:keep-with-next="always".

In your case, use this snippet, and remember to eval the babel block.

#+options:  toc:nil author:nil tex:t latex:t :H 10

# #+odt_extra_styles: <style:style style:name="Figure"
# #+odt_extra_styles:              style:parent-style-name="Caption"
# #+odt_extra_styles:              style:family="paragraph"
# #+odt_extra_styles:              style:class="extra"
# #+odt_extra_styles:              style:master-page-name="">
# #+odt_extra_styles:   <style:paragraph-properties fo:keep-with-next="always"
# #+odt_extra_styles:                               style:page-number="auto" />
# #+odt_extra_styles: </style:style>

#+begin_src emacs-lisp :exports results :results none
(setq org-odt-table-style-format
  "
<style:style style:name=\"%s\" style:family=\"table\" %s>
  <style:table-properties fo:margin-top=\"0cm\" fo:margin-bottom=\"0.20cm\" table:align=\"center\" %s fo:keep-with-next=\"always\"/>
</style:style>
"
  )
#+end_src


#+caption: Org unicorn
#+attr_odt: :category "figure" :list-table t
-
  -
    #+attr_odt: :width 7.1
    [[./org-mode-unicorn.png]]

  -
    #+attr_odt: :width 7.1
    [[./org-mode-unicorn.png]]


Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.

Line inserted to cause caption and figure seperation.
#+caption: Org unicorn
#+attr_odt: :category "figure" :list-table t
-
  -
    #+attr_odt: :width 7.1
    [[./org-mode-unicorn.png]]

  -
    #+attr_odt: :width 7.1
    [[./org-mode-unicorn.png]]


kjambunathan avatar Feb 15 '22 02:02 kjambunathan

That's indeed solves the issue. The ideal solution should be more flexibile: only subfigure captions need to be below the table, normal table shouldn't have keep with the next paragraph textflow property. Maybe add a keyword for it, like:

#+attr_odt: :category "figure" :list-table t :keep-with-next t

QiangF avatar Feb 16 '22 02:02 QiangF