How could I draw lines and write text along sections and subsections in the margin?

Hello,

I would like the draw lines along my sections in my document in the margin and add text/label to them. I’ve tried something using blocks to show what I would like to have, but it seems a bit hacky and I don’t see how to add text to it until now.

#block(stroke: (left: black), outset: (left: 10mm, rest: 0mm))[
  = Section<test_section>

  #block(stroke: (left: black), outset: (left: 5mm, rest: 0mm))[
    == subsection
    #lorem(100)
  ]
]

#block(stroke: (left: black), outset: (left: 10mm, rest: 0mm))[
  = Section<test_section>

  #block(stroke: (left: black), outset: (left: 5mm, rest: 0mm))[
    == subsection
    #lorem(80)
  ]

  #block(stroke: (left: black), outset: (left: 5mm, rest: 0mm))[
    == subsection
    #lorem(50)
  ]
]

So I would like to add for example the name of the section and subsection vertically on their corresponding line to have a kind of quick overview when the sections run over several pages for example.
Do you have any hint or idea to handle this? Thanks!

Maybe not the final solution but could help:

1 Like

Oh thanks! I’ve tried several searches but not this (obvious) one… There are some nice ideas here… In the meantime, I’ve managed to add the text I wanted with something like this:

#block(stroke: (left: gray), outset: (left: 10mm, rest: 0mm))[
  #place(
    horizon + left,
    dx: -10mm - 0.5em,
    rotate(-90deg, reflow: true, box(fill: white, outset: (x: 0.5em), [#text(black, [Title])])),
  )
  #heading(level: 1, [Title])
  #lorem(100)
]

I’m going to clean it and improve it a bit with your links before posting the final result.

2 Likes