admin管理员组

文章数量:1399966

I am trying to explore the utility of quarto and typst for PDF output from R.

Unfortunately, I am unable to find in the documentation how to control the font size of the figure captions. When rendering the Quarto document, the figure caption appears to have the same font size than the normal body text.

On top of that, it appears that the cross-referencing of the figure captions to include the chapter, e.g. Figure 5.1 ..., does not react to the the YAML crossref: chapters: true.

I am trying to explore the utility of quarto and typst for PDF output from R.

Unfortunately, I am unable to find in the documentation how to control the font size of the figure captions. When rendering the Quarto document, the figure caption appears to have the same font size than the normal body text.

On top of that, it appears that the cross-referencing of the figure captions to include the chapter, e.g. Figure 5.1 ..., does not react to the the YAML crossref: chapters: true.

Share Improve this question edited Mar 24 at 20:52 M-- 29.5k10 gold badges69 silver badges106 bronze badges asked Mar 24 at 20:09 RayRay 2,30017 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

The font size of figure captions could be adjusted by applying a custom show rule like this:

#show figure.caption: set text(size: 18pt)

Regarding the crossref: chapters: true it seems to be a little bit more complex because, as you stated, with format: typst Quarto does not seem to react and additionally, Typst currently has no built-in feature for this need (see e.g. typst/typst#1896 for more details). However, a solution as indicated in this comment should be applicable:

#set figure(numbering: num => {
  locate(loc => {
    let chap_num = counter(heading.where(level: 1)).at(loc).first()
    let chap_loc = query(heading.where(level: 1).before(loc)).last().location()
    let fig_offset = counter(figure).at(chap_loc).first()
    str(chap_num) + "." + str(num - fig_offset)
  })
}) 

---
title: Figure caption font size and numbering in Quarto Typst
format:   
  typst:     
    include-before-body:        
      - text: |      
          #set heading(numbering: "1")    
          
          #show figure.caption: set text(size: 18pt)

          #set figure(numbering: num => {
            locate(loc => {
              let chap_num = counter(heading.where(level: 1)).at(loc).first()
              let chap_loc = query(heading.where(level: 1).before(loc)).last().location()
              let fig_offset = counter(figure).at(chap_loc).first()
              str(chap_num) + "." + str(num - fig_offset)
            })
          })    
---

# First chapter

# Second chapter

![Figure caption with custom font size](elephant.png){#fig-elephant1 width=40%}

See @fig-elephant1 for an illustration.

本文标签: quartoHow to control the font size of figure captions and include chapter notationStack Overflow