如何在 Latex 输出中将 R 代码的一部分标记为粗体?

如何在 Latex 输出中将 R 代码的一部分标记为粗体?

Rmarkdown YAML

output:
  pdf_document:
      latex_engine:  xelatex
classoption: x11names
documentclass: article
header-includes:
- \PassOptionsToPackage{x11names}{xcolor} 
- \usepackage{eso-pic,graphicx}
- \usepackage[absolute,overlay]{textpos}
- \usepackage{fontspec}
- \setmainfont{Arial}
- \renewcommand{\seriesdefault}{bx}
- \usepackage[top=2cm, bottom=2cm, outer=0cm,     inner=0cm]{geometry}

可重现的示例:

first_column <- c("client")
total <- c("45673")

df <- data.frame(first_column, total)


example = paste("The fund had this much money",paste("\\$",data$total,sep=""), "because of something something")

使用

\begin{textblock*}
\item[\textcolor{tasb_blue}{\textbullet}]\fontsize{8}{12}\selectfont
  {\color{tasb_blue}{`r example`}}
  \end{itemize}
\end{textblock*}

如果不将文本插入实际的乳胶格式,我该如何输入 \textbf 以便货币值加粗。我试过了, example = paste("The fund had this much money",paste("\\textbf{""\\$",data$total,"}"sep=""), "because of something something") 但没有成功。

下面是我想要的输出:

基金有这么多钱45673因为某事某事

答案1

我不清楚代码textblock*与粗体数字的问题有什么关系,但无论如何:

`r example` 

这是 Rmarkdown 代码。你可以在 Rmarkdown 代码中包含 LateX 代码,但是不是LaTeX 代码中的 Rmarkdown。

另一方面,我不明白为什么不直接使用:

... money **$`r df$total`** because... 

在任何输出格式下都可以正确打印。无论如何,在 R 端编码的仅 LaTeX 格式也是可能的:


output: pdf_document
---

```{r, echo=F}
first_column <- c("client")
total <- c("45673")
df <- data.frame(first_column, total)
example = paste("The fund had this much money 
\\bgroup\\bfseries\\$", df$total, " \\egroup 
because of something something",sep="")
```

`r example` 


The fund had this much  money **$`r df$total`** 
because of something something

姆韦


但是因为 R 代码首先传递给 markdown,然后传递给 LaTeX,所以更简单:

example = paste("The fund had this much  money 
**$",df$total,"** 
because of something something",sep="")

相关内容