![在 Latex 文档中像 R 一样格式化](https://linux22.com/image/454014/%E5%9C%A8%20Latex%20%E6%96%87%E6%A1%A3%E4%B8%AD%E5%83%8F%20R%20%E4%B8%80%E6%A0%B7%E6%A0%BC%E5%BC%8F%E5%8C%96.png)
答案1
这将自动列出 R 会话的包,具有所需的格式:
测试.Rnw在 Rstudio 中(或测试版在 Overleaf 中)
\documentclass{article}
\begin{document}
<<foo,echo=F>>=
library(xtable) # loaded only for test
library(ggplot2) # loaded only for test
@
\subsection*{A hard R work}
<<morefoo,echo=T>>=
2+3
@
\subsection*{Materials and Methods}
<<info,echo=F>>=
a <- knitr::combine_words(.packages(),
before = "\\texttt{", after ="}")
@
For this hard work we used the
\Sexpr{sessionInfo()$R.version$version.string}
with the packages \Sexpr{a}.
\end{document}