Latex常用语法

INSTALL

使用Vscode(编辑)+TeX Liv(编译)实现。

Vscode需要Latex workshop扩展。

Main

目录结构

1
2
3
4
5
6
7
8
9
10
11
12
parper->
assets
bst
build
Chapter
Chapter1
Chapter1.tex
Chapter2
Chapter2.tex
Chapter3
Chapter3.tex
main.tex

main.tex

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
44
45
46
47
48
%%% 主文件 main.tex %%%

% 注意主文件名不能有空格或中文字符

\documentclass{article}
\usepackage{graphicx}

%\graphicspath{{assets/}}

% 如果习惯引入图片时直接输入图片文件名,应取消注释上面 \graphicspath{{assets/}} 一行,否则保留注释
% 例如我们的图片都放在 assets 文件夹下,其中有一张图片叫做 2024-08-15_13-50-23.pdf
% 那么在取消了注释后,应使用 \includegraphics{2024-08-15_13-50-23.pdf} 来引入图片
% 如果没有取消注释,则应使用 \includegraphics{assets/2024-08-15_13-50-23.pdf} 来引入图片

\usepackage{graphicx}%
\usepackage{multirow}%
\usepackage{amsmath,amssymb,amsfonts}%
\usepackage{amsthm}%
\usepackage{mathrsfs}%
\usepackage[title]{appendix}%
\usepackage{xcolor}%
\usepackage{textcomp}%
\usepackage{manyfoot}%
\usepackage{booktabs}%
\usepackage{algorithm}%
\usepackage{algorithmicx}%
\usepackage{algpseudocode}%
\usepackage{listings}%
\usepackage{blindtext}
\usepackage{fancyhdr} %
\usepackage{subfiles} % Best loaded last in the preamble
\usepackage{xeCJK}
\setCJKmainfont{SimSun}
\title{标题}
\author{ME}
\date{2025.2.28}

\begin{document}

\maketitle

\subfile{Chapter/Chapter1/Chapter 1.tex}
\subfile{Chapter/Chapter2/Chapter 2.tex}

\bibliographystyle{plainnat}
\bibliography{bst/ref.bib}
\end{document}

Chapter1.tex

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
%%% 子文件 Chapter 1.tex %%%

\documentclass[../main.tex]{subfiles}
%为了能正常分文档编译,主文件的文件名不能含有中文或空格,否则会报错
%在子文件中,指定主文件的正确路径应为 ../../main.tex, 但这样每次 ctrl+s 编译子文件时会弹出文件编译选择框, 比较麻烦。经过测试发现路径设置为 ../main.tex 时不仅能正常编译子文件(正常引入导言区),而且不会弹出文件编译选择框

\graphicspath{{\subfix{../../}}}
\begin{document}


\section{This Chapter 1}
\thispagestyle{fancy}



Hello, here is some text without a meaning... \cite{bib1}

Hello, here is some text without a meaning...

Hello, here is some text without a meaning...

Hello, here is some text without a meaning...

\end{document}

Chapter2.tex

1
2
3
4
5
6
7
8
9
10
11
12
13
14
\documentclass[../main.tex]{subfiles}
%为了能正常分文档编译,主文件的文件名不能含有中文或空格,否则会报错
%在子文件中,指定主文件的正确路径应为 ../../main.tex, 但这样每次 ctrl+s 编译子文件时会弹出文件编译选择框, 比较麻烦。经过测试发现路径设置为 ../main.tex 时不仅能正常编译子文件(正常引入导言区),而且不会弹出文件编译选择框

\begin{document}

\section{This Chapter 2}
\thispagestyle{fancy}

This is chapter 2. This is chapter 2. This is chapter 2.


\end{document}

图片

1
2
3
4
5
\begin{figure}[h]
\centering
\includegraphics[width=0.6\textwidth]{fig1.png}
\caption{描述}\label{fig1}
\end{figure}

其他

1
2
3
4
5
6
7
8
9
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%
%% Please do not use \input{...} to include other tex files. %%
%% Submit your LaTeX manuscript as one .tex document. %%
%% %%
%% All additional figures and files should be attached %%
%% separately and not embedded in the \TeX\ document itself. %%
%% %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%