admin管理员组

文章数量:1390466

I am trying to pass title, author, and other variables through yaml in quarto. I've managed to get most of it working but I am unable to have the title display in the header. Here's my template:

#let title-page(title: none, author: none,
  date: none, name: none, body) = {
  
  set page(fill: rgb("#20746c"), margin: (top: 1.5in, rest: 1.5in))
  set text(font: "Source Sans Pro", size: 14pt)
  set heading(numbering: "1.1.1")
  line(start: (0%, 0%), end: (8.5in, 0%), stroke: (thickness: 2pt))
  
  align(center)[
    #text(size: 48pt, fill: white, strong(title)) 
    #v(1em)
    #text(size: 24pt, fill: white, strong(name))
    #v(1em)
    #text(size: 24pt, author) 
    #v(2em)
    #text(size: 16pt, date)
  ]
  
  pagebreak()

  // New page should be "normal"
  set page(fill: rgb("#F2F0EF"), margin: auto, 
  header: [
    #rect(fill: rgb("#20746c"),
    height: 100%,
    width: 100%)
    #smallcaps[title]
  ], 
  footer: [
    #rect(fill: rgb("#20746c"),
    height: 100%,
    width: 100%)
    str(here().page())
  ])
  

  align(horizon, outline(indent: auto))
  
  body
}

This is my typst-show:


#show: title-page.with(
$if(title)$
  title: [$title$],
$endif$
$if(author)$
  author: [$author$],
$endif$
$if(date)$
  date: [$date$],
$endif$
$if(params.name)$
  name: [$params.name$],
$endif$
)

Here is my yaml present in Quarto Markdown Document:

---
title: "A Comprehensive Report"
author: "Report Created by: User"
date: today
params: 
  name: "ABC Student"
format:
  typst:
    template-partials: 
      - typst-template.typ
      - typst-show.typ
    toc: true
    toc-depth: 2
    toc-title: Contents
    toc-indent: 1.5em
    papersize: us-letter
    margin:
      x: 1cm
      y: 1cm
---

My coverpage page And this is my output:

As you see, the "title" field is shown in the cover page but not in the header portion. Why?

I am trying to pass title, author, and other variables through yaml in quarto. I've managed to get most of it working but I am unable to have the title display in the header. Here's my template:

#let title-page(title: none, author: none,
  date: none, name: none, body) = {
  
  set page(fill: rgb("#20746c"), margin: (top: 1.5in, rest: 1.5in))
  set text(font: "Source Sans Pro", size: 14pt)
  set heading(numbering: "1.1.1")
  line(start: (0%, 0%), end: (8.5in, 0%), stroke: (thickness: 2pt))
  
  align(center)[
    #text(size: 48pt, fill: white, strong(title)) 
    #v(1em)
    #text(size: 24pt, fill: white, strong(name))
    #v(1em)
    #text(size: 24pt, author) 
    #v(2em)
    #text(size: 16pt, date)
  ]
  
  pagebreak()

  // New page should be "normal"
  set page(fill: rgb("#F2F0EF"), margin: auto, 
  header: [
    #rect(fill: rgb("#20746c"),
    height: 100%,
    width: 100%)
    #smallcaps[title]
  ], 
  footer: [
    #rect(fill: rgb("#20746c"),
    height: 100%,
    width: 100%)
    str(here().page())
  ])
  

  align(horizon, outline(indent: auto))
  
  body
}

This is my typst-show:


#show: title-page.with(
$if(title)$
  title: [$title$],
$endif$
$if(author)$
  author: [$author$],
$endif$
$if(date)$
  date: [$date$],
$endif$
$if(params.name)$
  name: [$params.name$],
$endif$
)

Here is my yaml present in Quarto Markdown Document:

---
title: "A Comprehensive Report"
author: "Report Created by: User"
date: today
params: 
  name: "ABC Student"
format:
  typst:
    template-partials: 
      - typst-template.typ
      - typst-show.typ
    toc: true
    toc-depth: 2
    toc-title: Contents
    toc-indent: 1.5em
    papersize: us-letter
    margin:
      x: 1cm
      y: 1cm
---

My coverpage page And this is my output:

As you see, the "title" field is shown in the cover page but not in the header portion. Why?

Share Improve this question asked Mar 14 at 13:37 PssPss 6631 gold badge6 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I solved this by using () instead of [].

header: [
      #rect(fill: rgb("#20746c"),
            height: 100%,
            width: 100%)
            #smallcaps(title)
        ]

本文标签: Unable to use title variable in header Typst and Quarto MarkdownStack Overflow