CTEX零基础基础入门Latex

1. 基本框架

  • article
%格式引用
\documentclass{article}%book,report,letter

%宏包
\usepackage{amsmath}%美国数学宏包

%导言区

\begin{document}
%正文区

\end{document} 
  • book
%格式引用
\documentclass{book}%article,report,letter

%宏包
\usepackage{amsmath}%美国数学宏包

%导言区

\begin{document}

%目录
\tableofcontents
%页码开始排
\mainmatter

%正文
\part{partI}
\chapter{introduction}
\section{sectionI}
\subsection{subsectionI}

\end{document}

2. 中文支持

%格式引用
\documentclass{article}%book,report,letter

%宏包
\usepackage{amsmath}%美国数学宏包
\usepackage{CJK}

%导言区

\begin{document}
\begin{CJK}{GBK}{song}
%正文区


\end{CJK}
\end{document} 

CJK宏包

latex编译

使用CJK包

\documentclass[GBK,a4paper,10pt]{ctexart}

%宏包
\usepackage{amsmath}%美国数学宏包
\usepackage{CJK}

%导言区

\begin{document}
\begin{CJK}{GBK}{song}
%正文区


\end{CJK}
\end{document} 

使用ctex包

\documentclass{article}
\usepackage{ctex}
中文直接写

article+ctex

3. 文章头信息

%标题
\title{My book}
%作者
\author{Regent Wan}

%删除日期
\date{}

\maketitle

4. 目录

%目录
\tableofcontents

第一次编译生成toc文件,第二次编译即可生成目录

页码从第一页开始:在第一页之前\mainmatter

toc目录文件
\contentsline {part}{I\hspace {1em}partI}{1}
\contentsline {chapter}{\numberline {1}introduction}{3}
\contentsline {section}{\numberline {1.1}sectionI}{3}
\contentsline {subsection}{\numberline {1.1.1}subsectionI}{3}

5. 章节

\mainmatter

%正文
\part{partI}
\chapter{introduction}
\section{sectionI}
\subsection{subsectionI}
\subsubsection{subsectionI}

上面方式自带排序

若在章节后加*则去掉自动编号

如\section*{Answer 1}

6. 无序列表itemize

\begin{itemize}
\item item1
\item item2
\item item3
\end{itemize}

7. 有序列表enumerate

\begin{enumerate}
\item item1
\item item2
\item item3
\end{enumerate}

修改前导符:

\usepackage{enumerate}

\begin{enumerate}[A.]
\item item1
\item item2
\item item3
\end{enumerate}

\bfseries A.可以加粗

\setcounter{enumi}{4}设置起始量,第二层用enumii

\begin{enumerate}[\bfseries A.]
\setcounter{enumi}{4}
\item item1
\item item2
\begin{enumerate}
\setcounter{enumii}{3}
\item item21
\item item22
\end{enumerate}
\item item3
\end{enumerate}

8. 表格

\begin{tabular}{||||}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
 &  &  \\
 &  &  \\
 &  &  \\
\hline
\end{tabular}

{c|l|r}clr为对齐方式,竖线为表格竖线

\hline为表格横线

\ \为表格换行

&表格分隔

\begin{tabular}{|c|l|r|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
1 & 2 & 3 \\
\hline
4 & 5 & 6 \\
\hline
7 & 8 & 9 \\
\hline
\end{tabular}

multicolumn{2}{c}{}合并列

\cline{3-6}加下划线

注:excel数据如何放到latex中?

将excel数据复制到文本文件中,用 & 替换 (tab),每行末尾添加\ \,复制到tabular内容区,添加各列对齐方式即可

当前表格是没有表头的,添加table,将tabular放入其内容即可

\begin{table}
\centering
\begin{tabular}{clr}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
1 & 2 & 3 \\
\hline
4 & 5 & 6 \\
7 & 8 & 9 \\
\hline
\end{tabular}
\caption{This is my first table}
\end{table}

数据显示不全时将table换成longtable即可

9. 公式输入

  • 行间公式

  • $$content$$

  • \ [content\ ]

  • \begin{equation}\label{}
    
    \end{equation}
    
  • 行内公式:$content$

  • {}表示作用域

  • \left 、\right 使得()和|等的高度和公式高度相同

  • 公式对齐

\usepackage[fleqn]{amsmath}

+ $$
\begin{aligned}
T(k) &=4 T(k-1)+\mathrm{O}(1) \\
&=4^{2} T(k-2)+4 \mathrm{O}(1)+\mathrm{O}(1) \\
&=4^{3} T(k-3)+4^{2} \mathrm{O}(1)+4 \mathrm{O}(1)+\mathrm{O}(1) \\
&=\cdots \\
&=4^{k} T(0)+\mathrm{O}(1) \sum_{i=0}^{k-1} 4^{i}
\end{aligned}
$$

T ( k ) = 4 T ( k 1 ) + O ( 1 ) = 4 2 T ( k 2 ) + 4 O ( 1 ) + O ( 1 ) = 4 3 T ( k 3 ) + 4 2 O ( 1 ) + 4 O ( 1 ) + O ( 1 ) = = 4 k T ( 0 ) + O ( 1 ) i = 0 k 1 4 i \begin{aligned} T(k) &=4 T(k-1)+\mathrm{O}(1) \\ &=4^{2} T(k-2)+4 \mathrm{O}(1)+\mathrm{O}(1) \\ &=4^{3} T(k-3)+4^{2} \mathrm{O}(1)+4 \mathrm{O}(1)+\mathrm{O}(1) \\ &=\cdots \\ &=4^{k} T(0)+\mathrm{O}(1) \sum_{i=0}^{k-1} 4^{i} \end{aligned}

  • 矩阵:array bmatrix Bmatrix vmatrix Vmatrix pmatrix[amsmath宏包]
%矩阵
$$\left[\begin{array}{clr}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{array}\right]$$

$$
\begin{bmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{bmatrix}
$$

$$
\begin{Bmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{Bmatrix}
$$

$$
\begin{vmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{vmatrix}
$$

$$
\begin{Vmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{Vmatrix}
$$

$$
\begin{pmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{pmatrix}
$$
  • mathtype公式导入:选项->剪切和复制选项->转换为其他文字->latex2.09->去掉打钩->确定并复制公式->粘贴即可

10. 图片插入

\usepackage{graphicx}%图片宏包

\includegraphics{*.eps}

\begin{figure}
\centering
% Requires \usepackage{graphicx}
\includegraphics[scale=0.5,angle=30]{Fig1.eps}\\
\caption{This is a figure}
\end{figure}

matlab、adobe能生成eps文件

注意

表格和图片插入之后不在指定位置,是由于latex的自动排版机制所致,解决方法如下:引用float包 添加[H]

\usepackage{float}

\begin{table}[H]

\end{table}

11. 页眉

\usepackage{fancyhdr}

%文档开始后
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}

%文档结束前
\clearpage

12. 特殊符号

  • %:\%
  • $:\$
  • {}:\{\}
  • \:$\backslash$

13. 公式中有中文

\text{}

14. \eject或\newpage另起一页

15. 代码段

\begin{verbatim}
select *
from section inner join classroom using(building, room_number);
\end{verbatim}

16. 伪代码

\documentclass[11pt]{ctexart}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{amsmath}

\floatname{algorithm}{算法}
\renewcommand{\algorithmicrequire}{\textbf{输入:}}
\renewcommand{\algorithmicensure}{\textbf{输出:}}

\begin{document}
\begin{algorithm}
\caption{用归并排序求逆序数}
\begin{algorithmic}[1] %每行显示行号
  \Require $Array$数组,$n$数组大小
  \Ensure 逆序数
  \Function {MergerSort}{$Array, left, right$}
      \State $result \gets 0$
      \If {$left < right$}
          \State $middle \gets (left + right) / 2$
          \State $result \gets result +$ \Call{MergerSort}{$Array, left, middle$}
          \State $result \gets result +$ \Call{MergerSort}{$Array, middle, right$}
          \State $result \gets result +$ \Call{Merger}{$Array,left,middle,right$}
      \EndIf
      \State \Return{$result$}
  \EndFunction
  \State
  \Function{Merger}{$Array, left, middle, right$}
      \State $i\gets left$
      \State $j\gets middle$
      \State $k\gets 0$
      \State $result \gets 0$
      \While{$i<middle$ \textbf{and} $j<right$}
          \If{$Array[i]<Array[j]$}
              \State $B[k++]\gets Array[i++]$
          \Else
              \State $B[k++] \gets Array[j++]$
              \State $result \gets result + (middle - i)$
          \EndIf
      \EndWhile
      \While{$i<middle$}
          \State $B[k++] \gets Array[i++]$
      \EndWhile
      \While{$j<right$}
          \State $B[k++] \gets Array[j++]$
      \EndWhile
      \For{$i = 0 \to k-1$}
          \State $Array[left + i] \gets B[i]$
      \EndFor
      \State \Return{$result$}
  \EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}

17. 分列

\documentclass[11pt]{article}
\usepackage{ctex}
\usepackage{multicol}
\begin{document}

\begin{multicols}{2} % 分两栏 若花括号中为3则是分三列
内容
\end{multicols}
\end{document}

18. slide

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Beamer Presentation
% LaTeX Template
% Version 1.0 (10/11/12)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------
%	PACKAGES AND THEMES
%----------------------------------------------------------------------------------------

\documentclass{beamer}

\mode<presentation> {

% The Beamer class comes with a number of default slide themes
% which change the colors and layouts of slides. Below this is a list
% of all the themes, uncomment each in turn to see what they look like.

%\usetheme{default}
%\usetheme{AnnArbor}
%\usetheme{Antibes}
%\usetheme{Bergen}
%\usetheme{Berkeley}
%\usetheme{Berlin}
%\usetheme{Boadilla}
%\usetheme{CambridgeUS}
%\usetheme{Copenhagen}
%\usetheme{Darmstadt}
%\usetheme{Dresden}
%\usetheme{Frankfurt}
%\usetheme{Goettingen}
%\usetheme{Hannover}
%\usetheme{Ilmenau}
%\usetheme{JuanLesPins}
%\usetheme{Luebeck}
\usetheme{Madrid}
%\usetheme{Malmoe}
%\usetheme{Marburg}
%\usetheme{Montpellier}
%\usetheme{PaloAlto}
%\usetheme{Pittsburgh}
%\usetheme{Rochester}
%\usetheme{Singapore}
%\usetheme{Szeged}
%\usetheme{Warsaw}

% As well as themes, the Beamer class has a number of color themes
% for any slide theme. Uncomment each of these in turn to see how it
% changes the colors of your current slide theme.

%\usecolortheme{albatross}
%\usecolortheme{beaver}
%\usecolortheme{beetle}
%\usecolortheme{crane}
%\usecolortheme{dolphin}
%\usecolortheme{dove}
%\usecolortheme{fly}
%\usecolortheme{lily}
%\usecolortheme{orchid}
%\usecolortheme{rose}
%\usecolortheme{seagull}
%\usecolortheme{seahorse}
%\usecolortheme{whale}
%\usecolortheme{wolverine}

%\setbeamertemplate{footline} % To remove the footer line in all slides uncomment this line
%\setbeamertemplate{footline}[page number] % To replace the footer line in all slides with a simple slide count uncomment this line

%\setbeamertemplate{navigation symbols}{} % To remove the navigation symbols from the bottom of all slides uncomment this line
}

\usepackage{graphicx} % Allows including images
\usepackage{booktabs} % Allows the use of \toprule, \midrule and \bottomrule in tables

%----------------------------------------------------------------------------------------
%	TITLE PAGE
%----------------------------------------------------------------------------------------

\title[Short title]{Full Title of the Talk} % The short title appears at the bottom of every slide, the full title is only on the title page

\author{John Smith} % Your name
\institute[UCLA] % Your institution as it will appear on the bottom of every slide, may be shorthand to save space
{
University of California \\ % Your institution for the title page
\medskip
\textit{[email protected]} % Your email address
}
\date{\today} % Date, can be changed to a custom date

\begin{document}

\begin{frame}
\titlepage % Print the title page as the first slide
\end{frame}

\begin{frame}
\frametitle{Overview} % Table of contents slide, comment this block out to remove it
\tableofcontents % Throughout your presentation, if you choose to use \section{} and \subsection{} commands, these will automatically be printed on this slide as an overview of your presentation
\end{frame}

%----------------------------------------------------------------------------------------
%	PRESENTATION SLIDES
%----------------------------------------------------------------------------------------

%------------------------------------------------
\section{First Section} % Sections can be created in order to organize your presentation into discrete blocks, all sections and subsections are automatically printed in the table of contents as an overview of the talk
%------------------------------------------------

\subsection{Subsection Example} % A subsection can be created just before a set of slides with a common theme to further break down your presentation into chunks

\begin{frame}
\frametitle{Paragraphs of Text}
Sed iaculis dapibus gravida. Morbi sed tortor erat, nec interdum arcu. Sed id lorem lectus. Quisque viverra augue id sem ornare non aliquam nibh tristique. Aenean in ligula nisl. Nulla sed tellus ipsum. Donec vestibulum ligula non lorem vulputate fermentum accumsan neque mollis.\\~\\

Sed diam enim, sagittis nec condimentum sit amet, ullamcorper sit amet libero. Aliquam vel dui orci, a porta odio. Nullam id suscipit ipsum. Aenean lobortis commodo sem, ut commodo leo gravida vitae. Pellentesque vehicula ante iaculis arcu pretium rutrum eget sit amet purus. Integer ornare nulla quis neque ultrices lobortis. Vestibulum ultrices tincidunt libero, quis commodo erat ullamcorper id.
\end{frame}

%------------------------------------------------

\begin{frame}
\frametitle{Bullet Points}
\begin{itemize}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit
\item Aliquam blandit faucibus nisi, sit amet dapibus enim tempus eu
\item Nulla commodo, erat quis gravida posuere, elit lacus lobortis est, quis porttitor odio mauris at libero
\item Nam cursus est eget velit posuere pellentesque
\item Vestibulum faucibus velit a augue condimentum quis convallis nulla gravida
\end{itemize}
\end{frame}

%------------------------------------------------

\begin{frame}
\frametitle{Blocks of Highlighted Text}
\begin{block}{Block 1}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lectus nisl, ultricies in feugiat rutrum, porttitor sit amet augue. Aliquam ut tortor mauris. Sed volutpat ante purus, quis accumsan dolor.
\end{block}

\begin{block}{Block 2}
Pellentesque sed tellus purus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vestibulum quis magna at risus dictum tempor eu vitae velit.
\end{block}

\begin{block}{Block 3}
Suspendisse tincidunt sagittis gravida. Curabitur condimentum, enim sed venenatis rutrum, ipsum neque consectetur orci, sed blandit justo nisi ac lacus.
\end{block}
\end{frame}

%------------------------------------------------

\begin{frame}
\frametitle{Multiple Columns}
\begin{columns}[c] % The "c" option specifies centered vertical alignment while the "t" option is used for top vertical alignment

\column{.45\textwidth} % Left column and width
\textbf{Heading}
\begin{enumerate}
\item Statement
\item Explanation
\item Example
\end{enumerate}

\column{.5\textwidth} % Right column and width
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lectus nisl, ultricies in feugiat rutrum, porttitor sit amet augue. Aliquam ut tortor mauris. Sed volutpat ante purus, quis accumsan dolor.

\end{columns}
\end{frame}

%------------------------------------------------
\section{Second Section}
%------------------------------------------------

\begin{frame}
\frametitle{Table}
\begin{table}
\begin{tabular}{l l l}
\toprule
\textbf{Treatments} & \textbf{Response 1} & \textbf{Response 2}\\
\midrule
Treatment 1 & 0.0003262 & 0.562 \\
Treatment 2 & 0.0015681 & 0.910 \\
Treatment 3 & 0.0009271 & 0.296 \\
\bottomrule
\end{tabular}
\caption{Table caption}
\end{table}
\end{frame}

%------------------------------------------------

\begin{frame}
\frametitle{Theorem}
\begin{theorem}[Mass--energy equivalence]
$E = mc^2$
\end{theorem}
\end{frame}

%------------------------------------------------

\begin{frame}[fragile] % Need to use the fragile option when verbatim is used in the slide
\frametitle{Verbatim}
\begin{example}[Theorem Slide Code]
\begin{verbatim}
\begin{frame}
\frametitle{Theorem}
\begin{theorem}[Mass--energy equivalence]
$E = mc^2$
\end{theorem}
\end{frame}\end{verbatim}
\end{example}
\end{frame}

%------------------------------------------------

\begin{frame}
\frametitle{Figure}
Uncomment the code on this slide to include your own image from the same directory as the template .TeX file.
%\begin{figure}
%\includegraphics[width=0.8\linewidth]{test}
%\end{figure}
\end{frame}

%------------------------------------------------

\begin{frame}[fragile] % Need to use the fragile option when verbatim is used in the slide
\frametitle{Citation}
An example of the \verb|\cite| command to cite within the presentation:\\~

This statement requires citation \cite{p1}.
\end{frame}

%------------------------------------------------

\begin{frame}
\frametitle{References}
\footnotesize{
\begin{thebibliography}{99} % Beamer does not support BibTeX so references must be inserted manually as below
\bibitem[Smith, 2012]{p1} John Smith (2012)
\newblock Title of the publication
\newblock \emph{Journal Name} 12(3), 45 -- 678.
\end{thebibliography}
}
\end{frame}

%------------------------------------------------

\begin{frame}
\Huge{\centerline{The End}}
\end{frame}

%----------------------------------------------------------------------------------------

\end{document} 

19. 框架

%格式引用
%\documentclass{article} %article,book,report,letter
\documentclass[GBK,a4paper,10pt]{ctexart}

%宏包
\usepackage{amssymb,amsfonts,amsmath,amsthm}%美国数学宏包
\usepackage{enumerate}%有序列表前导符修改
\usepackage{graphicx}%图片宏包
\usepackage{CJK}
\usepackage[left=2.50cm, right=2.50cm, top=2.50cm, bottom=2.50cm]{geometry}
\usepackage{fancyhdr}%页眉

%导言区

\begin{document}
\begin{CJK}{GBK}{song}
%标题
\title{My book}
%作者
\author{Regent Wan}

%删除日期
\date{}

\maketitle

% 设置页眉
\pagestyle{fancy}
\lhead{}
\chead{center}
\rhead{name}
\lfoot{}
\cfoot{\thepage}
\rfoot{}

\section{一级标题}
\subsection{二级标题}
\subsubsection{三级标题}
\paragraph{定义\ 1}
\subparagraph{图\ 1}

%正文区
你好,拉泰赫!
hello,Latex!

%特殊符号
\%
\$
\{\}
$\backslash$

%无序列表
\begin{itemize}
\item item1
\item item2
\begin{itemize}
\item item21
\item item22
\end{itemize}
\item item3
\end{itemize}

%有序列表
\begin{enumerate}
\item item1
\item item2
\item item3
\end{enumerate}

\begin{enumerate}[\bfseries A.]
\setcounter{enumi}{4}
\item item1
\item item2
\begin{enumerate}
\setcounter{enumii}{3}
\item item21
\item item22
\end{enumerate}
\item item3
\end{enumerate}

%表格
\begin{tabular}{clr}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
1 & 2 & 3 \\
\hline
4 & 5 & 6 \\
7 & 8 & 9 \\
\hline
\end{tabular}

\begin{table}
\centering
\begin{tabular}{clr}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
1 & 2 & 3 \\
\hline
4 & 5 & 6 \\
7 & 8 & 9 \\
\hline
\end{tabular}
\caption{This is my first table}
\end{table}

%公式
%行内公式
The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog. $\frac{{ -b \pm \sqrt {{b^2}-4ac}}}{{2a}}$ The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.

$\sum{n^2}\sqrt[3]{b^2-4ac}\frac{a}{b}x_{k}x^{k}$


$V: = {\left[ {{V_j}} \right]_{j \in J}} \in {\left\{ {0,1} \right\}^{\left| J \right|}}$

%行间公式
$$\frac{{ -b \pm \sqrt {{b^2}-4ac}}}{{2a}}$$
\[\sum^5_{i=1}i^2\]
\begin{equation}
\frac{{ -b \pm \sqrt {{b^2}-4ac}}}{{2a}}
\end{equation}

%矩阵
$$\left[\begin{array}{clr}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{array}\right]$$

$$
\begin{bmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{bmatrix}
$$

$$
\begin{Bmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{Bmatrix}
$$

$$
\begin{vmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{vmatrix}
$$

$$
\begin{Vmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{Vmatrix}
$$

$$
\begin{pmatrix}
123 & 2 &32\\
2 & 213 & 321\\
32 & 23 & 2\\
\end{pmatrix}
$$

%图片
\includegraphics{Fig1.eps}

\begin{figure}
\centering
% Requires \usepackage{graphicx}
\includegraphics[scale=0.5,angle=30]{Fig1.eps}\\
\caption{This is a figure}
\end{figure}

\clearpage
\end{CJK}
\end{document}

觉得本文对你有帮助的话,欢迎点赞转发!有任何学术上的问题也欢迎与小幸一起探讨!小幸创建了一个QQ群,方便大家学习交流,群内也会经常分享一下学习资源。有兴趣的小伙伴可以加群哦!
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Zeno_wrj/article/details/107924628