How to change the font color?

前端 未结 7 1748
轻奢々
轻奢々 2020-11-29 00:30

In RMarkdown is there a way to specify the font color?

There doesn\'t seem to be an option while browsing through the chunk options

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 00:41

    I basically used Nicholas Hamilton's answer but because I used xtable and print, I had some problems with certain latex sequences being escaped. Namely, \\textcolor being transformed to $\backslash$textcolor. I was able to get it right by avoiding sanitizing in the following way:

    ```{r results='asis'}
    tbl = data.frame(a = letters[1:10], b = 1:10 / 10)
    tbl$b = ifelse(tbl$b < 0.5, colFmt(tbl$b, "red"), colFmt(tbl$b, "green"))
    print(xtable(tbl), sanitize.text.function = identity)
    ```
    

    I then had to go and manually sanitize a few characters like % but at least \textcolor was correctly applied. Of course, this could be avoided by expanding your own sanitize function.

提交回复
热议问题