Open acircleda opened 4 years ago
Here are several ways to solve this... https://stackoverflow.com/questions/60271684/add-an-image-to-rmarkdown-bookdown-output-before-top-level-heading/65605643#65605643
Example here..
Why this happens ?
This is because one feature of gitbook is that the title is repeated on hover in the navbar. See
So when an image is added in the title directly in the yaml header, it will be used twice, hence the duplication on hover.
About the recommandation in https://bookdown.org/yihui/rmarkdown-cookbook/latex-logo.html, this is explicitly for latex and not for HTML. This is why it is not out of the box for bookdown's gitbook format.
The solution with JS in here : https://stackoverflow.com/a/62093846/3436535 is maybe the easiest one Adding this into the index.Rmd file
```{js, echo = FALSE}
title=document.getElementById('header');
title.innerHTML = '<img src="/path/to/img.png" alt="Test Image">' + title.innerHTML
I let this opens as a feature request to support adding a cover image in the book.
What prevents us to do this for now is that it is easy to add one where ever you want, using JS, markdown html or else. Also often each author wants it in a specific place AND you may not want this image in your PDF output, which makes it difficult for us to provide a generic solution.
One example in the R Markdown Cookbook under the title and in a [`asis` chunk](https://bookdown.org/yihui/rmarkdown-cookbook/eng-asis.html) so that it will only be shown in the PDF output : https://github.com/yihui/rmarkdown-cookbook/blob/0dca0dbdb217f4da5c1a30ba96460c030705374f/index.Rmd#L93
But we could offer one option as default using a yaml chunk, and if someone wants to customize differently the above solution could be used.
I'm working on a solution were the user can provide a cover image through an optional cover_image
argument. Would you accept a PR with such a feature?
I have added a logo in lieu of a text title by following the directions here: https://bookdown.org/yihui/rmarkdown-cookbook/latex-logo.html.
However, by doing so, hovering over the HTML logo causes a duplicate to appear. This is visible here: https://bookdown.org/aschmi11/RESMHandbook/. Note: this does not occur in the RStudio viewer.
The top part of my index.Rmd file looks like this:
Even if I add text to title, as below, the issue persists:
There have been several solutions proposed on Stack Overflow, but all of them are very hacky: https://stackoverflow.com/questions/60271684/add-an-image-to-rmarkdown-bookdown-output-before-top-level-heading/60537857#60537857. The best solution is to add a transparent image in the header, and then add the following HTML below the first header:
<img src="cover_image.png" style="position:absolute;top:50px;width=75%;align:center;" />
However, if this is recommended as an R Markdown solution, shouldn't it work fir Bookdown? This seems like a bug. We should have an option to specify a text title for the navbar/header bar at the top and a logo to be used either with the text logo or in place of it.
Session Info
By filing an issue to this repo, I promise that
xfun::session_info('bookdown')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('rstudio/bookdown')
.I understand that my issue may be closed if I don't fulfill my promises.