latex

latex

1、介紹

以前在windows上一直在使用ctex,基本上沒什麼問題。如今切換到Ubuntu上,平時基本上不會到Windows下了,想在Ubuntu上搭建起這個環境,方便之後使用。html

xelatex提供了更好的Unicode中文支持,因此這裏主要使用xelatex。
beamer模板能夠快速進行PPT的製做。除了外表美觀,還能夠提升效率,咱們只須要把本身的內容填進去只能夠了。shell

2、安裝

網上有許多教程:windows

  1. 安裝texlive, ctex, xelatex, beamer
    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
  2. 安裝biblatex(3.11), biber(2.10),保持二者版本相適應
  3. 安裝中文字體simhei, simsun, simkai, simfong

另外推薦texmaker這個軟件,在Windows和Linux上都有,之前在Windows時就不喜歡自帶的編輯器,到Ubuntu上發現texmaker仍是那麼好用。編輯器

3、beamer使用

  1. xelatex有時須要加上-shell-escape選項ide

  2. 中文支持字體

    \usepackage{xeCJK}
    \setCJKmainfont{SimSun}
  3. 插入代碼
    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}
  4. 簡單的模板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}

5. 效果

latex
latex
相關文章
相關標籤/搜索