tools 工具 LaTeX 论文排版入门 一句话概述:LaTeX 是学术论文排版的标准工具,几乎所有期刊和会议都支持,掌握基础语法就能排出专业论文。
核心知识点 概念 白话解释 LaTeX 排版系统 = 写代码生成漂亮 PDF TeX Live 发行版 = LaTeX 的安装包(包含所有工具) .tex 源文件 = 你写的 LaTeX 代码 .bib 文献库 = BibTeX 格式的参考文献 pdflatex/xelatex 编译器 = 把 .tex 变成 PDF(中文用 xelatex) 宏包 (package) 扩展包 = 类似 Python 的 import documentclass 文档类 = 定义文档类型(article/report/book)
安装配置 # Linux(Ubuntu/Debian)
sudo apt install texlive-full # 完整安装(约 5GB)
sudo apt install texlive-xetex texlive-lang-chinese # 最小中文支持
# macOS
brew install --cask mactex # 完整安装
# 验证
pdflatex --version # 检查 pdflatex
xelatex --version # 检查 xelatex(中文必需)
# 编辑器推荐
# VS Code + LaTeX Workshop 插件(免费,推荐)
# Overleaf(在线,免安装)
基本文档结构 % paper.tex
\documentclass [12pt,a4paper] { article} % 文档类:12号字,A4纸
% === 导言区(加载宏包、全局设置) ===
\usepackage [UTF8] { ctex} % 中文支持(用 xelatex 编译)
\usepackage { amsmath} % 数学公式增强
\usepackage { graphicx} % 插入图片
\usepackage { booktabs} % 三线表
\usepackage { hyperref} % 超链接
\usepackage [left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm] { geometry} % 页边距
\usepackage { natbib} % 参考文献格式
% 文档信息
\title { 2型糖尿病肠道菌群宏基因组分析} % 标题
\author { 张三} % 作者
\date { \today } % 日期
% === 正文区 ===
\begin { document}
\maketitle % 生成标题
\begin { abstract} % 摘要
本研究对2型糖尿病患者肠道菌群进行宏基因组分析...
\end { abstract}
\tableofcontents % 目录
\newpage % 换页
\section { 引言} % 一级标题
2型糖尿病(T2D)是一种常见的代谢性疾病\cite { wang2022} 。
\subsection { 研究背景} % 二级标题
肠道菌群与宿主代谢密切相关。
\subsubsection { 菌群多样性} % 三级标题
Alpha 多样性是衡量样本内物种丰富度的指标。
\section { 材料与方法}
\subsection { 样本采集}
本研究收集了 \textbf { 50} 例样本(\textit { n} = 50)。 % 加粗和斜体
% 公式
Shannon 多样性指数计算公式:
\begin { equation}
H' = -\sum_ { i=1}^{ S} p_ i \ln p_ i % 编号公式
\label { eq:shannon}
\end { equation}
如公式\ref { eq:shannon} 所示... % 引用公式
% 图片
\begin { figure} [htbp] % h=此处 t=顶部 b=底部 p=独立页
\centering % 居中
\includegraphics [width=0.8\textwidth] { fig1.png} % 宽度为页面80%
\caption { 物种丰度热图} % 图题
\label { fig:heatmap} % 标签(用于引用)
\end { figure}
% 表格(三线表)
\begin { table} [htbp]
\centering
\caption { 样本基本信息} % 表题
\label { tab:samples}
\begin { tabular}{ lcc} % l=左对齐 c=居中
\toprule % 顶线
样本 & Shannon & Simpson \\ % 表头
\midrule % 中线
S1 & 3.21 & 0.89 \\ % 数据行
S2 & 2.98 & 0.85 \\
\bottomrule % 底线
\end { tabular}
\end { table}
% 列表
\begin { itemize} % 无序列表
\item 第一项
\item 第二项
\end { itemize}
\begin { enumerate} % 有序列表
\item 步骤一
\item 步骤二
\end { enumerate}
% 参考文献
\bibliographystyle { plainnat} % 文献格式
\bibliography { refs} % 引用 refs.bib
\end { document}
BibTeX 文献管理 % refs.bib
@article { wang2022 ,
author = {Wang, Lei and Li, Ming} ,
title = {Gut Microbiome in Type 2 Diabetes} ,
journal = {Nature Medicine} ,
year = {2022} ,
volume = {28} ,
pages = {1--15} ,
doi = {10.1038/s41591-022-0001}
}
编译命令 # 中文文档编译(推荐流程)
xelatex paper.tex # 第1次编译
bibtex paper # 处理参考文献
xelatex paper.tex # 第2次编译(生成引用)
xelatex paper.tex # 第3次编译(完善交叉引用)
# 英文文档可用 pdflatex
pdflatex paper.tex && bibtex paper && pdflatex paper.tex && pdflatex paper.tex
常见报错 报错 原因 解决 Undefined control sequence命令拼错或缺宏包 检查拼写,确认 \usepackage Missing $ inserted数学符号没放在 $...$ 中 加 $ 包围公式 File not found图片/bib 文件路径错 检查文件名和路径 Citation undefined没编译 bibtex 按顺序编译 3 次 Package inputenc Error编码错误 中文用 xelatex + ctex
速查表 # 编译
xelatex file.tex # 中文编译
pdflatex file.tex # 英文编译
bibtex file # 处理参考文献
# 常用命令
# \textbf{加粗} \textit{斜体} \underline{下划线}
# \section{} \subsection{} \subsubsection{} # 标题
# \ref{label} \cite{key} # 引用
# \begin{figure} \begin{table} \begin{equation} # 浮动体
# \includegraphics[width=0.8\textwidth]{file} # 图片
# \begin{itemize} / \begin{enumerate} # 列表
# 中文论文必备宏包
# ctex → 中文支持
# amsmath → 数学公式
# graphicx → 图片
# booktabs → 三线表
# natbib/biblatex → 参考文献
# hyperref → 超链接