polop
polop

Reputation: 51

R markdown change inline code background color for PDF

How to change the background color for inline code elements in R-markdown PDF ?

Currently when I use the single back-ticks like that, the background color is not rendered when I knit the pdf (only the font, see the capture below). However everything is working for code blocks, so I am wondering if there are some tweaks around.

inline code color not rendered

I tested the answer from issue 50727217, but the font is not rendered like 'code'.

I just want to display R-markdown inline code like markdown does.

Note

The inline code I want to have a gray background color will not be used to run code within R markdown, only to highlight some code elements (like a path, a function's name etc.).

Upvotes: 1

Views: 847

Answers (1)

LuizZ
LuizZ

Reputation: 1044

First run library(kableExtra), then try the following inline code: `r text_spec("(vectorizer.pickle)", color="white", background = "gray")`.

You can also make the text bold and play with hexadecimal colors to find the right shade of gray you want:`r text_spec("(vectorizer.pickle)", bold = T, color="white", background = "#918C8B")`.

It worked for me. This is the pdf output:

enter image description here

Upvotes: 1

Related Questions