2017-05-17

Colour definition

The iosp package provides the add_box_colour(name, bg, bg_header, text, text_header) function to declare additional background colours. Where:

  • name is the mandatory name of the new colour (which will be prefixed with bg- if it is omitted).
  • bg is the mandatory background colour in a format recognized by col2rgb():
    • A colour name listed by colours().
    • A hexadecimal colour code (e.g. #FF11GG).
  • header_bg is the optional header background colour.
  • text is the optional text colour. If text = NULL, the text will be either black or white depending on bg (using the algorithm presended in this post).
  • header_text is the optional header text colour. If header_text = NULL, the text will be either black or white depending on header_bg.

Using add_box_colour()

in the yaml header

You can either define your colours in the yaml header or in a chunk.

title: "IOSlides custom box colours"
output:
  iosp::ioslides_plus:
    box_colours:
      bg-my_colour: "slateblue2"
      bg-my_colour2: ["tomato3", "tomato2"]
      bg-my_colour3: ["springgreen4", header_text: "#FFD700"]

Box

First box based on the slateblue2 colour.

Box

Box with a tomato3 background colour and a tomato2 header background colour.

Box

Box with a springgreen4 background colour and a gold (#FFD700) header text.

Using add_box_colour()

in a chunk

Set the chunk results option to "asis" (you might also want to hide the chunk with echo = FALSE).

iosp::add_box_colour("my_colour4", "snow3", text = "violetred")
#  equivalent to iosp::add_box_colour("bg-my_colour4", "snow3", text = "violetred")

We omitted the bg- prefix in the colour definition but should nevertheless use the .bg-my_snow class to render the box:

Box

A box using the bg-my_colour4 colour defined in a chunk.