文章排版之LaTeX真香

这两天学习了如何使用LaTeX,感觉用LaTeX编写文章简直太香了。决定把自己的心得体会记录下来造福大家。具体教程大家可以上哔哩哔哩或者百度上搜索。
1.环境搭建
我用的是texlive和texstudio这两个软件。在此附上下载地址:
texlive:www.tug.org/texlive/
texstudio:http://texstudio.sourceforge.net/
具体怎么下载安装上百度搜即可。在这里,我把自己走过的弯路做一个简述:
(1)安装taxlive时必须选用以管理员身份打开。安装时间长,静静等待一个小时。
(2)使用texstudio无法编译,在环境变量中添加路径。
文章排版之LaTeX真香_第1张图片
2.LaTeX的基本操作
对于写一篇文章排版无非就是那几个部分:字体、公式、参考文献。LaTeX的好处是一次排版,终身使用。虽然编程麻烦了一些但是一旦排版好后下一次就不需要重新排版了。首先声明,下列的操作仅仅是部分LaTeX操作,想要了解更多可以自己去texlive自带的说明书查阅,或者直接百度。
LaTeX将排版分为导言区与正文区。导言区相当于C语言main函数之前的部分,主要是添加宏包与声明。正文区就是真正的排版了。 一般的结构是这样的:

 %导言区
     \documentclass{article}
     \usepackage{ctex}
   %正文区
     \begin{document}
	你好,\LaTeX。
     \end{document} 

3.对LaTeX有了基本的认识后,下面介绍具体操作。
(1)首先是宏包:
如果有中文则必须添加 \usepackage{ctex}在导言区,诸如此类需要添加多个宏包才能实现正文区功能实现。
(2)生成标题作者等信息

   \documentclass{article}%book,report,lette
      \usepackage{ctex}
      \newcommand\degree{^\circ}
     %定义文章标题等信息
     \title{\heiti 勾股定理}
     \author{\kaishu 小白}
     \date{\today}
    %正文区(文稿区)
    \begin{document}
	\maketitle%添加信息
	下面介绍一个公式	
    \end{document}

(3)生成目录大纲

 \documentclass{ctexbook}%这里采用book,其他的当然也行
    \usepackage{ctex}
     %正文区
     \begin{document}
	\tableofcontents%生成目录
	\chapter{实验报告}%章节大纲
	\section{引言}
	尽管传统的机器学习在分类、回归等领域取得了极大的成功,但是在实际场景中仍然有
	很多限制。 其原因是机器学习遵循两个重要的假设:(1)有足够多的训练数据以得到
	足够好的模型(2) 训练数据和测试数据在同一个特征空间,并遵循相同的分布。
	\section{实验方法}
	\section{实验结果}
	\subsection{数据}%二级标题
	\subsection{图标}
	\subsubsection{实验条件}%三级标题
	\section{结论}
    \end{document}

(4)文章字符

\documentclass{article}
   \usepackage{ctex}
   \begin{document}
   \section{回车换行}
    %使用\\或者空行
	\section{空白符号}
	%空行分段,多个等于一个
	%自动缩进
	%英文多个空格等于一个
	%禁止使用中文全角空格
	%空白字符
	a\quad b%1em,em表示M所占的地方,一般用这个即可
	a\qquad b%2em
	a\thinspace b%1/6em
	a\enspace b%0.5em
	%空格
	a\ b%空格
	a~b%硬空格
	\section{\LaTeX 控制符}
	\# \$ \% \{ \} \& \_ \~ \ texbackslash
	\section{排版符号}
	\S \quad \P \dag \ddag \copyright \pounds
	\section{\ Tex 标志符号}
	\TeX \LaTeX \LaTeXe
	\section{引号}
	` ' `` '' 你好''
	\section{连字符}
	- -- ---
	\section{非英文字符}
	具体的含义可以去文档自查
	\section{重音符号}
     \end{document}

(5)字体设置

\documentclass[10pt]{article}%前缀为字体大小

\usepackage{ctex}

\newcommand{\myfont}{}

\begin{document}
	%字体族设置,两种方法
	\textrm{Roman Family}  \textsf{Sans Serif family} \texttt{typewriter family}
	
	\rmfamily Roamn Family {\sffamily Sans Serif family} {\ttfamily typewriter family}   
	
	\rmfamily Although the traditional machine learning inclassification,regression and other fields has achieved great success, but there are still many restrictions in the actual scenarios.  
	
	\sffamily The reason is that machine learning follows two important assumptions: 1) there are enough training data to get a good model 2) the training data and testing data are in the same feature space and follow the same distribution.
	
	%字体系列设置
	\textmd{medium series} \textbf{boldface series} 
	
	{\mdseries medium series} {\bfseries boldface series}
	
	%字体形状(直立、斜体、伪斜体、小型大写)
	\textup{upright shape} \textit{italic shape} \textsl{slanted shape} \textsc{small caps shape}
	
	{\upshape upright shape} {\itshape italic shape} {\slshape slanted shape}
	{\scshape small caps shape}
	
	%中文字体设置,使用ctex宏包
	{\songti 宋体}\quad{\heiti 黑体}\quad{\fangsong 仿宋}\quad{\kaishu 楷书}\\
	中文字体的\textbf{粗体}与\textit{斜体}\\
	%字体大小
	{\tiny       hello}\\
	{\scriptsize hello}\\
	{\footnotesize hello}\\
	{\small      hello}\\
	{\normalsize  hello}\\
	{\large      hello}\\
	{\Large      hello}\\
	{\LARGE      hello}\\
	{\huge       hello}\\
	{\Huge       hello}\\
	%中文字体大小,可以打开texdoc ctex查看
	\zihao{5}您好!
\end{document}

(6)插入图片

\documentclass{article}
   \usepackage{graphicx}%所需宏包
    \usepackage{ctex}
%插入图像:\includegraphics[选项]{文件名}
%格式:EPS,PDF,PNG,JPEG,BMP
%详见texdoc graphicx文档
\graphicspath{}%图片在当前目录下的文件夹,当前目录:当前文件的保存路径
\begin{document}
	\includegraphics{kt
    \includegraphics[angle=-45,width=10cm,height=0.1\textheight]{kt}%改变参数
    \includegraphics[scale=0.3]{kt}%图像整体缩放
\end{document} 

(7)插入表格

\documentclass{article}
\usepackage{ctex}
%具体可见texdoc booktab ,texdoc longtab ,texdoc tabu
\begin{document}
	\begin{tabular}{|c|c|c|c|c|p{1cm}}%l左对齐,r右对齐,c居中对齐,|表格竖线
    \hline%表格横线 		
	姓名 & 语文 & 数学 & 外语 & 备注\\
	\hline
	张三 & 100 & 100 & 100 & 优秀\\	
    \hline
	\end{tabular}
\end{document}	

(8)浮动体

%浮动体
\documentclass{article}
\usepackage{ctex}
\usepackage{graphicx}
\graphicspath{}
\begin{document}
	LaTeX中的插图可以为
%figure浮动体
	\begin{figure}[h]%h表示here,t表示top,b表示bottom,p表示独立一页 
	 \centering%居中
     \includegraphics[scale=0.3]{kt}
     \caption{系统框图}%添加名字与编号
	\end{figure}
%table浮动体
    LaTeX中的表格
        \begin{table}[h]
    	\centering%居中
    \begin{tabular}{|c|c|c|c|c|p{1cm}}%l左对齐,r右对齐,c居中对齐,|表格竖线
    	\hline%表格横线 		
    		姓名 & 语文 & 数学 & 外语 & 备注\\
    		\hline
    		张三 & 100 & 100 & 100 & 优秀的一批\\	
    		\hline   
    	\end{tabular}
    \caption{成绩表} 
    \end{table}
    \end{document}	

(9)公式编辑

  \documentclass{article}

   \usepackage{ctex}

   %数学公式
   \begin{document}
	\section{行内公式}
	\subsection{美元公式\$}
	例如$1+1=2$
	\subsection{小括号}
	\(1+1=2\)
	\subsection{math环境}
	例如
	\begin{math}
		1+1=2
	\end{math}
	\section{上下标}
	\subsection{上标}
	$3x^2+x=4$
	
	$3x^{4x+2}+x=4$
	\subsection{下标}	
	$a_0,a_1,a_2...a_{100}$
    \section{希腊字母}  
    $\alpha$
    $\beta$
    $\gamma$
    $\pi$
    $\omega$
    
    $\Gamma$
    
    $2\gamma+3\beta=2$
    \section{数学函数}
    $\log$
    $\sin$
    $\cos$  
    
    $\cos(\angle90)=0$ 
    
    $\cos^2x+\sin^2x=1$ 
    
    $\sqrt[4]{\sin x}$
    
    $\frac{\sin x}{\cos x}$
    
   \section{行间公式}
   \subsection{双美元符号}
     $$1+1=2$$
    \subsection{中括号}
    \[1+1=2\]
    \subsection{displaymath环境}
    \begin{displaymath}
      \centering
    	1+1=2
    \end{displaymath}
    \subsection{自动编号}
    一个简单的数学公式见式\ref{eq:111}%公式调用
    \begin{equation}
	 1+1=2 \label{eq:111}
   \end{equation}
   \subsection{非自动编号}
    \begin{equation*}
    	2+2=4
    \end{equation*}
    \end{document}	

(10)矩阵定义:

%矩阵定义必须要有\[\]
\documentclass{article}
\usepackage{amsmath}
\usepackage{ctex}

\begin{document}
	\[
	\begin{matrix}%与表格类似
	0 & 0\\
	1 & 1\\
	\end{matrix}	
	\begin{pmatrix}%与表格类似
	0 & 0\\
	1 & 1
	\end{pmatrix}
	\begin{bmatrix}%与表格类似
	0 & 0\\
	1 & 1
	\end{bmatrix}
	\begin{Bmatrix}%与表格类似
	0 & 0\\
	1 & 1
	\end{Bmatrix}
	\begin{vmatrix}%与表格类似
	0 & 0\\
	1 & 1
	\end{vmatrix}
	\begin{Vmatrix}%与表格类似
	0 & 0\\
	1 & 1
	\end{Vmatrix}
	\begin{pmatrix}%与表格类似
	a_{11} & a_{12}\\
	a_{21} & a_{22}
	\end{pmatrix}
	A=\begin{pmatrix}%省略号
	a_{11} & \dots & a_{1n}\\
	\vdots & \ddots & \vdots \\
	0 & \dots & a_{nn} 
	\end{pmatrix}_{n \times n}
	\]
%该命令可以生成各种矩阵,自行查看说明文档
\end{document}	

(11)多行公式

%多行公式
\documentclass{article}

\usepackage{ctex}
\usepackage{amsmath}
\usepackage{amssymb}
%具体可见texdoc booktab texdoc longtab texdoc tabu

\begin{document}
	
	\begin{gather}%带编号
	a+b=b+a\\
	ab=ba
	\end{gather}
	\begin{gather*}%不带编号
	a+b=b+a\\
	ab=ba
	\end{gather*}
	\begin{gather}%阻止编号
	a+b=b+a \notag \\
	ab=ba
	\end{gather}
	\begin{align}%&对齐
	a+b&=b+a &a^2&=b^2\\
	ab&=ba  &a^2+b^2&=1
	\end{align}
	
	\begin{equation}
	 \begin{split}
	 a+b&=b+a\\
	 &=ba
	 \end{split}
	\end{equation}
	
	\begin{equation}
	D(x)=\begin{cases}%分段函数
	1,&x>0\\%需使用\text{}才能使用中文
	0,&x<0	
	\end{cases}
	\end{equation}

\end{document}	

你可能感兴趣的:(文章排版)