LaTeX,Sweave:如何在显示代码的行中获取 \upshape (或 \rm)?

LaTeX,Sweave:如何在显示代码的行中获取 \upshape (或 \rm)?

如何在显示以下代码的行(例如1:300 + runif(300))中获取 upshape 字体 (\rm) [使用 Sweave]?我尝试了几件事(我fontshape=n在网上找到的),但它们对结果没有影响。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{fancyvrb}

% \DefineVerbatimEnvironment{Sinput}{Verbatim}{fontsize=\small, fontshape=n}
% \DefineVerbatimEnvironment{Soutput}{Verbatim}{fontsize=\small, fontshape=n}
% \DefineVerbatimEnvironment{Scode}{Verbatim}{fontsize=\small, fontshape=n}
\fvset{listparameters={\setlength{\topsep}{0pt}}, fontsize=\small}

\SweaveOpts{engine=R, pdf=TRUE, eps=FALSE, width=5.33, height=3}
\SweaveOpts{strip.white=TRUE, keep.source=TRUE}

\begin{document}
<<label=preliminaries, echo=FALSE, results=hide>>=
options(width=70, useFancyQuotes="UTF-8", prompt="> ", continue="  ")
options(SweaveHooks=list(fig=function() par(mar=c(4, 4, 0.4, 0.7))))
@
<<label=foo>>=
1:300 + runif(300)
@
\end{document}

答案1

好的,我刚刚意识到我忘了加载Sweave,所以这有效:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[american]{babel}
\usepackage{fancyvrb}

\usepackage{Sweave}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontsize=\small, fontshape=n}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{fontsize=\small, fontshape=n}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontsize=\small, fontshape=n}
\fvset{listparameters={\setlength{\topsep}{0pt}}}

\SweaveOpts{engine=R, pdf=TRUE, eps=FALSE, width=5.33, height=3}
\SweaveOpts{strip.white=TRUE, keep.source=TRUE}

\begin{document}
<<label=preliminaries, echo=FALSE, results=hide>>=
options(width=74, useFancyQuotes="UTF-8", prompt="> ", continue="  ")
options(SweaveHooks=list(fig=function() par(mar=c(4, 4, 0.4, 0.7))))
@
<<label=foo>>=
round(1:300 + runif(300))
@
\end{document}

相关内容