typst-theorems icon indicating copy to clipboard operation
typst-theorems copied to clipboard

Theorem and picture side by side

Open fagu opened this issue 2 years ago • 2 comments

I would like to display text and a picture side by side inside the theorem's box, like this: test2-wanted Is there an easy way to achieve this? The following code produces an unnecessary line break after "Theorem 0.1":

#import "@preview/ctheorems:1.1.2": *
#show: thmrules
#set page(width: 11cm, height: 4cm, margin: 0pt)
#let theorem = thmbox("theorem", "Theorem", fill: blue.lighten(90%))

#theorem[
  #grid(columns: (1fr, auto), gutter: 1em,
    lorem(20),
    box(stroke: 1pt+black, width: 2cm, height: 2cm)[#align(center + horizon)[Picture]]
  )
]

test2 (Same if you use the wrap-it package instead of directly using grid.) What do you think about adding a parameter blockfmt: x => x to boxfmt that transforms the entire block as blockfmt([#title#name#separator#body])? One could then use:

#import "ctheorems.typ": *
#show: thmrules
#set page(width: 11cm, height: 3cm, margin: 0pt)
#let theorem = thmbox("theorem", "Theorem", fill: blue.lighten(90%))

#theorem(
  blockfmt: it =>
    grid(columns: (1fr, auto), gutter: 1em,
      it,
      box(stroke: 1pt+black, width: 2cm, height: 2cm)[#align(center + horizon)[Picture]]
    )
)[
  #lorem(20)
]

fagu avatar Apr 16 '24 14:04 fagu

I like the idea of a blockfmt, will try and give that flexibility in v2.0.0.

The best solution I can offer at the moment is putting the grid around the theorem.

#import "@preview/ctheorems:1.1.2": *
#show: thmrules
#set page(width: 11cm, height: auto, margin: 0.5cm)

#let theorem = thmbox("theorem", "Theorem", fill: blue.lighten(90%))

#theorem[
  #lorem(15)
]

#let theorem-2col(..args, first, second) = {
  let theorem = thmbox("theorem", "Theorem", padding: (top: 0em, bottom: 0em), inset: 0em)
  block(fill: blue.lighten(90%), radius: 0.3em, inset: 1.2em)[
    #grid(columns: (1fr, auto), gutter: 1em, align: horizon)[
      #theorem(..args)[
        #first
      ]
    ][
      #second
    ]
  ]
}

#theorem-2col([Name])[
  #lorem(16)
][
  #box(stroke: 1pt + black, width: 2cm, height: 2cm)[#align(center + horizon)[Picture]]
]

pic

sahasatvik avatar Apr 16 '24 16:04 sahasatvik

Thank you!

fagu avatar Apr 16 '24 16:04 fagu