Add lines around all grid items

119 Views Asked by At

How to add lines around all grid items?

enter image description here

Here is the code I have so far:

// template
#set page(height: 16.5cm, width: 18cm,
margin: (left: 1cm, right: 1cm, top: 1cm, bottom: 1cm))
#set text(14pt, fill: rgb("#444444"))

#let conf(
  authors: (),
  doc,
) = {
  let count = authors.len()
  let ncols = calc.min(count, 2)
  let nrows = 4
  
  set align(center)
  set page(
    background: grid(
      columns: (1fr,) * ncols,
      rows: (1fr,) * nrows,
      row-gutter: 1cm,
      block(height: 100%, width: 100%,
            stroke: (paint: silver, thickness: 1pt, dash: "dashed")
      )
    )
  )

  grid(
    columns: (1fr,) * ncols,
    rows: (1fr,) * nrows,
    row-gutter: 1cm,
    ..authors.map(author => [
         #author.name \
         #author.affiliation \
         #link("mailto:" + author.email)
    ])
  )
}

// values
#show: doc => conf(
  authors: (
    (
      name: "Theresa Tungsten",
      affiliation: "Artos Institute",
      email: "[email protected]",
    ),
    (
      name: "Eugene Deklan",
      affiliation: "Honduras State",
      email: "[email protected]",
    ),
    (
      name: "Eugene Deklan",
      affiliation: "Honduras State",
      email: "[email protected]",
    ),
    (
      name: "Eugene Deklan",
      affiliation: "Honduras State",
      email: "[email protected]",
    ),
  ),
  doc,
)
1

There are 1 best solutions below

0
ntjess On BEST ANSWER

Generally, you want to style elements instead of the page. This can be accomplished with a simple helper function that takes your content and formats it using a box with your stroke.

// template
#set page(height: 16.5cm, width: 18cm,
margin: (left: 1cm, right: 1cm, top: 1cm, bottom: 1cm))
#set text(14pt, fill: rgb("#444444"))

#let author-box(content) = {
  set align(center + horizon)
  box(
    width: 100%,
    height: 100%,
    stroke: (paint: silver, thickness: 1pt, dash: "dashed"),
    content
  )
}

#let conf(
  authors: (),
  doc,
) = {
  let count = authors.len()
  let ncols = calc.min(count, 2)
  let nrows = 4
  
  grid(
    columns: (1fr,) * ncols,
    rows: (1fr,) * nrows,
    row-gutter: 1cm,
    ..authors.map(author => author-box[
         #author.name \
         #author.affiliation \
         #link("mailto:" + author.email)
    ])
  )
}

// values
#show: doc => conf(
  authors: (
    (
      name: "Theresa Tungsten",
      affiliation: "Artos Institute",
      email: "[email protected]",
    ),
    (
      name: "Eugene Deklan",
      affiliation: "Honduras State",
      email: "[email protected]",
    ),
    (
      name: "Eugene Deklan",
      affiliation: "Honduras State",
      email: "[email protected]",
    ),
    (
      name: "Eugene Deklan",
      affiliation: "Honduras State",
      email: "[email protected]",
    ),
  ),
  doc,
)

A few notes:

  • width/height: 100% inside author-box means the box will size to its full container, which is the grid cell. So if you change how big the grid makes its cells, the box will fill that space. You can alternatively set outset or inset to keep a fixed margin around the content: https://typst.app/docs/reference/layout/box/#parameters-outset
  • You can get spacing between the columns too in this code by adding column-gutter to your grid.

enter image description here