Setting up headers in Touying

Hi guys. I am trying to setup Touying based on an internal .pptx template so I can (hopefully) more easily produce slides.

This template is very simple, but I am having a lot of trouble adjusting the simple theme to be compatible with it. Essentially it consists of a header with the slide title in bold justified to the left, the slide number justified to the right in neutral colors, and a colored bar on the bottom. The slide should have no margin whatsoever.

The first slide essentially requires a header with three images justified to the left, with the title and subtitle on the center. The latter is already given by simple theme but that is about it.

Essentially, it should look like this:


But so far I could only get the code below. Sorry, I can’t show what it renders because the forums only allows two figure uploads.

#import "@preview/touying:0.6.3": *
#import themes.simple: *

#let red = rgb("#ff0000")//rgb("#391881")
// #let container = rect.with(height: 100%, width: 100%, inset: 0pt)
// #let innerbox = rect.with(stroke: (dash: "dashed"))

#let header(self) = {
  set align(top)
  // show: components.cell.with(fill: self.colors.primary, inset: 1em)
  // set align(horizon)
  set text(fill: rgb("#000000"), 
    size: 2.5em, 
    weight: "bold"
  )
  utils.display-current-heading(level:2)
  context utils.slide-counter.display()

  linebreak()
  
  // purple line
  line(
    length: 100%,
    stroke: (
      paint: red,
      thickness: 3pt
    )
  )
}


#show: simple-theme.with(aspect-ratio: "16-9",
header: header,
config-page(
   margin: (top: 0em, bottom: 0em, x: 0em)
  ))


= Title
Subtitle

== Slide 1
Content 1

== Slide 2
Content2

Could someone explain to me what I am doing wrong and how can I fix this? It would make my day.

These are the slides I have managed to make thus far:


Hi. Here is how I’d probably do it:

#import "@preview/touying:0.6.3": *
#import themes.simple: *

// #let red = rgb("#ff0000") // rgb("#391881")
#let red = rgb("#ff0404") // rgb("#391881")

#let header(self) = {
  {
    show: components.cell.with(inset: 5mm)
    text(2.5em, strong(utils.display-current-heading()))
    h(1fr)
    show: box
    show: move.with(dx: 0.5em, dy: 0.5em)
    context utils.slide-counter.display()
  }
  line(length: 100%, stroke: red + 3pt)
}

#let title-background = {
  set align(top + left)
  set rect(stroke: blue.lighten(50%) + 4pt)
  show: pad.with(2pt)
  grid(
    columns: 3,
    gutter: 5mm,
    align: bottom,
    rect(width: 40mm, height: 30mm),
    rect(width: 37mm, height: 27mm),
    rect(width: 35mm, height: 25mm),
  )
}

#show: simple-theme.with(
  header: header,
  footer-right: none,
  subslide-preamble: none,
  config-info(title: "Title"),
  config-page(margin: (top: 3em, rest: 5mm), fill: gray.lighten(50%)),
  config-common(zero-margin-header: true, zero-margin-footer: true),
  config-colors(primary: black),
)
#set text(font: "Liberation Sans")

#title-slide(config: config-page(background: title-background))[
  #title()
  Subtitle
]

== Slide 1
#lorem(98)

== Slide 2
#lorem(98)

This is not how it works, nor how presentations work in general. You clearly have some padding around all text boxes and just in general for the main slide text. This contradicts with your reproduction goal.

1 Like

Hi Andrew!!! That seems perfect. Thank you so much!!! Would you mind telling me how you learned to be so good at Typst? Is there any study material you recommend?

This is not how it works, nor how presentations work in general. You clearly have some padding around all text boxes and just in general for the main slide text. This contradicts with your reproduction goal.

Yeah, you are right about that… It is just that the margins are pretty tight and there are no margins on the line or the figures.

Practice makes perfect. I’ve been using it probably weekly (sometimes daily) for almost 3 years and solved hundreds of different Questions. I’m also a coder, so Typst code is pretty cool to work with, automate stuff, etc. With enough enthusiasm, perseverance, practice, and time you can become just as good.

Though Setting up headers in Touying - #3 by Andrew isn’t actually that advanced or anything, just gotta figure out how to work with a rather complex library. The docs are pretty good now.

There are some that are known and probably useful to some, like About - Typst Examples Book. But I don’t know much and GitHub - qjcg/awesome-typst: Awesome Typst Links · GitHub doesn’t have anything else.

Oh, right, there actually is something else. And this one I can recommend because I’m the co-author and because it can be useful or just interesting to almost anyone, probably. A paper about Typst, written in Typst, and with an official Typst-based template in the IJIMAI journal

1 Like

These resources are excellent, I will save them here. I guess I finally learned how to customize headers with them.

Nice job with the article, it looks like a great first resource for understanding Typst or how to write certain things with it.

Thank you very much!!! :grin:

1 Like

Thanks for the praise regarding the docs, most goes to orangeX4.
If you feel like stuff is missing, we are always happy to have more input.

And we are still working on getting the docs up-to-date with all the features, some quirky things however are better described in a longer form like here.

1 Like