要求设置Rstudio环境代码为UTF-8,也就是tools->options中的encoding选项,否则source代码框内中文为乱码,但不影响pdf输出结果。以下为个人使用的一个相关模板,你可以测试一下,不保证你能够正常编译,因为我已经很久没有更新我的cTex了。不过我这里可以正常编译,也会有一个Issuing Warning
<br />
\documentclass[xcolor=dvipsnames,10pt]{beamer}\usepackage{graphicx, color}<br />
%% maxwidth is the original width if it is less than linewidth<br />
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)<br />
\makeatletter<br />
\def\maxwidth{ %<br />
\ifdim\Gin@nat@width>\linewidth<br />
\linewidth<br />
\else<br />
\Gin@nat@width<br />
\fi<br />
}<br />
\makeatother</p>
<p>\IfFileExists{upquote.sty}{\usepackage{upquote}}{}<br />
\definecolor{fgcolor}{rgb}{0.2, 0.2, 0.2}<br />
\newcommand{\hlnumber}[1]{\textcolor[rgb]{0,0,0}{#1}}%<br />
\newcommand{\hlfunctioncall}[1]{\textcolor[rgb]{0.501960784313725,0,0.329411764705882}{\textbf{#1}}}%<br />
\newcommand{\hlstring}[1]{\textcolor[rgb]{0.6,0.6,1}{#1}}%<br />
\newcommand{\hlkeyword}[1]{\textcolor[rgb]{0,0,0}{\textbf{#1}}}%<br />
\newcommand{\hlargument}[1]{\textcolor[rgb]{0.690196078431373,0.250980392156863,0.0196078431372549}{#1}}%<br />
\newcommand{\hlcomment}[1]{\textcolor[rgb]{0.180392156862745,0.6,0.341176470588235}{#1}}%<br />
\newcommand{\hlroxygencomment}[1]{\textcolor[rgb]{0.43921568627451,0.47843137254902,0.701960784313725}{#1}}%<br />
\newcommand{\hlformalargs}[1]{\textcolor[rgb]{0.690196078431373,0.250980392156863,0.0196078431372549}{#1}}%<br />
\newcommand{\hleqformalargs}[1]{\textcolor[rgb]{0.690196078431373,0.250980392156863,0.0196078431372549}{#1}}%<br />
\newcommand{\hlassignement}[1]{\textcolor[rgb]{0,0,0}{\textbf{#1}}}%<br />
\newcommand{\hlpackage}[1]{\textcolor[rgb]{0.588235294117647,0.709803921568627,0.145098039215686}{#1}}%<br />
\newcommand{\hlslot}[1]{\textit{#1}}%<br />
\newcommand{\hlsymbol}[1]{\textcolor[rgb]{0,0,0}{#1}}%<br />
\newcommand{\hlprompt}[1]{\textcolor[rgb]{0.2,0.2,0.2}{#1}}%</p>
<p>\usepackage{framed}<br />
\makeatletter<br />
\newenvironment{kframe}{%<br />
\def\at@end@of@kframe{}%<br />
\ifinner\ifhmode%<br />
\def\at@end@of@kframe{\end{minipage}}%<br />
\begin{minipage}{\columnwidth}%<br />
\fi\fi%<br />
\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep<br />
\colorbox{shadecolor}{##1}\hskip-\fboxsep<br />
% There is no \\@totalrightmargin, so:<br />
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%<br />
\MakeFramed {\advance\hsize-\width<br />
\@totalleftmargin\z@ \linewidth\hsize<br />
\@setminipage}}%<br />
{\par\unskip\endMakeFramed%<br />
\at@end@of@kframe}<br />
\makeatother</p>
<p>\definecolor{shadecolor}{rgb}{.97, .97, .97}<br />
\definecolor{messagecolor}{rgb}{0, 0, 0}<br />
\definecolor{warningcolor}{rgb}{1, 0, 1}<br />
\definecolor{errorcolor}{rgb}{1, 0, 0}<br />
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX</p>
<p>\usepackage{alltt}</p>
<p>%\usepackage{amsmath} %数学符号???<br />
%\usepackage{natbib} %参考文献引用包<br />
\usepackage[UTF8,noindent]{ctexcap}<br />
%\usepackage{cctbase}<br />
\usecolortheme[named=Brown]{structure}<br />
\usetheme{Warsaw}<br />
\usepackage{colortbl,xcolor}<br />
\setbeamertemplate{caption}[numbered] %插图自动编号<br />
\setbeamertemplate{footline}[frame number] %页码</p>
<p>\begin{document}<br />
\title{beamer function test}<br />
\author{chinese 中文}<br />
\institute{WTO}<br />
\maketitle</p>
<p>\begin{frame}[fragile]<br />
%注意使用以下字体,在不能正常显示时请加载CJK???<br />
\heiti 中文字体\\<br />
\songti 中文字体\\<br />
\songti 中文字体\\<br />
\fangsong 中文字体\\<br />
\kaishu 中文字体\\<br />
%\lishu 中文字体\\<br />
%\youyuan 中文字体\\<br />
D. Knuth wrote some books, e.g. \cite{DK1}<br />
\end{frame}</p>
<p>\begin{frame}[fragile]<br />
%注意使用以下字体,在不能正常显示时请加载CJK???<br />
\zihao{3}\heiti 中文字体\\<br />
\zihao{4}\songti 中文字体\\<br />
\zihao{5}\songti 中文字体\\<br />
\zihao{6}\fangsong 中文字体\\<br />
\zihao{7}\kaishu 中文字体\\<br />
%\lishu 中文字体\\<br />
%\youyuan 中文字体\\<br />
\end{frame}</p>
<p>\begin{frame}[fragile]<br />
this is test page\\<br />
\heiti 这就是黑体中文\\<br />
\songti 还需要仔细研究后面页的代码生成图形的浮动问题及显示控???<br />
%\begin{columns}[t]<br />
%\begin{column}{5cm}<br />
%\linespread{1.3} 行间??? 默认值为1<br />
\begin{knitrout}\scriptsize<br />
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}<br />
\begin{alltt}<br />
x <- \hlfunctioncall{c}(1:10)<br />
y <- \hlfunctioncall{c}(1:10)<br />
x<br />
\end{alltt}<br />
\begin{verbatim}<br />
## [1] 1 2 3 4 5 6 7 8 9 10<br />
\end{verbatim}<br />
\begin{alltt}<br />
y<br />
\end{alltt}<br />
\begin{verbatim}<br />
## [1] 1 2 3 4 5 6 7 8 9 10<br />
\end{verbatim}<br />
\begin{alltt}<br />
\hlfunctioncall{print}(x)<br />
\end{alltt}<br />
\begin{verbatim}<br />
## [1] 1 2 3 4 5 6 7 8 9 10<br />
\end{verbatim}<br />
\begin{alltt}<br />
y<br />
\end{alltt}<br />
\begin{verbatim}<br />
## [1] 1 2 3 4 5 6 7 8 9 10<br />
\end{verbatim}<br />
\end{kframe}<br />
\end{knitrout}</p>
<p>this is test text<br />
%\end{column}<br />
%\end{columns}<br />
\end{frame}</p>
<p>\begin{frame}[fragile]<br />
\begin{block}{this is block title}<br />
\begin{columns}[t]<br />
\begin{column}{5cm}<br />
this is used to column application 1\\<br />
\begin{figure}[numbered]<br />
\begin{knitrout}<br />
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}</p>
<p>\includegraphics[width=\maxwidth]{figure/unnamed-chunk-1} \hfill{}</p>
<p>\end{knitrout}</p>
<p>\caption{This caption is placed below the figure.}<br />
\end{figure}<br />
\end{column}<br />
\begin{column}{5cm}<br />
this is used to column application 2\\<br />
\begin{figure}[numbered]<br />
\begin{knitrout}<br />
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}</p>
<p>\includegraphics[width=\maxwidth]{figure/unnamed-chunk-2} \hfill{}</p>
<p>\end{knitrout}</p>
<p>\caption{This caption is placed below the figure.}<br />
\end{figure}<br />
\end{column}<br />
\end{columns}<br />
\end{block}<br />
this is buttom text\\<br />
这是中文的说???<br />
\end{frame}</p>
<p>\begin{frame}[fragile]<br />
\begin{theorem}{this's lemma}<br />
\texttt{test lemma function application \footnote{this is footnote}}<br />
\end{theorem}<br />
\end{frame}</p>
<p>\begin{frame}<br />
\begin{thebibliography}{123456}<br />
\bibitem[Knuth1]{DK1} D. Knuth, T.A.O.C.P. , Vol. 1, Addison-Wesley, 1997.<br />
\bibitem[Knuth2]{DK2} D. Knuth, T.A.O.C.P. , Vol. 2, Addison-Wesley, 1997.<br />
\bibitem[Knuth3]{DK3} D. Knuth, T.A.O.C.P. , Vol. 3, Addison-Wesley, 1998.<br />
\end{thebibliography}<br />
\end{frame}</p>
<p>\end{document}<br />
</p>
ps:
win平台,R3.0,Rstudio 0.97.336