文章目录
Latex排版教程
教程来自b站–latex中文教程-15集从入门到精通包含各种latex操作
1. Latex源文件的基本结构
% 导言区 用于全局设置
\documentclass{article} % book, report, letter
\usepackage{ctex} %中文
\title{My First Document}
\author{ZhangYue}
\date{\today}
% 正文区
\begin{document}
\maketitle %输出标题
Hello World!
\end{document}
2. 大纲目录
\section{}
一级标题, \subsection{}
二级标题,\subsubsection{}
三级标题
空行用于分割段落,\\
用于换行,\par
也用于换行 注意命令与文字之间用空格间隔
\chapter{}
章节大纲
\tableofcentonts
生成目录
3. 文字设置
3.1字体族设置
3.1.1英文
罗马字体、无衬线字体、打字机字体
\textrm{Roman Family}%在花括号内的字体都是罗马字体
\textsf{Sans Serif Family}
\texttt{Typewriter Family}
{ %括号限制作用范围
\rmfamily Roman Family\\
Xiamen, located in Fujian province, is a famous coastal city. It's not only renowned for its natural beauty, but also for its modernization.
}
\sffamily Sans Serif Family %该命令下面的字体都是是无衬线字体字体,直到新的声明出现覆盖该声明。
{\ttfamily Typewriter Family\\
As far as I'm concerned, Xiamen is very clean and pretty. In that city, we can enjoy clear sky, beautiful sea, and green tropical plants. I guess living there must be very pleasant.
}
3.1.2中文
{\songti 宋体}
{\heiti 黑体}
{\fangsong 仿宋}
{\kaishu 楷书}
3.2字体粗细宽度设置
\textmd{Medium Series}
\textbf{Boldface Series}
{\mdseries Medium Series}
{\bfseries Boldface Series}
3.3 字体形状设置
直立、斜体、伪斜体、大小写
\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
3.4字体大小设置
与文档相对
3.4.1英文
{\tiny hello}\\
{\scriptsize hello}\\
{\footnotesize hello}\\
{\small hello}\\
{\normalsize hello}\\
{\large hello}\\
{\Large hello}\\
{\LARGE hello}\\
{\huge hello}\\
{\Huge hello}
3.4.2中文
\subsection{中文字号}
\zihao{-0} 你好\\
\zihao{5} 你好
4. 特殊字符
空白字符
- 英文多个空格,当作一个空格处理
- 中英文混合时,自动产生空格间隔
- 中文空格无效
a\quad b % 1em(当前字体一个M的大小)
a\qquad b % 2em
a\, b 或者 a\thinspace b % 1/6的个em
a\enspace b % 0.5em
控制符
%转义字符 其中‘\’ 用\textbackslash
\# \$ \% \{ \} \~{} \_{} \^{} \& \textbackslash
引号
` ' %单引号
`` " %双引号
博客《LaTeX学习系列之—LaTeX的特殊字符》总结的很详细
5. 插入图片
5.1普通插图
\usepackage{graphicx} %导入图片的宏包
\graphicspath{{figures/},{pics/}} %图片搜索路径
%includegraphics[<选项>]{<文件名>}
%格式:EPS PDF PNG JPEG BMP
\includegraphics[scale=0.1]{IMG_1148}
scale=0.3
设置缩放比例
height=3cm
设置图片的高度
width=100pt
设置图片的宽度
height=1\textheight
设置图片的相对高度
width=1\textwidth
设置图片的相对宽度
angle=-45
设置角度
同时设置多个参数时,用","进行分割
5.2浮动体环境
浮动体就是会移动的文本框
如图\ref{fig:fig-fudong}所示 %交叉引用
\begin{figure}[htbp]
\centering %居中排版
\includegraphics[scale=0.1]{IMG_1148.JPG}
%标题和标签
\caption{浮动图}\label{fig:fig-fudong}
\end{figure}
\ref
交叉引用可以用于公式,表格,图片
h
:此处(here)-代码所在的上下文
t
:页顶(top)-代码所在页的顶部或者之后页的顶部
b
:底页(botton)-代码所页的底部,或者下一页的底部
p
:独立的一页(page)-浮动页面
6. 表格插入
6.1普通插表
设置宽度:p{宽度值},内容超过宽度时,自动换行
\begin{tabular}{l|c c c||r} %l 左, c 居中, r 对齐; | 竖线, || 双竖线
1 & 2 & 33333333333333 & 4 & 5\\
1 & 2 & 3 & 4 & 5\\
\hline %横线
1 & 2 & 3 & 4 & 5\\
\hline \hline %双横线
1 & 2 & 3 & 4 & 5\\
1 & 2 & 3 & 4 & 5
\end{tabular}
6.2浮动体环境
\usepackage{bigstrut,multirow,rotating}
\usepackage{booktabs}
\usepackage[table ]{ xcolor}
\begin{table}[htbp]
\centering
\begin{tabular}{lrrrr}
\toprule
& \multicolumn{2}{c}{a} & \multicolumn{2}{c}{b} \\
& \multicolumn{1}{l}{type1} & \multicolumn{1}{l}{type2} & \multicolumn{1}{l}{type3} & \multicolumn{1}{l}{type4} \\
\midrule
sn & 2.35 & 2.69 & 7.34 & 5.48 \\
sp & 6.32 & 5.32 & 9.13 & 7.46 \\
\bottomrule
\end{tabular}%
\caption{Add caption1}\label{tab:addlabel1}
\end{table}%
\begin{table}[htbp]
\centering
\begin{tabular}{crrrrr}
\toprule
& & \multicolumn{1}{l}{type1} & \multicolumn{1}{l}{type2} & \multicolumn{1}{l}{type3} & \multicolumn{1}{l}{type4} \\
\midrule
\multirow{2}[1]{*}{sn} & 1 & 2.35 & 2.69 & 7.34 & 5.48 \\
& \cellcolor[rgb]{ .906, .902, .902} 2 & \cellcolor[rgb]{ .906, .902, .902} 2.35 & \cellcolor[rgb]{ .906, .902, .902} 2.69 & \cellcolor[rgb]{ .906, .902, .902} 7.34 & \cellcolor[rgb]{ .906, .902, .902} 5.48 \\
\multirow{2}[1]{*}{sp} & 3 & 6.32 & 5.32 & 9.13 & 7.46 \\
& \cellcolor[rgb]{ .906, .902, .902} 4 & \cellcolor[rgb]{ .906, .902, .902} 6.32 & \cellcolor[rgb]{ .906, .902, .902} 5.32 & \cellcolor[rgb]{ .906, .902, .902} 9.13 & \cellcolor[rgb]{ .906, .902, .902} 7.46 \\
\bottomrule
\end{tabular}
\caption{Add caption2}\label{tab:addlabel2}
\end{table}%
7.公式插入
7.1单行公式
\usepackage{amsmath}
\usepackage{amssymb}`
\begin{equation} %产生带编号的公式
f(x)=a+b
\label{eq:eq1}
\end{equation}
\begin{equation}
f(x)=a-b
\label{eq:eq2}
\end{equation}
%一个公式的多行排版, & 对齐位置
\begin{equation}
\begin{split}
\cos 2x &= \cos^2 x -\sin^2 x\\
&= 2\cos^2 x - 1
\end{split}
\end{equation}
\begin{equation*}
产生不带编号的公式
7.2矩阵
\begin{equation}
\left[ \begin{matrix}
a& b& \cdots& d\\
& a& \cdots& d\\
& & \ddots& \vdots\\
0& & & d\\
\end{matrix} \right]
\end{equation}
\begin{pmatrix}
a& b& \cdots& d\\
& a& \cdots& d\\
& & \ddots& \vdots\\
0& & & d\\
\end{pmatrix}
\[
\begin{bmatrix}
a& b& \cdots& d\\
& a& \cdots& d\\
& & \ddots& \vdots\\
0& & & d\\
\end{bmatrix}
\begin{Bmatrix}
a& b& \cdots& d\\
& a& \cdots& d\\
& & \ddots& \vdots\\
0& & & d\\
\end{Bmatrix}
\begin{vmatrix}
a& b& \cdots& d\\
& a& \cdots& d\\
& & \ddots& \vdots\\
\text{\huge 0}& & & d\\
\end{vmatrix}
\begin{Vmatrix}
a& b& \cdots& d\\
& a& \cdots& d\\
& & \ddots& \vdots\\
\text{\large 0}& & & d\\
\end{Vmatrix}
\]
这是行内小矩阵
\begin{math}
\left(
\begin{smallmatrix}
x & -y \\ y & x
\end{smallmatrix}
\right)
\end{math}
7.3多行公式
7.3.1居中对齐
\begin{gather}
a + b = b + a\\
a - b = c
\end{gather}
%gather带编号,gather*不带编号
\begin{gather*}
a + b = b + a\\
a - b = c
\end{gather*}
7.3.2指定对齐位置
\begin{align}
x &= t + \cos t + 1\\
y &= 2\sin t
\end{align}
7.3.3带括号
\begin{equation}
D\left( x \right) =\left\{ \begin{array}{l}
1,if\ x>0\\
0,if\ x<0\\
\end{array} \right.
\end{equation}
8.版面设计
1.纸张大小的设置
\usepackage{geometry}
%\geometry{papersize={宽, 高}}
\geometry{papersize={20cm, 15cm}}
2.边距的设置
\usepackage{geometry}
%\geometry{left=左边距,right=右边距,top=上边距,bottom=下边距}
\geometry{left=5cm,right=5cm,top=5cm,bottom=5cm}
3.页眉页脚的设置
\usepackage{fancyhdr}
\pagestyle{fancy}
%设置页眉
\lhead{页眉左}
\chead{页眉中}
\rhead{页眉右}
%设置页脚
\lfoot{左页脚}
\cfoot{中页脚}
\rfoot{右页脚}
4.横分割线的设置
%\renewcommand{\headrulewidth}{上分割线的宽度}
%\renewcommand{\headwidth}{\textwidth}
%\renewcommand{\footrulewidth}{下分割线的宽度}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\headwidth}{\textwidth}
\renewcommand{\footrulewidth}{0.4pt}
5.行间距与段间距
\usepackage{setspace}
\onehalfspacing %命令:设置行间距,1.5倍
%设置段落间距
%\addtolength{\parskip}{宽度}
%导言区
\usepackage{geometry} %导入版面设置的宏包
\usepackage{fancyhdr} %导入页眉页脚需要的宏包
\pagestyle{fancy}
\usepackage{setspace} %行间距所用的包
\geometry{papersize={20cm, 15cm}} %设置纸张的大小
\geometry{left=2cm,right=5cm,top=5cm,bottom=5cm}%设置边距
%设置页首
\lhead{张一根}
\chead{理工大学}
\rhead{\today}
%设置页眉
\lfoot{左页脚}
\cfoot{\thepage}
\rfoot{右页脚}
%设置横线分割的宽度
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\headwidth}{\textwidth}
\renewcommand{\footrulewidth}{0.4pt}
\onehalfspacing %设置行间距,1.5倍
\addtolength{\parskip}{0.4em} %设置段落间距
%正文区
\begin{document}
秋风用时光的旋律,...,渲染得天地间空旷而又阳刚。
酷热的夏天刚刚过去,...说上一晚悄悄话。
\end{document}
9.参考文献
把所以的参考文献放在一个后缀名为.bib的文件里
\bibliographystyle{plain} %在导言区需要导入
%再在需要导入文献的地方,使用
\cite{标签名}
\bibliography{test.bib} %在文字末尾使用