Hello everyone!
I am trying to create a vertical line that serves as a running rule along the content of a box/block. I am using place()
to attach it to the box, but I can’t get the automatic height adjusting for the line.
My first attempt was
#set page(height: 8cm, width: 8cm, margin: 1em)
#box(
width: 4cm,
inset: (left: 1.4em, bottom: 1.4em, rest: 1em),
radius: 0.4em,
fill: blue.lighten(85%)
)[
#place(
horizon + left,
dx: -0.4em,
// failed vertical line
line(
angle: 90deg,
length: 100%,
// start:(0%,0%), // similar approach, same result
// end:(0%,100%)
)
)
#lorem(15)
]
Which has output (1) in the photo:
I thought it was easily achievable via relative lengths for example (like 1fr
or 100%
), thinking that these lengths adapt as the content is within a container and not simply in the page.
Which they partially do, only adapting to horizontal width of a container, but not vertical. As I tested the dynamic horizontal length by placing another horizontal line as evident from (2) in the picture above.
// added the following to the content of the box
// to test horizontal dynamic length
#place(
bottom + center,
dy: 0.4em,
// successful horizontal line
line(
angle: 0deg,
length: 100%,
// start:(0%,0%), // similar approach
// end:(100%,0%)
)
)
My next attempt was to attempt utilizing either measure()
or layout()
but I can’t seem to get what I am doing wrong, maybe implementing context
related ideas is a bit tricky for me.
My last attempt was to try the create everything in a context block and make a measuring function that I can access from withing the box/block but ended up failing.
#let mes(body) = context{
let bsize = measure(body)
[#bsize #body]
}
trying to access the value of bsize.height
from within the box as it is wrapped in mes()
#mes[
#box(
width: 4cm,
inset: (left: 1.4em, bottom: 1.4em, rest: 1em),
radius: 0.4em,
fill: blue.lighten(85%)
)[
#place(
horizon + left,
dx: -0.4em,
// failed vertical line
line(
angle: 90deg,
length: 100%, // cannot use `#bsize.height`
// start:(0%,0%), // similar approach
// end:(0%,100%)
)
)
#place(
bottom + center,
dy: 0.4em,
// successful horizontal line
line(
angle: 0deg,
length: 100%,
// start:(0%,0%), // similar approach
// end:(100%,0%)
)
)
#lorem(15)
]
]
Which gave:
I would like a way to make the vertical line adapt to the size of the container.
I apologize in advance if I am missing something obvious.