Skip to content

Short figure caption for outline #1295

Open

Description

@mareikep

Description

Allow adding an optional short caption to be displayed in the outline

Use Case

When adding a caption to a figure, the text might be quite long, in particular, when the figure contains a table or (multiple) images that require explanation. The entire caption text is automatically added to the outline, which may look really messy, depending on the text length.
In the caption package of LaTeX, one can add an argument <list entry> (kind of a short caption), that shows up in the outline instead of the <heading> (i.e. the actual caption), if given: \caption[⟨list entry⟩]{⟨heading⟩}. If no <list entry> is given, the <heading> is shown in the outline (as is happening now in typst) and if it is given, but left empty ( \caption[]{⟨heading⟩}) , no entry will be made in the outline.

Activity

  1. added
    feature request
    on May 23, 2023
  2. kamasylvia commented on Aug 25, 2023

    @kamasylvia

    I propose changing the heading.outlined type from boolean to string/none. This modification will enable the Table of Contents (ToC) to display a specified string if it is not set to none.

  3. NicolasHaeffner commented on Sep 29, 2023

    @NicolasHaeffner

    But then, if it is none is it not showing or is it using the long caption?

  4. laurmaedje commented on Sep 29, 2023

    @laurmaedje
    Member

    See also: #1892 (comment)

  5. yrd commented on Oct 12, 2023

    @yrd

    Here's an idea for a workaround while this isn't implemented yet:

    #let outlined-figure(
    	contents,
    	label-name,
    	placement: auto,
    	caption: none,
    	outline-caption: none,
    ) = [
    	#if outline-caption != none [
    		#show figure: it => it.counter.update(v => v - 1)
    		#figure(contents, caption: outline-caption)
    	]
    	#figure(
    		contents,
    		placement: placement,
    		caption: caption,
    		outlined: outline-caption == none,
    	) #label(label-name)
    ]

    Seems to work and produce the desired result (as far as I can tell).

  6. added
    model
    and removed on Nov 24, 2023
  7. bguo068 commented on Dec 13, 2023

    @bguo068

    Here's an idea for a workaround while this isn't implemented yet:

    #let outlined-figure(
    	contents,
    	label-name,
    	placement: auto,
    	caption: none,
    	outline-caption: none,
    ) = [
    	#if outline-caption != none [
    		#show figure: it => it.counter.update(v => v - 1)
    		#figure(contents, caption: outline-caption)
    	]
    	#figure(
    		contents,
    		placement: placement,
    		caption: caption,
    		outlined: outline-caption == none,
    	) #label(label-name)
    ]

    Seems to work and produce the desired result (as far as I can tell).

    This works for me. Thank you!!

  8. laurmaedje commented on Dec 13, 2023

    @laurmaedje
    Member

    Here is another solution that is maybe a little bit less cursed:

    #let in-outline = state("in-outline", false)
    #show outline: it => {
      in-outline.update(true)
      it
      in-outline.update(false)
    }
    
    #let flex-caption(long, short) = locate(loc => 
      if in-outline.at(loc) { short } else { long }
    )

    Which can then be used like this:

    #outline(title: [Figures], target: figure)
    
    #figure(
      rect(),
      caption: flex-caption(
        [This is my long caption text in the document.],
        [This is short],
      )
    )
  9. bguo068 commented on Dec 14, 2023

    @bguo068

    Here is another solution that is maybe a little bit less cursed:

    #let in-outline = state("in-outline", false)
    #show outline: it => {
      in-outline.update(true)
      it
      in-outline.update(false)
    }
    
    #let flex-caption(long, short) = locate(loc => 
      if in-outline.at(loc) { short } else { long }
    )

    Which can then be used like this:

    #outline(title: [Figures], target: figure)
    
    #figure(
      rect(),
      caption: flex-caption(
        [This is my long caption text in the document.],
        [This is short],
      )
    )

    Working nicely 😄 . Also works for headings:

    #heading(level:1, flex-caption(
      [ a ver long title a ver long title a ver long title  ], 
      [my short one])
    )

    Thank you so much!!

  10. mst2k commented on Feb 25, 2024

    @mst2k

    Here is another solution that is maybe a little bit less cursed:

    #let in-outline = state("in-outline", false)
    #show outline: it => {
      in-outline.update(true)
      it
      in-outline.update(false)
    }
    
    #let flex-caption(long, short) = locate(loc => 
      if in-outline.at(loc) { short } else { long }
    )

    Which can then be used like this:

    #outline(title: [Figures], target: figure)
    
    #figure(
      rect(),
      caption: flex-caption(
        [This is my long caption text in the document.],
        [This is short],
      )
    )

    For future reference - this can (obviously) also be used to omit citations inside figure outlines.

    #outline(title: [Figures], target: figure)
    
    #figure(
      rect(),
      caption: flex-caption(
        [Some figure showing x @somesource], //Display caption including citation
        [Some figure showing  x], //Caption without citation used in the outline
      )
    )
  11. yichechang commented on Mar 30, 2024

    @yichechang

    Hi all — I'm new to Typst, so if I should check out some more documentation on my own, please don't hesitate to tell me "just read [XYZ]"!

    But I was curious if the new "context" introduced in 0.11.0 will be able to improve the current workaround? I tend to think it can, but I am not entirely sure how. Any advice?

  12. andreasKroepelin commented on Apr 30, 2024

    @andreasKroepelin

    But I was curious if the new "context" introduced in 0.11.0 will be able to improve the current workaround?

    Yes, it would now look like this:

    #let flex-caption(long, short) = context if in-outline.get() { short } else { long }
  13. AhmedSalih3d commented on Nov 12, 2024

    @AhmedSalih3d

    But I was curious if the new "context" introduced in 0.11.0 will be able to improve the current workaround?

    Yes, it would now look like this:

    #let flex-caption(long, short) = context if in-outline.get() { short } else { long }

    You saved my day in my step of trying to migrate a document from LaTeX to Typst, as a learning experience. I was quite bummed out, thinking that it was not possible at all - hopefully this is integrated into the figure environment in some way in the future

    Kind regards

  14. q-wertz commented on Mar 24, 2025

    @q-wertz

    As it took me quite a white to get it up and running (in a multi file document) here a full example derived from the solution of @andreasKroepelin

    In your main file add

    #let in-outline = state("in-outline", false)
    #show outline: it => {
      in-outline.update(true)
      it
      in-outline.update(false)
    }
    
    // [...]
    // e.g. #show: my-theme.with(...) and/or outline(title: "List of figures", target: figure.where(kind: image))
    
    #include "chapters/test.typ"

    before any usage of outline() (e.g. of your theme). If I changed the order I got the same caption version in the outline and below the figure.

    In an extra file (misc_functions.typ in my case) add the function definition (I changed it to have named arguments because I always mix up short and long version 😅 ):

    #let flex-caption(short: none, long: none) = context if state("in-outline", false).get() {
      short
    } else { long }
    
    // [...]

    When you want to use flex-caption in file chapters/test.typ:

    #import "../misc_functions.typ": *
    
    // [...]
    
    #figure(
      "My awesome figure",
      caption: flex-caption(
        short: [Short caption appearing in outline.],
        long: [Long caption appearing in document body],
      ),
    ) <fig:example>

    Let me know if I just misunderstood some typst basics and the whole thing also works in an easier way 😅

    EDIT:
    Removed unnecessary line in main file. Thx for noticing @jasperlig

  15. jasperlig commented on Sep 13, 2025

    @jasperlig

    As it took me quite a white to get it up and running (in a multi file document) here a full example derived from the solution of @andreasKroepelin

    In your main file add

    #let in-outline = state("in-outline", false)
    #show outline: it => {
      in-outline.update(true)
      it
      in-outline.update(false)
    }
    #let flex-caption(short, long) = context if in-outline.get() { short } else { long }
    
    // [...]
    // e.g. #show: my-theme.with(...) and/or outline(title: "List of figures", target: figure.where(kind: image))
    
    #include "chapters/test.typ"

    before any usage of outline() (e.g. of your theme). If I changed the order I got the same caption version in the outline and below the figure.

    In an extra file (misc_functions.typ in my case) add the function definition (I changed it to have named arguments because I always mix up short and long version 😅 ):

    #let flex-caption(short: none, long: none) = context if state("in-outline", false).get() {
      short
    } else { long }
    
    // [...]

    When you want to use flex-caption in file chapters/test.typ:

    #import "../misc_functions.typ": *
    
    // [...]
    
    #figure(
      "My awesome figure",
      caption: flex-caption(
        short: [Short caption appearing in outline.],
        long: [Long caption appearing in document body],
      ),
    ) <fig:example>

    Let me know if I just misunderstood some typst basics and the whole thing also works in an easier way 😅

    It seem like the #let flex-caption(short, long) = context if in-outline.get() { short } else { long } in the main file is not beeing used and therefore should be removed.

  16. nmaggioni commented on Sep 13, 2025

    @nmaggioni

    When using this approach I am getting a warning at compile time:

    warning: layout did not converge within 5 attempts
    

    Wrapping the short text in a block() as suggested here gets rid of the warning, but messes up the outline (as expectable). Weirdly enough, commenting other parts of the main text seems to randomly trigger or solve this warning. Any clues on how to bisect this properly?

  17. q-wertz commented on Sep 14, 2025

    @q-wertz

    It seem like the #let flex-caption(short, long) = context if in-outline.get() { short } else { long } in the main file is not beeing used and therefore should be removed.

    Thx @jasperlig for noticing. Updated the comment.

    When using this approach I am getting a warning at compile time

    @nmaggioni never had a problem with that due to this code. Do you have a clean code or other packages/function/... in use? Or can you give a MWE?

    My last converge problem was due to the usage of the drafting package and two margin notes close to each other.

  18. nmaggioni commented on Sep 18, 2025

    @nmaggioni

    @q-wertz You're most probably right: I can't reproduce the issue in a MWE and it seems to have gone away by itself anyway, so it was likely caused by a conflict elsewhere. I am indeed using the drafting package :)

  19. bgmeulem commented on Jan 30, 2026

    @bgmeulem

    While having explicit control over the short and long title has already been answered, I'd like to highlight the option of simply shortening the title to the first sentence by default, by splitting it on the first fullstop. For example:

    #show outline.entry: it => {
      (
        text(weight: "bold", [Figure #it.element.numbering:]),   // some markup to look nice
        it.element.caption.body.text.split(".").at(0) + ".",     // only show first sentence as "short title"
        box(width: 1fr, repeat[.]),                              // fill with dots, if you want
        it.page()                                                // page number
      ).join(" ")
    }

    This way, you don't need custom functions, or importing these in every document that has a figure. You only need to define this once for the figure outline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestmodel

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions