Add image before bookdown title

三世轮回 提交于 2021-01-28 05:26:09

问题


I'm trying to add an image before the title in gitbook style bookdown project. This is similar to this question from the RStudio Community page, but I would like the image to appear only before the title, not every top-level heading.

I've created a reprex here: https://bd-reprex.netlify.app/

I've edited the _output.yml to include:

bookdown::gitbook:
  ...
  includes:
    before_body: assets/logo.html

However, as can be seen in the example above, the image now appears before every chapter, not just before the title.

Any help would be greatly appreciated!


回答1:


This question was answered here.

The solution is to add a JS codeblock to the end of the index.Rmd file, such as

```{js, echo = FALSE}
title=document.getElementById('header');
title.innerHTML = '<img src="/path/to/img.png" alt="Test Image">' + title.innerHTML
```


来源:https://stackoverflow.com/questions/62074546/add-image-before-bookdown-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!