R markdown HTML output title

I would like to modify how the title is set in the R markdown HTML output. Right now, it generates a title tag in the head and an H1 tag in the body, but it's the same text. Is there a way to have two versions of the title, one for the head and one for the body?

You can use pagetile in the yaml under in addition to title

title: text in body
pagetitle: text in head
output: html_document

Some text

pagetitle default to title if not set.


That's great! Exactly what I was looking for.

Is this documented somewhere? I tried searching for "pagetitle" and pandoc/yaml/markdown and I get various mentions of it in places like StackOverflow or GitHub issues, but nothing definitive. Even the YAML Fieldguide, which I thought was the most comprehensive resource, does not mention it.

This is not document as-is, exactly for your question. However, you can follow the hints

Rmarkdown is using pandoc to convert markdown to output format and YAML field are used as metadata for variable to pandoc. Custom template give hints to that
https://bookdown.org/yihui/rmarkdown/template-pandoc.html and also pandoc documentation itself https://pandoc.org/MANUAL.html#variables

To know which variables can be used, it is interesting to look at the template. You can see the pagetitle variable used here

Hope it helps.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.