Latex笔记


记录一些Latex排版的技巧和坑。

对列表中新的段落增加缩进

1
2
\usepackage{enumitem} %导言下加入
\setlist[enumerate]{listparindent=\parindent}

表格中单元格自动换行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
\begin{table}[H]
\centering
\setlength{\tabcolsep}{12mm}{ %设置列表宽度
\caption{累积贡献率表}\label{table_4-3}
\begin{tabular}{cp{11.8cm}} % cp{超出该值自动换行} 好像仅支持三线表,表格就得手动了。
\toprule
& \hspace{10em}部分药材编号 \\
\midrule
1类 & 1、17、32、35 39、40、45、46 \\
2类 & 2、5、8、11、13、15、16、18、22、24、25、26、27、28、29、33,34、36、37、38、43、44、47、49 \\
3类 & 1、4、6、7、9、10、12、14 19、20、21、23、24、30、31、35、36、37、41、42、48、50 \\
\bottomrule
\end{tabular}}
\end{table}

为表格添加注释

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
\begin{table}[H]
\centering
\caption{分波段方差分析表}\label{table_4-4}
\setlength{\tabcolsep}{17mm}{ %设定宽度一定要包在tabular外面一层
\begin{tabular}{ccc}
\toprule
波段 & F value & P value \\
\midrule
$[901-950]$ & 192.4 & <2e-16*** \\ %表格中[]中括号要加数学数学公式才能打出来
$[951-1000]$ & 132.9 & <2e-16*** \\
$[1001-1050]$ & 46.14 & 1.13E-1*** \\
$[1051-1200]$ & 78.06 & <2e-16*** \\
... & ... & ... \\
\bottomrule
\end{tabular}}
\begin{tablenotes}
\footnotesize
\item 注:*、**、***分别代表0.1、0,05、0.01的显著性水平
\end{tablenotes}
\end{table}

图片并列排放

1
2
3
4
5
6
7
8
9
10
11
12
13
\begin{figure}[H]
\centering
\begin{minipage}[t]{0.48\textwidth} %设定宽度
\centering
\includegraphics[width=.8\textwidth]{figure_4-24.jpg}
\caption{不同种类药材光谱数据均值曲线}\label{figure_4-24}
\end{minipage}
\begin{minipage}[t]{0.48\textwidth}
\centering
\includegraphics[width=.8\textwidth]{figure_4-25.jpg}
\caption{不同种类药光谱数据标准差曲线}\label{figure_4-25}
\end{minipage}
\end{figure}

图表编号混乱可以重置计数器

1
\setcounter{table}{0} %重置table计数器

行内公式大小修正

可以用的字体有:

1
2
3
4
\displaystyle 标准
\textstyle 行内
\scriptstyle 第一层上下标
\scriptscriptstyle 第二层上下标

案例:

1
$P=\displaystyle{\frac{T P}{T P+F P}}$ % \displaystyle在数学公式符号内将需要修正大小的数学公式括起来

表格中单元格合并

合并一行多列:\multicolumn{cols}{pos}{text}

合并多行一列:\multirow{rows}{width}{text}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\begin{table}[H]
\centering
\setlength{\tabcolsep}{5.62mm}{
\caption{累积贡献率表}\label{table_5-3}
\begin{tabular}{cccccc}
\toprule
数据 & 模型 & 召回率 & 精确率 & 准确率 & F1值 \\
\midrule
%\multirow命令所覆盖的单元格需要用~代替
\multirow{6}*{原始数据} & SVC & 0.869 & 0.876 & 0.871 & 0.870 \\
~ & RF & 0.500 & 0.538 & 0.535 & 0.506 \\
~ & XGBoost & 0.566 & 0.599 & .588 & 0.568 \\
~ & GBDT & 0.502 & 0.520 & 0.529 & 0.500 \\
~ & LightGBM & 0.570 & 0.604 & 0.600 & 0.571 \\
~ & MLP & 0.514 & 0.538 & 0.550 & 0.509 \\
\multirow{3}*{PCA降维数据} & SVC & 0.876 & 0.869 & 0.870 & 0.871 \\
~ & RF & 0.538 & 0.500 & 0.506 & 0.535 \\
~ & XGBoost & 0.599 & 0. .566 & 0.568 & 0.588 \\
\bottomrule
\end{tabular}}
\end{table}

表格续前表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
\begin{center}
\setlength{\tabcolsep}{5.62mm}{
\begin{longtable}{cccccc}
\caption{基于机器学习方法的药材产地鉴别模型比较}\\
\label{revenuepatternexplain} \\
\endfirsthead %此命令以上为第一页表头
\toprule %一条线
\endhead %此命令以上为续前表的表头
数据 & 模型 & 召回率 & 精确率 & 准确率 & F1值 \\
\midrule
\multirow{7}*{原始数据} & SVC & 0.869 & 0.876 & 0.871 & 0.870 \\
~ & RF & 0.500 & 0.538 & 0.535 & 0.506 \\
~ & XGBoost & 0.566 & 0.599 & .588 & 0.568 \\
~ & GBDT & 0.502 & 0.520 & 0.529 & 0.500 \\
~ & LightGBM & 0.570 & 0.604 & 0.600 & 0.571 \\
~ & MLP & 0.514 & 0.538 & 0.550 & 0.509 \\
\multirow{7}*{PCA降维数据} & SVC & 0.876 & 0.869 & 0.870 & 0.871 \\
~ & RF & 0.538 & 0.500 & 0.506 & 0.535 \\
~ & XGBoost & 0.599 & 0. .566 & 0.568 & 0.588 \\
~ & GBDT & 0.539 & 0.498 & 0.500 & 0.541 \\
~ & LighGBM & 0.516 & 0.473 & 0.475 & 0.512 \\
~ & MLP & 0.521 & 0488 & 0.482 & 0.521 \\
\multirow{7}*{原始数据} & SVC & 0.914 & 0.921 & 0.913 & 0.916 \\
~ & RF & 0.915 & 0.929 & 0.927 & 0.915 \\
~ & XGBoost & 0.970 & 0.974 & 0.970 & 0.920 \\
~ & GBDT & 0.881 & 0.889 & 0.900 & 0.883 \\
~ & LightGBM & 0.964 & 0.968 & 0.964 & 0.964 \\
~ & MLP & 0.813 & 0.839 & 0.828 & 0.817 \\
\multirow{7}*{原始数据} & SVC & 0.861 & 0.868 & 0.863 & 0.860 \\
~ & RF & 0.869 & 0.882 & 0.857 & 0.861 \\
~ & XGBoost & 0.915 & 0.935 & 0.921 & 0.920 \\
~ & GBDT & 0.793 & 0.834 & 0.816 & 0.799 \\
~ & LightGBM & 0.923 & 0.932 & 0.925 & 0.923 \\
~ & MLP & 0.812 & 0.820 & 0.815 & 0.809 \\
\multirow{7}*{原始数据} & SVC & 0.824 & 0.835 & 0825 & 0.823 \\
~ & RF & 0.834 & 0.871 & 0.853 & 0.841 \\
~ & XGBoost & 0.881 & 0.897 & 0.887 & 0.884 \\
~ & GBDT & 0.814 & 0.835 & 0.822 & 0.822 \\
~ & LightGBM & 0.850 & 0.866 & 0.854 & 0.853 \\
~ & MLP & 0.787 & 0.795 & 0.790 & 0.785 \\
\bottomrule
\end{longtable}}
\end{center}

简单三线表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
\begin{table}[H]
\centering
\setlength{\tabcolsep}{12mm}{ %设置列表宽度
\caption{各管线费用}\label{table_1}
\begin{tabular}{cc}
\toprule
管线 & 铺设费用 \\
\midrule
A炼油厂 & 5.6万元/km \\
B炼油厂 & 6.0万元/km \\
共用管线 & 7.2万元/km \\
\bottomrule
\end{tabular}}
\end{table}

公式中实现等号对齐

1
2
3
4
5
6
\begin{equation}
\begin{split}
f(x, y, m) = & P_{1} \sqrt{x^{2}+(y-a)^{2}}+P_{2} \sqrt{(c-x)^{2}+(b-m-y)^{2}} \\
& +\left(Q+P_{2}\right) \sqrt{(l-c)^{2}+m^{2}}+ P^{\prime} y
\end{split}
\end{equation}\label{eqx1}

引用文献实现超链接

1
\cite{bib:seven}

并列图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\end{table}
\begin{figure}[H]
\centering
\caption{LDA与SVM在近红外光谱数据中的混淆矩阵示意图}\label{LDA_SVM}
\begin{minipage}[t]{0.48\textwidth}
\centering
\includegraphics[width=.9\textwidth]{近红外_LDA.eps}
\caption*{LDA}
\end{minipage}
\begin{minipage}[t]{0.48\textwidth}
\centering
\includegraphics[width=.9\textwidth]{近红外_SVM.eps}
\caption*{SVM}
\end{minipage}
\end{figure}

评论