Search code examples
rhex

Using hex code to change text color in RMarkdown PDF (R)


I'm trying to change the text color in an RMD file using a PDF output. I'm doing this for work and need to use a specific hex color code.

I was able to successfully change the text color using the command:

Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}

Is it possible to change the text color in a PDF output using color hex codes? Example:

Roses are \textcolor{#1C8FCE}{#1C8FCE}, violets are \textcolor{#BBD531}{#BBD531}

Any and all help is appreciated.


Solution

  • Yes, you can, see there and there:

    You can also use CSS:

    e.g.:

    ```{css echo=FALSE}
    .my color {
      color: #FF0000;
      font-weight: 700
    }
    ```
    
    
    #R Markdown
    `r sprintf("<span class='my color'>BLAH-BLAH</span>")`
    

    To make a pdf from html. "Knit to Html" - > "Open in Browser" -> "Save as PDF..."