用Sweave在\ sexp中加粗文本的一部分

问题描述 投票:0回答:1

我使用一个条件通过Sweave显示2个不同的文本。之后,我显示此文本。

但是我想加粗我的第一部分文字。

<<condition, echo=FALSE>>=
if (x > 0) {
  text <- paste("text 1 start :",paste(variables, collapse = ","), ". text 1 end.")
  } else {
    text <- paste("text 2")
  }
@

\Sexpr{text}

这里,我的report.pdf中的实际输出是:

文本1开头:var1,var2,var3文本1结尾

但是我想:

文本1开始:var1,var2,var3。文字1结束

r sweave
1个回答
0
投票
您可以分别返回数据,并使用普通的LaTeX命令,例如\Sexpr{foo} \textbf{\Sexpr{bar}} \textbf{\Sexpr{foobar}}

或者,您可以像这样在R中嵌入必要的LaTeX命令:

\documentclass[A4]{article} \begin{document} <<>>= foo <- paste(1, 2, "\\\\textbf{", 3, "}", '4') @ Test text with some \Sexpr{foo} with formatting. \end{document}

记住很多必要的反斜杠。
© www.soinside.com 2019 - 2024. All rights reserved.