0

Is it possible to change the bullet colors in Xaringan presentation? The text should have a different color.

I have not find any option in xaringanthemer package neither going through the css file. I could not find any information remark.js documentation.

2 Answers2

3

You can change the bullet point colour by adding a custom CSS to the YAML header of your Xaringan presentation.

Following is a fully reproducible minimal example.

Markdown file

title: "Example"
author: "Author"
date: "`r Sys.Date()`"
output:
  xaringan::moon_reader:
    css: 
        - default
        - default-fonts
        - custom.css
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```

## Change bullet point colour

* An item
* Another item

Custom custom.css

We have taken the relevant CSS code to theme the bullet points from here.

ul {
  list-style: none; /* Remove default bullets */
}

ul li::before {
  content: "\2022";  /* Add content: \2022 is the CSS Code/unicode for a bullet */
  color: red; /* Change the color */
  font-weight: bold; /* If you want it to be bold */
  display: inline-block; /* Needed to add space between the bullet and the text */
  width: 1em; /* Also needed for space (tweak if needed) */
  margin-left: -1em; /* Also needed for space (tweak if needed) */
}

Output

enter image description here

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
2

xaringan output is html so you can change any parts by css (e.g. using this guide to change bullet color to a red dot. Taking this as a template, you can add this chunk soon after the YAML of the Rmd to change it to a red bullet:

```{css, echo=F}
ul {
  list-style: none; /* Remove default bullets */
}

ul li::before {
  content: "\2022";  /* Add content: \2022 is the CSS Code/unicode for a bullet */
  color: red; /* Change the color */
  font-weight: bold; /* If you want it to be bold */
  display: inline-block; /* Needed to add space between the bullet and the text */ 
  width: 1em; /* Also needed for space (tweak if needed) */
  margin-left: -1em; /* Also needed for space (tweak if needed) */
}
```

Separate style from content

Or more preferably (since it separates out the style component from slide content), create a css file, say style.css which contains:

ul {
  list-style: none; /* Remove default bullets */
}

ul li::before {
  content: "\2022";  /* Add content: \2022 is the CSS Code/unicode for a bullet */
  color: red; /* Change the color */
  font-weight: bold; /* If you want it to be bold */
  display: inline-block; /* Needed to add space between the bullet and the text */ 
  width: 1em; /* Also needed for space (tweak if needed) */
  margin-left: -1em; /* Also needed for space (tweak if needed) */
}

then add in the YAML, making sure that style.css is in the same path as your Rmd,

css: [xaringan-themer.css, style.css]

Tweaking the bullet shape

You can change the shape the bullet using a different unicode supplied in content (e.g. use \2023 for a triangle bullet - see other common types here).

Changing the bullet color

You just need to replace red with the color of your choice. You can replace it with the hex color code instead too.

Emi
  • 3,514
  • 8
  • 11
  • 1
    Isn't this in essence the same as the solution I posted earlier? – Maurits Evers May 28 '19 at 10:28
  • 1
    Hello Maurits. In my account Emi’s answer is considered the oldest. You solution is also correct. – Leonardo Ribeiro May 28 '19 at 15:16
  • Both solutions were able to differentiate the color of the bullets from the color of the text. However, when rendering in moon_reader the presentation template (from Yihui Xie) the bullets get vertically in the wrong position. Check slide 5 (first 'red' bullet is ok' but when going further things get mixed. – Leonardo Ribeiro May 28 '19 at 18:55
  • @LeonardoRibeiro *" In my account Emi’s answer is considered the oldest."* That is incorrect and can be easily checked if you take a look at the timestamp. Emi's answer is just a slight variation of my earlier post (even with an identical CSS). – Maurits Evers May 28 '19 at 21:11
  • @LeonardoRibeiro PS. You can see the actual timestamp if you hover the mouse over the "answered xx hours ago" message for a few seconds. – Maurits Evers May 28 '19 at 21:20
  • You are right! Your answer was 4 minutes earlier :-) Anyway, I am having trouble since the proposed solutions are not working (when knitting the bullets do not align with the text. – Leonardo Ribeiro May 28 '19 at 21:26
  • 1
    @LeonardoRibeiro If it's not coming out correctly vertically, try adding `margin-top: 0.5em;` (tweak number as necessary). It does come out correctly on mine but it might be due to font differences etc. As for the solution, I didn't see @MauritsEvers solution. There were no answer when I was answering and I suspect that as I was writing the solution, @MauritsEvers was writing theirs. – Emi May 28 '19 at 22:26
  • @Emi. Both you and Maurits have been of great help. You are probably right about your guess. From what I recall your answer showed in my screen before (probably my mistake anyway). As for your hint, I have tried but it did not work and I figured out why. I was basically using a space between bullets. This works fine in the default xaringan themes. When using the proposed solution the bullets get messed up. This works: `- One item
    - Another item` This doesn't work: `- One item

    - Another item`
    – Leonardo Ribeiro May 29 '19 at 11:31
  • @LeonardoRibeiro Great that you found a working solution! – Emi May 30 '19 at 04:04