Home > database >  Proper sansfontoptions syntax
Proper sansfontoptions syntax

Time:09-10

In my YAML header I would like to specify a hex color for the sansfont in my document however based on the Quarto documentation it's not readily clear how to incorporate the \fontspec options.

In the code below, I would like to set the sansfont to #ff7832, but I get the error

"sansfontoptions has value text: | \fontspec[Color="#ff7832"], which must be a string"

I have tried both with and without quotation marks. Is there a different way I should be formatting this?

format: 
  pdf: 
    mainfont: Calibri
    sansfont: Overpass-ExtraBold
    sansfontoptions: 
      text: | 
        \fontspec[Color="#ff7832"]

I also tried to define a custom color, but did not have any success

 \definecolor{Foo}{rgb}{0.3,0.4,0.5}
 \fontspec[Color= Foo]{Overpass-ExtraBold}

CodePudding user response:

You just need to pass the options of fontspec by listing them on separate line prepended by - , not the latex command.

---
format: pdf
mainfont: "Calibri"
sansfont: "Roboto"
sansfontoptions:
  - Color=ff7832
  - WordSpace=0.2
---

## This is Quarto

Quarto enables you to weave together content and executable code into a 
finished document. To learn more about Quarto see <https://quarto.org>.

## Running Code

When you click the **Render** button a document will be generated that
includes both content and the output of embedded code. You can embed 
code like this:

```{r}
1   1
```

colored header done by setting the sansfontoptions


And about the color code, as per the fontspec documentation, p-26

The colour is defined as a triplet of two-digit Hex RGB values, with optionally another value for the transparency (where 00 is completely transparent and FF is opaque.)

So simply use the hex color code (that is, use ff7832, not #ff7832).

  • Related