Latex的学习笔记
LaTeX特别适合于论文撰写,类似markdown,使用标记文本来显示内容,比word好的地方在于投稿不需要花太多时间排版以及专注于论文写作本身。安装过程参考网上的技术博客,速度较慢,安装编译器和各个包需要一个小时左右。
基础命令
%开始部分
\documentclass{article} % 文档类型声明
\begin{document} % 文档开始
\end{document} % 文档结束
\title % 标题
\author{} %名字
\date{\today} %时间
% 基本格式化
\textbf{粗体文本} % textbf = text bold face
\textit{斜体文本} % textit = text italic
\underline{下划线文本} % underline = underline
\texttt{等宽字体} % texttt = text typewriter
% 字体大小 (相对于正常大小的预定义尺寸)
{\tiny 超小字体} % tiny = very small size
{\small 小字体} % small = smaller than normal
{\large 大字体} % large = larger than normal
{\huge 超大字体} % huge = very large size
% 段落控制
\noindent 这段不缩进。 % noindent = no indentation
\hspace{2cm}这里有额外空间。 % hspace = horizontal space
% 换行与分段
第一行文本 \\ % \\ = new line
第二行文本
% 列表环境
\begin{itemize} % itemize = unordered list
\item 无序列表项1 % item = list item
\item 无序列表项2
\end{itemize}
\begin{enumerate} % enumerate = ordered list
\item 有序列表项1
\item 有序列表项2
\end{enumerate}
%显示特殊符号
\# = hash/pound sign
\$ = dollar sign
\% = percent sign
\& = ampersand
\{ \} = curly braces %显示花括号
\_ = underscore
\^{} = caret %显示插入符(^)
\~{} = tilde %显示波浪号(~)
\textbackslash = backslash %显示反斜杠(\)
数学公式与符号
\documentclass{article}
\usepackage{amsmath} % amsmath = American Mathematical Society math package
\begin{document}
% 1. 行内公式(inline math)
$E = mc^2$
% 2. 独立公式(displayed math)
\[
E = mc^2
\]
% 3. 带编号的公式
\begin{equation} % equation = numbered equation
F = ma
\end{equation}
% 4. 多行公式
\begin{align} % align = aligned equations align默认是带有公式编号
y &= x^2 + 2x + 1 \\
&= (x+1)^2
\end{align}
% 5. 常用数学符号
$\sum_{i=1}^{n} i$ % sum = summation
$\prod_{i=1}^{n} i$ % prod = product
$\int_{a}^{b} f(x)dx$ % int = integral
$\frac{a}{b}$ % frac = fraction
$\sqrt{x}$ % sqrt = square root
$\sqrt[n]{x}$ % nth root
% 6. 数学运算符
$a \times b$ % times = multiplication 乘
$a \div b$ % div = division 除
$a \pm b$ % pm = plus-minus 加
$a \geq b$ % geq = greater than or equal
$a \leq b$ % leq = less than or equal
$a \neq b$ % neq = not equal
% 7. 希腊字母
$\alpha, \beta, \gamma$
$\Delta, \Omega, \Phi$
\end{document}
图片
\begin{figure}[htbp]
\centering
{
\includegraphics[width=\textwidth]{image9.jpeg}
}
\caption{2 pics}
\end{figure}
页面布局与章节结构
% 定义文档类,设置12磅字号和A4纸张
\documentclass[12pt, a4paper]{article}
% 中文支持包
\usepackage[UTF8]{ctex}
% 页面布局包
\usepackage{geometry}
% 页眉页脚包
\usepackage{fancyhdr}
% 页面布局设置
\geometry{
paper=a4paper, % A4纸张
top=2.54cm, % 上边距
bottom=2.54cm, % 下边距
left=3.18cm, % 左边距
right=3.18cm, % 右边距
headheight=15pt, % 页眉高度
footskip=1cm % 页脚间距
}
% 页眉页脚设置
\pagestyle{fancy} % 使用fancy样式
\fancyhf{} % 清除默认页眉页脚
\fancyhead[L]{\leftmark} % 左页眉
\fancyhead[R]{\thepage} % 右页眉
\fancyfoot[C]{Page \thepage} % 页脚中间
\begin{document}
% 文档标题信息
\title{Document Title}
\author{Author Name}
\date{\today}
\maketitle
% 一级标题
\section{First Chapter}
% 二级标题
\subsection{First Section}
% 三级标题
\subsubsection{Sub Section}
% 生成目录
\tableofcontents
% 强制新页
\newpage
% 段落示例
This is the first paragraph.
% 带标题段落
\paragraph{Paragraph Title}
This is a paragraph with a title.
% 强制分页
\newpage
This starts a new page.
% 清除浮动体并分页
\clearpage
% 确保从偶数页开始
\cleardoublepage
% 自定义章节编号格式:使用罗马数字
\renewcommand{\thesection}{\Roman{section}}
% 自定义小节编号格式:数字编号
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\end{document}
参考文献与引用
% 导入必要的包
\documentclass{article}
\usepackage[UTF8]{ctex}
\usepackage[backend=biber]{biblatex} % 参考文献管理包
\usepackage{hyperref} % 超链接支持包
\usepackage{cleveref} % 智能引用包
% 设置参考文献数据库
\addbibresource{references.bib} % 添加文献数据库文件
\begin{document}
% 1. 交叉引用示例
\section{Introduction}
\label{sec:intro} % 设置标签供引用
% 引用章节
As discussed in Section~\ref{sec:intro} % 引用章节
% 2. 图表引用
\begin{figure}
\centering
\caption{Sample Figure}
\label{fig:sample} % 图片标签
\end{figure}
% 引用图片
As shown in Figure~\ref{fig:sample} % 引用图片
% 3. 文献引用示例
This is a citation \cite{smith2020} % 标准引用
This is a text citation \textcite{jones2019} % 文本引用
See \parencite{wilson2021} % 括号引用
% 4. 生成参考文献列表
\printbibliography % 打印参考文献列表
\end{document}
生成一个参考文献文件references.bib,放在同级目录下(参考文件的格式Google学术以及文献管理软件都可以导出为bib):
% 期刊文章
@article{smith2020,
author = {Smith, John},
title = {Sample Article Title},
journal = {Journal Name},
year = {2020},
volume = {10},
number = {2},
pages = {100-110}
}
% 书籍
@book{jones2019,
author = {Jones, Sarah},
title = {Book Title},
publisher = {Publisher Name},
year = {2019},
address = {City}
}
% 会议论文
@inproceedings{wilson2021,
author = {Wilson, Mike},
title = {Conference Paper Title},
booktitle = {Conference Name},
year = {2021},
pages = {200-210}
}
自此,Latex基本的用法都掌握了,不熟悉就再查询一下。
用起来很优雅,不用再考虑排版了,爽。
参考
Claude sonnet 3.5 (问题:我不会LATEX,但有markdown和代码基础,请让我学习十个课程,快速入门。开始第一讲。)