Skip to content

Multi-column Float Elements (Figures, Tables, Code Blocks, etc.) #553

Closed

Description

@giannissc

Supersedes: #137.

I want to be able to break the column rules for figures and tables to the full size of the page and I want to be able to float these elements. I believe these two must be tackled together as you can see in the motivating examples

Activity

  1. added
    feature request
    layout
    on Apr 3, 2023
  2. changed the title [-][Feature Request] Multi-column Figure and Tables[/-] [+]Multi-column Figure and Tables[/+] on Apr 4, 2023
  3. giannissc commented on Apr 4, 2023

    @giannissc
    ContributorAuthor

    Currently elements cannot break away from their local scope. If columns is activated globally in the document, subsequent elements cannot break from their column parent to use the full width of the page.

    A separate issue is that if an element (e.g. image) doesn't fit into the remaining space it will move to the next page/column leaving a blank space behind it.

    These two issues, while separate, must be tackled together as there are complex interactions between them.

    To solve the first issue I propose that we introduce a scope argument to all the layout methods. Scope can either be global (relative to page) or local (relative to parent [existing behavior]).

    To solve the second issue I propose a new layout element #wrap or #float (no strong preference but for the rest of this post I will be using #wrap). #wrap is the counterpart to #place. Unlike place however, it can participate in the flow.

    The function signatures would be:

    • #place(scope, alignment, dx, dy, body)
    • #wrap(scope, [alignment], dx, dy, body)

    alignment:

    • No alignment - []:
    • Primary alignment - [alignment]:
    • Primary + Secondary alignments - [alignment, alignment, ...]
    • Secondary alignment - [, alignment, ...]
  4. giannissc commented on Apr 4, 2023

    @giannissc
    ContributorAuthor

    Algorithm for #wrap elements:

    1. Calculate #wrap element's dimensions and check if the element can fit to existing page/column (other #wrap elements might already populate the page)
    2. If it can, place #wrap element at correct position in current page/column based on its alignment policy. Relayout all other content (except other #wrap elements) in current page/column.
    3. If not, place #wrap element at correct position in the next page/column based on its alignment policy. Keep adding content to current page until it is filled.
  5. giannissc commented on Apr 4, 2023

    @giannissc
    ContributorAuthor

    In case 2 or more #wrap elements are placed in the same position in a page/column fallback arguments can be used to decide its position:

    • Repeated secondary alignment - [alignment1, alignment1]: place it to the next available spot (e.g. if 2 #wrap elements request the top position then place the first #wrap element at the top and the second #wrap below it.)
    • Alternate secondary alignment - [alignment1, alignment2]: Place the 2nd #wrap to the position indicated by alignment2. Assuming there are no more conflicts the content is laid out again in the available space. If there is another conflict move to the next page and repeat (alignment1 -> alignment2). For example if the first #wrap request the top position then the second can request in the fallback the bottom.
    • Only primary alignment - [alignment]: no fallback value is provided, move to the next page and repeat (alignment)
    • No primary alignment - []: no primary alignment value is provided, try to fit #wrap into existing page/column. Otherwise move to the top of next page/column. If there is a conflict move to an empty space below
    • Only secondary alignment - [, alignment]: Try to place to current page/column at current position. If it doesn't fit or there is some other conflict use secondary alignment. If there are more conflicts move to the top of next page and repeat
  6. giannissc commented on Apr 4, 2023

    @giannissc
    ContributorAuthor

    Does this seem reasonable? @laurmaedje, @reknih

    Also is this the best place to discuss or do you prefer discord?

    I am also willing to contribute code to get this out sooner! 🙂

  7. giannissc commented on Apr 5, 2023

    @giannissc
    ContributorAuthor

    Motivating Examples

    No wrap (existing behavior)

    Not allowing text to wrap around other elements can result in the following issue:
    Screenshot 2023-04-05 at 08-05-05 Test Paper (copy) – Typst

    No wrap,break column rules (global scope)

    Simple allowing content to break the column rules and layout based on page will also have the same issue:
    Screenshot 2023-04-05 at 08-20-18 Test Paper – Typst

    Wrap (local scope) - #wrap(scope: local, alignment: []) - Default

    Screenshot 2023-04-05 at 08-08-54 Test Paper (copy) – Typst

    Wrap (global scope) - #wrap(scope: global, alignment: [])

    Screenshot 2023-04-05 at 08-22-12 Test Paper – Typst

    Wrap (global scope) + Alignment(Centered) - #wrap(scope: global, alignment: [center+horizon])

    Screenshot 2023-04-05 at 08-34-00 Test Paper – Typst

    Wrap (global scope) + Conflict (Repeated) - #wrap(scope: global, alignment: [top, top])

    Screenshot 2023-04-05 at 08-35-25 Test Paper – Typst

    Wrap (global scope) + Conflict (Alternate) - #wrap(scope: global, alignment: [top, bottom])

    Screenshot 2023-04-05 at 08-37-54 Test Paper – Typst

  8. changed the title [-]Multi-column Figure and Tables[/-] [+]Multi-column Float Elements (Figures, Tables, Code Blocks, etc.)[/+] on Apr 5, 2023
  9. Andonome commented on Apr 5, 2023

    @Andonome

    This is great. In fact, it'd be ideal.

  10. giannissc commented on Apr 5, 2023

    @giannissc
    ContributorAuthor

    Do you think the primary and secondary alignments are both necessary? @Andonome

  11. eltos commented on Apr 5, 2023

    @eltos
    Contributor

    This is the most important missing feature to make typst as powerful as LaTeX.

  12. Andonome commented on Apr 5, 2023

    @Andonome

    Do you think the primary and secondary alignments are both necessary? @Andonome

    I wouldn't say 'necessary', but I've found a great deal of flexibility in having both 'top' and 'bottom' options.

    This page looks fine, as-is, but the two elements float apart when more text is added, which matches the general format of pictures-at-bottom, and tables-on-top.

    image

    I've not found tables in the centre work very often.

    Of course if anyone wants to get really fancy, automatic wrapping around a PNGs filled parts would be punk-as-all-heck.

  13. Andonome commented on Apr 5, 2023

    @Andonome

    This is the most important missing feature to make typst as powerful as LaTeX.

    LaTeX doesn't have this ability. There is no reliable text wrapping in a multicols environment. It's a big factor which stops it having reliable output - every compile, every page needs to be checked, images moved, et c.


    Edit: I see I've received some silent naysayers downvoting this comment.

    If anyone wants to put their code where their mouth is, check out my main project, and get any 3 images (of your choosing) to float, using any macro you please.

  14. giannissc commented on Apr 6, 2023

    @giannissc
    ContributorAuthor

    @Andonome I think is wrap is to be implemented it should be implemented with all these usecases in mind. Another usecase that comes to mind is that you have a central circular figure and that text should wrap around it as well. You examples are genuinely useful. Thanks!

  15. 32 remaining items

  16. andrewboldi commented on Jul 19, 2024

    @andrewboldi

    @laurmaedje Any progress on this feature request? :)

  17. RaulDurand commented on Jul 19, 2024

    @RaulDurand

    I believe that the lack of support for multi-column figures and tables is the main limitation to using Typst for writing manuscripts for scientific journals.

  18. kescobo commented on Jul 19, 2024

    @kescobo

    is the main limitation

    It depends on the field - almost nothing I submit to (in biology) uses multi-column layouts, but I need line numbers (happily that's being worked on #352 )

  19. DKierner commented on Jul 20, 2024

    @DKierner

    I believe that the lack of support for multi-column figures and tables is the main limitation to using Typst for writing manuscripts for scientific journals.

    Definitely true for informatics and computer sciences where the IEEE format is quite common. Some stuff is just to large to fit in a single half-page column meaningfullly.

  20. danaugrs commented on Jul 21, 2024

    @danaugrs

    I think the ideal solution, from a user's perspective, would involve adding a single parameter, tentatively called colspan, to non-breakable block elements, which would specify how many columns that element should span. Specifying a colspan of more columns than exist in the current context would result in an error. I think such a parameter, coupled with the existing usage of placement: "auto" | "top" | "bottom", would provide complete freedom to place multi-column blocks anywhere as desired.

  21. jounathaen commented on Jul 22, 2024

    @jounathaen

    I'm not a mod, but I think that there are now enough "This feature is stopping me from using Typst"/"This feature is missing for XYZ support" comments in this issue. The Devs are aware of this issue, and it is as-of-now the third most upvoted issue. So instead of adding more comments of the same, I'd suggest using the emoticons to express your support for this feature.
    (And the selfish remark: Then people that have subscribed to this issue will not get spammed with non-progress messages)

  22. NeutrinoLiu commented on Aug 29, 2024

    @NeutrinoLiu
    Screenshot 2024-08-29 at 12 58 01 AM

    in case anyone who is still waiting for the new feature, here is my bypass (i really like typst and would never go back to latex, so i have played with the problem for quite a while):
    add your figure to the first column and wrap it with a place function, so that it appears in the middle of two cols. Then at the top of second column, you place another empty rect, so that contents on the right side will align with left side.

    #place(
     top,
     dx: 105%,
     float: true,
     clearance: 0pt,
     figure(
       place(
         auto,
         dx: -40%,
         float: true,
         clearance: -8pt,
         figure(
           table(
             align: center,
             columns: (80pt, 80pt, 80pt, 80pt, 80pt),
             [Primitive], [Rendering Quality], [Rendering Speed], [Accessibility], [Storage],
             [3DGS @3dgs], [high], [high (>100fps)], [relatively easy], [middle],
             [NeRF @nerf], [high], [low (\<10fps)], [relatively easy], [low],
             [point cloud], [depends], [middle], [easy], [high],
             [mesh], [depends], [high], [poor], [middle]
           )
         ),
       ),
       caption: [Comparison between different 3D representation]
     ),
    )
    #lorem(500)
    #place(
     top,
     float: true,
     rect(height: 87pt, fill: none, stroke: none)
    )
    
    

    you might want to adjust the location of the second place and the rect height so that visually it looks like that the table spans two columns. a nested place is used here to shift caption and table by different percentage. Interesting thing that the figure could still recognize the place wrapped table and generate "Table 1" as caption correctly.


    i did not find a way to append a label in this case, so i simply type in "Table 1" whenever i refer it.

  23. spped2000 commented on Sep 19, 2024

    @spped2000
    #place(
      top,
      dx: 70%, 
      float: true, 
      clearance: 0pt,
      figure(
        place(
          auto,
          dx: 0%, 
          float: true, 
          clearance: 0pt,
          image("A2.png", width: 200%)
        ),
        caption: [Visualization of Zero-Shot, Few-Shot model.] // Centered under the image
      ),
    )
    #place(
      top,
      float: true,
      rect(height: 5pt, fill: none, stroke: none)
    )
    #lorem(500)
    #place(
      top,
      float: true,
      rect(height: 290pt, fill: none, stroke: none)
    )

    Screenshot 2024-09-19 103051

  24. a-stevan commented on Sep 23, 2024

    @a-stevan

    @NeutrinoLiu and @spped2000 👋

    so i've tried your examples and they did not work on my side...
    could you share a complete repro of your examples? that would be amazing

    my repro

    i have installed Typst today with

    cargo +1.77 install --git https://github.com/typst/typst --locked typst-cli

    and i get the following typst --version

    typst 0.11.0 (8c813cb7)
    

    my Typst source is a single file, called main.typ and which contains

    #show: rest => columns(2, rest)
    
    #place(
     top,
     dx: 105%,
     float: true,
     clearance: 0pt,
     figure(
       place(
         auto,
         dx: -40%,
         float: true,
         clearance: -8pt,
         figure(
           table(
             align: center,
             columns: (80pt, 80pt, 80pt, 80pt, 80pt),
             [Primitive], [Rendering Quality], [Rendering Speed], [Accessibility], [Storage],
             [3DGS 3dgs], [high], [high (>100fps)], [relatively easy], [middle],
             [NeRF nerf], [high], [low (\<10fps)], [relatively easy], [low],
             [point cloud], [depends], [middle], [easy], [high],
             [mesh], [depends], [high], [poor], [middle]
           )
         ),
       ),
       caption: [Comparison between different 3D representation]
     ),
    )
    #lorem(500)
    #place(
     top,
     float: true,
     rect(height: 87pt, fill: none, stroke: none)
    )

    then i compile this with

    typst compile main.typ main.pdf

    and here is what i get 😕
    Screenshot from 2024-09-23 14-09-50

  25. laurmaedje commented on Sep 24, 2024

    @laurmaedje
    Member

    Good news: #5017

  26. sschuldenzucker commented on Feb 11, 2025

    @sschuldenzucker

    Hey guys, I'm probably missing something but can I use the new layout engine to wrap text around figures? The wrap-it package says that it's only relevant as long as this issue isn't resolved. Since it is now, does this mean I can actually wrap text around figures? (and how?) Or is it still not possible and the package documentation should be updated?

  27. laurmaedje commented on Feb 11, 2025

    @laurmaedje
    Member

    @sschuldenzucker Text wrapping around figures at the side was not part of the 0.12 work on floating placement. This subfeature was also proposed in this issue, but it was too large of an issue to be actionable. Side-wrapping is now tracked by #5181.

  28. AstroAure commented on Nov 6, 2025

    @AstroAure

    Hello !
    I'm re-opening this discussion since I can't manage to place my figures the ways I would like. Basically, I want my figures to behave like Wrap (local scope) shown above.
    With the placement option, this leads to the following logic:

    • If the figure has the space to stay on the same page/column: use placement: none
    Image
    • If the figure is pushed to a new page because it doesn't have enough space: use placement: top
    Image

    This ensures that the image is placed at the correct spot in the text if it it has the space for it, and otherwise gets placed at the top of the very next page/column, while continuing the text before to not leave blank space.
    Is there a way to achieve this behavior in the current version of Typst ? Otherwise, would this be possible to add in future versions ?
    Thank you !

  29. kescobo commented on Nov 6, 2025

    @kescobo

    @AstroAure I don't think it makes sense to extend this old issue since the discussion has moved on. If you think this may be a bug in the implementation from v0.12, you can open a new issue (or better yet hop on discord and ask for help in case there's a good solution), or if it's relevant to #5181 you could comment there.

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 requestlayout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions