How to change the font color?

前端 未结 7 1762
轻奢々
轻奢々 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:53

    I create a function like this:

    #Color Format
    colFmt = function(x,color){
      outputFormat = knitr::opts_knit$get("rmarkdown.pandoc.to")
      if(outputFormat == 'latex')
        paste("\\textcolor{",color,"}{",x,"}",sep="")
      else if(outputFormat == 'html')
        paste("",x,"",sep="")
      else
        x
    }
    

    Then you can use it inline like this:`r colFmt("MY RED TEXT",'red')`, and colored text will be rendered regardless of whether working on latex or HTML document.

提交回复
热议问题