在bookdown标题前添加图片 [英] Add image before bookdown title

查看:45
本文介绍了在bookdown标题前添加图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 gitbook 样式的 bookdown 项目的标题前添加图像.这类似于 这个问题 来自 RStudio 社区页面,但我希望图像仅出现在标题之前,而不是每个顶级标题之前.

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.

我在这里创建了一个 reprex:https://bd-reprex.netlify.app/

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

我已经编辑了 _output.yml 以包括:

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.

任何帮助将不胜感激!

推荐答案

此问题已得到解答 这里.

解决办法是在index.Rmd文件末尾添加一个JS代码块,如

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
```

这篇关于在bookdown标题前添加图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆