以前在windows上一直在使用ctex,基本上没什么问题。如今切换到Ubuntu上,平时基本上不会到Windows下了,想在Ubuntu上搭建起这个环境,方便之后使用。html
xelatex提供了更好的Unicode中文支持,因此这里主要使用xelatex。
beamer模板能够快速进行PPT的制做。除了外表美观,还能够提升效率,咱们只须要把本身的内容填进去只能够了。shell
网上有许多教程:windows
sudo apt-get install texlive-latex-base sudo apt-get install latex-cjk-all sudo apt-get install texlive-latex-extra sudo apt-get install texlive-xetex sudo apt-get install latex-beamer
另外推荐texmaker这个软件,在Windows和Linux上都有,之前在Windows时就不喜欢自带的编辑器,到Ubuntu上发现texmaker仍是那么好用。编辑器
xelatex有时须要加上-shell-escape选项ide
中文支持字体
\usepackage{xeCJK} \setCJKmainfont{SimSun}
插入代码
beamer使用listings包插入代码,引入包并设置默认的代码格式::ui
\usepackage{listings}
\usepackage{xcolor}
\usepackage{color}
\definecolor{keywordcolor}{rgb}{0.8,0.1,0.5}
\lstset{breaklines}%这条命令可让LaTeX自动将长的代码行换行排版
\lstset{extendedchars=false}%这一条命令能够解决代码跨页时,章节标题,页眉等汉字不显示的问题
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstset{language=C, %用于设置语言为C commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=4,
xleftmargin=2em,xrightmargin=2em, aboveskip=1em,
% frame=shadowbox
}
但编译时出错,而在document文件上就没有问题,发现须要在每帧ppt上加上fragile就能够避免这个问题:this
\begin{frame}[fragile]
\frametitle{Test Code}
\begin{lstlisting}[ language=C]
int main(int argc, char ** argv)
{
printf("Hello world!\n");
return 0;
}
\end{lstlisting}
简单的模板spa
\documentclass{beamer}
\usetheme{Copenhagen}
\usecolortheme{default}
% 可供选择的主题参见 beameruserguide.pdf, 第 134 页起
% 无导航条的主题: Bergen, Boadilla, Madrid, Pittsburgh, Rochester;
% 有树形导航条的主题: Antibes, JuanLesPins, Montpellier;
% 有目录竖条的主题: Berkeley, PaloAlto, Goettingen, Marburg, Hannover;
% 有圆点导航条的主题: Berlin, Dresden, Darmstadt, Frankfurt, Singapore, Szeged;
% 有节与小节导航条的主题: Copenhagen, Luebeck, Malmos, Warsaw
% color theme:
% albatross crane beetle dove fly seagull wolverine beaver
% inner color lily orchid rose
% outter color whale seahorse dolphin
%--------------------------------------
% 中文字体
\usepackage{xeCJK}
\setCJKmainfont{SimSun}
%--------------------------------------
% 代码
\usepackage{listings}
\usepackage{xcolor}
\usepackage{color}
\definecolor{keywordcolor}{rgb}{0.8,0.1,0.5}
\lstset{breaklines}%这条命令可让LaTeX自动将长的代码行换行排版
\lstset{extendedchars=false}%这一条命令能够解决代码跨页时,章节标题,页眉等汉字不显示的问题
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstset{language=C, %用于设置语言为C commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=4,
xleftmargin=2em,xrightmargin=2em, aboveskip=1em,
% frame=single,
% framesep=3pt,%expand outward.
% framerule=0.1pt,%expand outward.
% xleftmargin=3.4pt,%make the frame fits in the text area.
% xrightmargin=3.4pt,%make the frame fits in the text area.
% rulecolor=\color{red}
}
%--------------------------------------
% logo
\logo{\includegraphics[height=0.09\textwidth]{logo.png}}
\begin{document}
\title{xelatex+beamer处理中文}
\author{Thoms}
\institute{XXX University...}
\frame{\titlepage}
\begin{frame} {你好,世界!}
A displayed formula:
$$ \int_{-\infty}^\infty e^{-x^2} \, dx = \sqrt{\pi} $$
\begin{itemize}
\item 成功编译tex文件
\item 须要处理中英文混排时候的字体问题
\item 还须要处理公式中的字体问题
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{An Algorithm For Finding Primes Numbers.}
代码以下:
\begin{lstlisting}[ language=C]
int main(int argc, char ** argv)
{
/* this is comment */
printf("Hello world!\n");
return 0;
}
\end{lstlisting}
\end{frame}
\end{document}