3

I found instructions to add a logo to the top of my Table of Contents (TOC). https://rstudio4edu.github.io/rstudio4edu-book/book-fancy.html

However, the edits I made are not reflected in the bookdown website.

I have made edits to

_output.yml
bookdown::gitbook:
  css: style.css
  config:
    toc:
      before: |
        <li class="toc-logo"><a href="./"><img src="docs/images/logos/logo-transparent.png"></a></li>
      after: |
        <li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
    edit: https://github.com/rstudio/bookdown-demo/edit/master/%s
    download: ["pdf", "epub"]
bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
bookdown::epub_book: default
bookdown::bs4_book: default

and the style.css

/*--- LOGO ---*/

.toc-logo {
  width: 200px !important;
  object-fit: contain;
  margin: 0 auto;
}

.toc-logo img {
  max-width: 100%;
  margin-bottom: 10px;
}

.summary > li:first-child {
  height: auto !important; 
}

my index.Rmd file looks like this:

title: "Book"
author: "FH"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
cover-image: images/logos/logo-transparent.png
github-repo: FH/book
description: "Guide book."

I am not sure why the when I Build Book, the logo change is not reflected. Also it seems that maybe the "tile: "Book" in index.Rmd overrides everything else?

What it looks like now:

enter image description here

1288Meow
  • 319
  • 2
  • 7

1 Answers1

0

So apparently the code above for adding a logo works but only if you are building a bookdown::gitbook

I had been building a bookdown::bs4_book for which it is not possible to add a logo this way. To add a logo I ended up creating an template.html file and adding it to the _output.xml

_output.yml
bookdown::bs4_book:
  template: template.html
  css: style.css

I found an example to follow by looking at: https://github.com/jeroenjanssens/data-science-at-the-command-line/tree/master/book/2e

Alternatively you can edit the original template.html of bs4_book https://github.com/rstudio/bookdown/blob/main/inst/templates/bs4_book.html

1288Meow
  • 319
  • 2
  • 7