Menu

#81 \captionbelowof not working

With captions=figureheading, the command \captionbelowof doesn't set the correct space for a below caption, as expected.

Example:

\documentclass{scrartcl}

\begin{document}

\KOMAoptions{captions=figureheading}

\noindent \dotfill BEFORE \dotfill
\captionbelowof{figure}{Caption below}
\noindent \dotfill AFTER \dotfill

\end{document}

This can be fixed with

\renewcommand*{\captionaboveof}[1]{\def\@captype{#1}%
  \@captionabovetrue%
  \scr@caption}
\renewcommand*{\captionbelowof}[1]{\def\@captype{#1}%
  \@captionabovefalse%
  \scr@caption}

In attachment, a more detailed test.

1 Attachments

Discussion

  • Markus Kohm

    Markus Kohm - 2025-06-04
    • labels: --> scrartcl, scrbook, scrreprt, \captionof, \captionbelowof, \captionaboveof, \caption, \captionbelow, \captionabove, bug
    • status: open --> accepted
    • assigned_to: Markus Kohm
    • Milestone: KOMA-Script 3.44 --> KOMA-Script 3.46
     
  • Markus Kohm

    Markus Kohm - 2025-06-04

    Sorry, but it is even more generally wrong, because a previous \captionaboveof or \captionbelowof can influence a following \captionof. This either has to be documented or (and this would IMHO be better) should be changed.

    And I should also check \caption, \captionabove and \captionbelow for similar issues.

    So I need some more time to change it.

     
  • Markus Kohm

    Markus Kohm - 2025-06-05

    BTW: Your attachment is extremely helpful as a basis for intensive testing not only of the current mistake, but also of possible solutions. I just have to extend it with the mentioned cases with \captionof to \caption(below|above)of and the same without of. Many thanks for that!

     

    Last edit: Markus Kohm 2025-06-05
  • Markus Kohm

    Markus Kohm - 2025-06-05

    I think, the correct fix of \captionof, \captionaboveof, \captionbelowof would be:

    \makeatletter
    \let\if@figurecaptionabove\relax
    \let\if@tablecaptionabove\relax
    \ExplSyntaxOn
    \tl_new:N \l__koma_after_caption_code_tl
    \cs_new:Npn \koma__after_caption:
      {
        \tl_set:Ne \l__koma_after_caption_code_tl
          {
            \cs_if_exist:NTF \@captype
              { \exp_not:n { \cs_set:Npn \@captype } { \@captype } }
              { \exp_not:n { \cs_set_eq:NN \@captype \relax } }
              \if@captionabove \exp_not:N \@captionabovetrue
              \else \exp_not:N \@captionabovefalse \fi
          }
        \tl_show:N \l__koma_after_caption_code_tl
      }
    \RenewDocumentCommand{\captionof} {m +O{#3} +m}
      {
        \koma__after_caption:
        \cs_set:Npe \@captype {#1}
        \cs_if_eq:ccTF { if@#1captionabove } { iftrue }
          {
            \@captionabovetrue
          }
          {
            \cs_if_eq:ccT { if@#1captionabove } { iffalse }
              { \@captionabovefalse }
          }
        \scr@caption[{#2}]{#3}%
        \tl_use:N \l__koma_after_caption_code_tl
      }
    \RenewDocumentCommand{\captionaboveof} {m +O{#3} +m}
      {
        \koma__after_caption:
        \cs_set:Npe \@captype {#1}
        \@captionabovetrue
        \scr@caption[{#2}]{#3}%
        \tl_use:N \l__koma_after_caption_code_tl
      }
    \RenewDocumentCommand{\captionbelowof} {m +O{#3} +m}
      {
        \koma__after_caption:
        \cs_set:Npe \@captype {#1}
        \@captionabovefalse
        \scr@caption[{#2}]{#3}%
        \tl_use:N \l__koma_after_caption_code_tl
      }
    \ExplSyntaxOff
    \makeatother
    

    And I should also implement options captions=figuredefault and captions=tabledefault, which would set \if@figurecaptionabove resp. \if@tablecaptionabove to \relax and therefore use the setting of captions=above resp. captions=below. But I still need to test, what happens when using package caption with the change. And I need to inspect \caption, \captionabove and \captionbelow.

     
  • Markus Kohm

    Markus Kohm - 2025-06-05

    Unfortunately, compatibility with package caption is indeed a problem. For example, the package relies on the fact that if \@figurecaptionabovetrue exists, \if@figurecaptionabovetrue is either \iftrue or \iffalse. It also changes \@figurecaptionabovetrue, \@figurecaptionabovefalse, \@captionabovetrue and \@captionabovefalse in a way that makes it difficult for me to implement the desired changes. I will therefore probably undo the changes I have just spent hours implementing and start all over again next week. A few things in caption are also still unclear to me, for example whether both a \captionsetup*[figure]{position=t} (via \@figurecaptionabovetrue) and a \caption@setposition{t} (via \@captionabovetrue) are really needed. The latter may be sufficient. The package really intervenes very deeply and in detail in internal functions of KOMA-Script.

     
  • Markus Kohm

    Markus Kohm - 2025-06-05
    • status: accepted --> open
     
  • Julien Labbé

    Julien Labbé - 2025-06-06

    You could maybe set the flags locally (inside groups)

    %% captionof
    \RenewDocumentCommand{\captionof} { m +O{#3} +m }
      {
        \group_begin:
        \cs_set:Npe \@captype {#1}
        \cs_set_eq:cc { if@captionabove } { if@#1captionabove }
        \scr@caption[{#2}]{#3}%
        \group_end:
      }
    %% captionof above/below
    \RenewDocumentCommand{\captionaboveof} { m +O{#3} +m }
      {
        \group_begin:
        \use:c { @#1captionabovetrue }
        \captionof { #1 } [ #2 ] { #3 }
        \group_end:
      }
    \RenewDocumentCommand{\captionbelowof} { m +O{#3} +m }
      {
        \group_begin:
        \use:c { @#1captionabovefalse }
        \captionof { #1 } [ #2 ] { #3 }
        \group_end:
      }
    %% caption above/below
    \RenewDocumentCommand{\captionabove} { +O{#2} +m }
      {
        \group_begin:
        \use:c { @captionabovetrue }
        \scr@caption [ #1 ] { #2 }
        \group_end:
      }
    \RenewDocumentCommand{\captionbelow} { +O{#2} +m }
      {
        \group_begin:
        \use:c { @captionabovefalse }
        \scr@caption [ #1 ] { #2 }
        \group_end:
      }
    

    In attachment the test file, rewritten and simplified.

     
  • Markus Kohm

    Markus Kohm - 2025-06-13

    The new code of [r4174], [r4175], [r4176] should not only fix this issue. It is also intended to improve compatibility of KOMA-Script and package caption and makes \captionabove, \captionbelow, \captionof, \captionaboveof, \captionbelowof available with the standard classes + package tocbasic. The position formatting of \caption and \captionof can be setup using tocbasic (preamble) option enablepatch=caption together with tocbasic (general) options: captionabove, captionbelow, captionposition=top, captionposition=bottom (the default), figurecaptionabove, figurecaptionbelow, figurecaptionposition=bottom, figurecaptionposition=top, figurecaptionposition=default (the default), tablecaptionabove, tablecaptionbelow, tablecaptionposition=top, tablecaptionposition=bottom, tablecaptionposition=default (the default). Additional options for environments defined using \DeclareNewTOC are automatically added and can be used after the declaration of the environments using \SetKeys[tocbasic}{…}.

    Note: There is still one issue in cooperation with package caption. But this is should be solved in captioncaption-koma.sto should be updated for KOMA-Script v3.46 and later.

     

    Related

    Commit: [r4174]
    Commit: [r4175]
    Commit: [r4176]


    Last edit: Markus Kohm 2025-06-20
    • Markus Kohm

      Markus Kohm - 2025-06-20

      Unfortunately Axel has announced that he will discontinue support for the caption package and all his packages from the related collection. The collection will thus go into “unmaintained” status. Since caption is IMHO an important package, this means additional work for me, because I now have to make sure that caption3 no longer loads caption-koma.sto and instead relevant parts of it go directly into KOMA-Script or are rebuilt. This sets the next release back even further and sets me back quite a bit in my overall plans.

      I now have two open, very urgent tasks that I am working on simultaneously, in addition to the ongoing task of maintaining and improving compatibility with new LaTeX releases (including the creation of tagging support).

       
  • Markus Kohm

    Markus Kohm - 2025-06-25
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.