How to typeset two columns with synchronized headings?

Probably somewhat related to another question but still kinda different.

I have a two column layout paper that I’d like to translate to another language. During the translation process I’d like to set up an intermediate representation where the left column would contain the original text, whereas the right one would contain my translation.

Since texts would quickly diverge due to different word lengths and phrase structures, I’d like to have a way to force header synchronization between the columns, so that layout engine would append vertical space to a shorter column so that the next headers in both columns would appear on the same horizontal line.

Here’s how it should look like:

I’ve simulated it using boxes with two columns inside.

Hi, I’ve updated your post’s title to a question as per our guidelines at How to post in the Questions category. Please keep this in mind in the future :slight_smile:

1 Like

This isn’t really possible without some manual intervention at the moment. I’d personally use a grid with two columns and 3 rows in your case:

#set page(width: 440pt, height: auto)
#grid(
  columns: (1fr, 1fr),
  row-gutter: 1em, 
  column-gutter: 3em,
  [= Header 1] + lorem(50), [= Header 1] + lorem(30),
  [= Header 2] + lorem(30), [= Header 2] + lorem(50),
  [= Header 3] + lorem(50), [= Header 3] + lorem(30),
)

Since there seems to be some intersection between your goal and grid typesetting (see discussion at Grid typesetting support · Issue #1306 · typst/typst · GitHub), you may also want to see if this package helps you: gridlock – Typst Universe

2 Likes

Hm… Isn’t it possible to enumerate headers and their corresponding content in both versions and then just do this programmatically?

Something needs to be done with duplicated media content and references though.

I am also interested in the same. For the time being, I am experimenting with the solution posted here: 📖 How to typeset two texts in parallel on pairs of facing pages? - #5 by sijo.

The headings are ‘synchronised’ insofar as you are using a grid for each element (heading, paragraphs, etc.). However, what I have not yet solved for is how to have the heading numbers synchronised when using automated numbering of headings.

1 Like

Enumerating headings is easy, but headings don’t “own” the content following them, so there is no built-in way in typst to divide a document into logical sections where each section would be a heading and its body of content.

It’s possible to do something like this with content introspection, but it can also be fragile and break if there are any styling commands (show rules) that span over multiple sections (and they start somewhere in the middle of the document, i.e they apply before your section-splitting algorithm can run)

Here’s an old experiment for document into section split: typst split document into sections.typ · GitHub This experiment comes with no warranty :slight_smile:

1 Like