在RMarkdown中有没有指定字体颜色的方法?
在浏览chunk options时似乎没有选项
发布于 2015-06-22 22:29:11
@Ben Bolker提供的链接中给出了答案:
Roses are <span style="color:red">red</span>,
violets are <span style="color:blue">blue</span>.
如果选择HTML (ioslides)作为输出格式,则不起作用。
但是,如果选择pdf (beamer)作为输出格式,则不起作用。如果要创建pdf,请使用LaTeX语法:
Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.
发布于 2016-05-10 01:53:14
我创建了一个这样的函数:
## Color Format
colFmt <- function(x,color) {
outputFormat <- knitr::opts_knit$get("rmarkdown.pandoc.to")
if(outputFormat == 'latex') {
ret <- paste("\\textcolor{",color,"}{",x,"}",sep="")
} else if(outputFormat == 'html') {
ret <- paste("<font color='",color,"'>",x,"</font>",sep="")
} else {
ret <- x
}
return(ret)
}
然后,您可以像这样内联使用它:`r colFmt("MY RED TEXT",'red')`
,并且无论是在latex还是HTML上工作,都将呈现彩色文本。
发布于 2018-05-01 20:58:27
这似乎在pdf和html这两种输出格式中都能很好地工作:
Roses are $\color{red}{\text{beautiful red}}$,
violets are $\color{blue}{\text{lovely blue}}$.
希望能有所帮助。
https://stackoverflow.com/questions/29067541
复制相似问题