LaTex 2

LaTex 入门

此时是否安装成功

  • 如果安装成功了LaTeX, 那么在计算机上会多出来LaTeX的编译器, LaTex Live 安装包在计算机上安装了多个不同的编译器, 有latex, xelatex, pdflatex等等
  • latex -v 或者 xelatex -v测试是否安装成功

升级软件

  • tlmgr update --all 其中tlmgr是Tex Live Manager, 因为墙的原因, 升级的过程可能会比较长

第一个Hello, World

使用latex编译器编译

  • vim test.tex

\documentclass{article}
\author{JH}
\title{Demo}

\begin{document}

Hello, World!

\end{document}
  • latex test.tex # 对test.tex进行编译, 生成.aux, .log 和 .dvi
  • dvipdfmx test.dvi # 将.dvi转为.pdf

使用xelatex编译器编译

  • vim test.tex

\documentclass{article}
\author{JH}
\title{Demo}

\begin{document}

Hello, World!

\end{document}
  • xelatex test.tex # 直接生成pdf
  • 如果要支持中文, 需要将文件保存为UTF-8编码格式并且使用ctex宏包, \usepackage{ctex}

.tex文件格式

  • 格式

% 导言区
% 在导言区定义文档的属性
\documentclass[12pt]{aritcal} % report, book, letter, 其中12pt控制的是正文的大小

\author{JH} % 可以修改字符, 使用\author{\kaishu JH}, 但是前提是导入了ctex宏包, 宏包就是类似于C语言中的#include, 将ctex中定义的属性拷贝到当前文件中
\title{This is My First Document}
\date{\today}
% 在导言区可以\newcommand定义新的命令
\newcommand\name{content}

% 正文区
\begin{document}
\maketitle % 在导言区定义的属性生效, 注意在文档格式为letter中没有\maketitle命令
% 在这里写正文
% 正文包含两个模式, 一个是文本模式, 另一个是数学模式
\end{document}

写文件

  • 应该先写出大纲, 在使用\tableofcontents命令生成目录
  • 示例

\documentclass{article}

\author{JH}
\title{JH}

\newcommand\super{jh}

\begin{document}
\maketitle

\tableofcontents
\section{section1}
\subsection{subsection1}
    hello, subsection1!
\subsection{subsection2}
    hello, subsection2!
\section{section2}
\subsection{subsection3}
    hello, subsection3!
\subsection{subsection4}
    hello, subsection4!
\section{section3}
\subsection{subsection5}
    hello, subsection5!
\subsection{subsection6}
    hello, subsection6!

\end{document}
  • 空行分段, 多个空行为1个
  • 自动缩进, 不要使用空格缩进

数学公式

  • 使用$$和$$ $$插入没有标号的公式
  • 使用\begin{equation} formula \end{equation}插入有标号的公式

插入图片

  • \usepackage{graphicx} % 导入宏包
  • \graphicspath{{figures/}, {pictures/}} % 这是图片查找路径, 这个很必要
  • \includegraphics[scale=0.3]{path} % 插入图片

插入表格


\begin{tabular}{l|c|c|r} % l左对齐, r右对齐, c居中对齐
\hline % 竖线
name & age & score \\
foo & 18 & 100 \\
bar & 22 &  96 \\
\end{tabular}

浮动体

  • 为了更好的排版表格和图片分别使用

\begin{table}
        \caption{Table} % 标题
        \\
        \centering % 居中
        \begin{tabular}{|l|c|c|r|}
            \hline
            name & age & score \\
            \hline
            foo & 18 & 100 \\
            \hline
            bar & 22 & 98 \\
            \hline
        \end{tabular}
    \end{table}
    
\begin{figure}[htbp] % 建议加上htbp

\includegraphics[scale=0.3]{path}
\end{figure}

CTeX

  • section左对齐: \CTEXsetup[format={\Large\bfseries}]{section}

案例


\documentclass[12pt]{ctexart}
\usepackage{graphicx}
% \usepackage{ctex}

\graphicspath{{wallpapers/}}

\title{论文}
\author{某人}
\date{\today}

\CTEXsetup[format={\Large\bfseries}]{section}

\begin{document}
    \maketitle
    \tableofcontents
    \section{介绍}
    我就是我,是颜色不一样的烟火。
    \subsection{背景}
    \subsection{调查}
    \section{我们的工作}
    \subsection{构建模型}
    \subsection{选择参数}
    \section{分析}
    \subsection{灵敏性分析}
    \section{总结}
    \subsection{优点}
    \subsection{缺点}
    
    \begin{equation}
        J(\theta)=\sum_{i=1}^{m}(h(x^{(i)})-y^{(i)})^{2}
    \end{equation}
    
    is the basic function.
    
        
    \begin{figure}[htbp]
        \includegraphics[scale=0.1]{1}
        \centering
        \caption{伦敦的公交车} \label{fig-bus}
    \end{figure}
    
    
\end{document}

注意

  • LaTeX中一个或者多个空白行表示一个\n, 使用\强制换行

猜你喜欢

转载自www.cnblogs.com/megachen/p/10003972.html