引言
LaTeX 是学术界公认的专业排版系统,尤其在数学、物理、计算机科学等领域被广泛使用。本文将介绍一些进阶技巧,帮助你写出更专业的学术论文。
1. 自定义命令与环境
1.1 自定义数学命令
为了提高写作效率和保持符号一致性,我们可以定义常用的数学命令:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 \newcommand {\R }{\mathbb {R}} \newcommand {\N }{\mathbb {N}} \newcommand {\Z }{\mathbb {Z}} \newcommand {\C }{\mathbb {C}} \newcommand {\bvec }[1]{\boldsymbol {#1 }} \newcommand {\norm }[1]{\left \| #1 \right \| } \newcommand {\inner }[2]{\langle #1 , #2 \rangle } \newcommand {\pdv }[2]{\frac {\partial #1 }{\partial #2 }}\newcommand {\ddv }[2]{\frac {d #1 }{d #2 }}
使用示例:对于 f : R n → R f: \R^n \to \R f : R n → R ,其梯度为:
\nabla f = \left( \pdv{f}{x_1}, \pdv{f}{x_2}, \ldots, \pdv{f}{x_n} \right)
1.2 带参数的命令
1 2 3 4 5 6 7 8 \newcommand {\integral }[4][\infty ]{ \int _ {#2 }^ {#1 } #3 \, d#4 } \integral {0}{f(x)}{x} \integral [\pi ]{0}{\sin x}{x}
2. 定理环境配置
2.1 使用 amsthm 包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \usepackage {amsthm}\theoremstyle {plain} \newtheorem {theorem}{定理}[section]\newtheorem {lemma}[theorem]{引理}\newtheorem {proposition}[theorem]{命题}\newtheorem {corollary}[theorem]{推论}\theoremstyle {definition} \newtheorem {definition}[theorem]{定义}\newtheorem {example}[theorem]{例}\theoremstyle {remark} \newtheorem *{remark}{注} \newtheorem *{note}{注意}
2.2 自定义证明环境
1 2 3 4 5 6 7 8 9 10 11 12 \renewcommand {\qedsymbol }{$ \blacksquare $ }\renewenvironment {proof}[1][证明]{ \par \pushQED {\qed } \normalfont \topsep 6\p@ \@plus 6\p@ \relax \trivlist \item [\hskip \labelsep \textbf {#1 .}]\ignorespaces }{ \popQED \endtrivlist \@endpefalse }
3. 参考文献管理
3.1 BibTeX 基础
创建 references.bib 文件:
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 @article{einstein1905, author = {Einstein, Albert}, title = {Zur Elektrodynamik bewegter Körper}, journal = {Annalen der Physik}, volume = {322}, number = {10}, pages = {891--921}, year = {1905}, doi = {10.1002/andp.19053221004} } @book{rudin1976, author = {Rudin, Walter}, title = {Principles of Mathematical Analysis}, publisher = {McGraw-Hill}, year = {1976}, edition = {3rd}, isbn = {978-0-07-054235-8} } @inproceedings{lecun1998, author = {LeCun, Yann and Bottou, Léon and Bengio, Yoshua and Haffner, Patrick}, title = {Gradient-based learning applied to document recognition}, booktitle = {Proceedings of the IEEE}, volume = {86}, number = {11}, pages = {2278--2324}, year = {1998} }
3.2 使用 biblatex
推荐使用现代的 biblatex 包:
1 2 3 4 5 6 7 8 9 10 11 12 \usepackage [ backend=biber, style=numeric, sorting=nyt, maxbibnames=3, maxcitenames=2, ]{biblatex} \addbibresource {references.bib}\printbibliography [title={参考文献}]
4. 图表绘制
4.1 TikZ 基础
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 \usepackage {tikz}\usetikzlibrary {arrows.meta, calc, positioning}\begin {tikzpicture} \draw [->] (-0.5,0) -- (4,0) node[right] {$ x$ }; \draw [->] (0,-0.5) -- (0,3) node[above] {$ y$ }; \draw [thick, blue, domain=0:3.5, samples=100] plot (\x , {0.5*\x *\x - 0.1*\x *\x *\x }); \node at (2.5, 2) {$ f(x) = \frac {1}{2}x^ 2 - \frac {1}{10}x^ 3$ }; \end {tikzpicture}
4.2 绘制神经网络图
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 \usetikzlibrary {chains, fit, backgrounds}\begin {tikzpicture}[ node distance=1cm, neuron/.style={circle, draw, minimum size=0.8cm}, input/.style={neuron, fill=green!20}, hidden/.style={neuron, fill=blue!20}, output/.style={neuron, fill=red!20}, ] \foreach \i in {1,2,3} { \node [input] (i\i ) at (0, -\i ) {$ x_ \i $ }; } \foreach \j in {1,2,3,4} { \node [hidden] (h\j ) at (2, -\j +0.5) {}; } \foreach \k in {1,2} { \node [output] (o\k ) at (4, -\k -0.5) {$ y_ \k $ }; } \foreach \i in {1,2,3} { \foreach \j in {1,2,3,4} { \draw [->] (i\i ) -- (h\j ); } } \foreach \j in {1,2,3,4} { \foreach \k in {1,2} { \draw [->] (h\j ) -- (o\k ); } } \end {tikzpicture}
5. 算法排版
5.1 使用 algorithm2e
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 \usepackage [ruled, linesnumbered]{algorithm2e}\begin {algorithm}[H] \caption {梯度下降算法} \KwIn {初始点 $ x_ 0$ ,学习率 $ \eta $ ,迭代次数 $ T$ } \KwOut {近似最优解 $ x^ *$ } $ x \gets x_ 0$ \; \For {$ t = 1$ \KwTo $ T$ }{ $ g \gets \nabla f(x)$ \; $ x \gets x - \eta \cdot g$ \; \If {$ \| g\| < \epsilon $ }{ \textbf {break}\; } } \Return {$ x$ }\; \end {algorithm}
6. 实用技巧
6.1 交叉引用
1 2 3 4 5 \usepackage {cleveref} 如\cref {thm:main}所示... 由\cref {eq:euler,eq:newton}可知...
6.2 单位排版
1 2 3 4 5 6 \usepackage {siunitx}速度为 \SI {3e8}{m/s} 质量为 \SI {9.109e-31}{kg} 温度为 \SI {273.15}{K}
6.3 代码高亮
1 2 3 4 5 6 7 8 9 \usepackage {minted}\begin {minted}[linenos, frame=lines]{python}def gradient_descent(f, x0, lr=0.01, epochs=1000): x = x0 for _ in range(epochs): x = x - lr * gradient(f, x) return x \end {minted}
推荐模板结构
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 \documentclass [11pt, a4paper]{article}\usepackage [utf8]{inputenc}\usepackage [T1]{fontenc}\usepackage {amsmath, amsthm, amssymb}\usepackage {graphicx}\usepackage {hyperref}\usepackage {tikz}\usepackage {algorithm2e}\usepackage {booktabs}\usepackage {siunitx}\usepackage {cleveref}\usepackage [backend=biber]{biblatex}\input {macros.tex}\input {theorems.tex}\begin {document}\title {论文标题}\author {作者名}\date {\today }\maketitle \begin {abstract}摘要内容... \end {abstract}\tableofcontents \section {引言}... \printbibliography \end {document}
总结
掌握 LaTeX 进阶技巧可以显著提高论文写作效率:
自定义命令 :保持符号一致性,减少重复输入
定理环境 :规范化数学文档结构
参考文献 :使用 biblatex 实现自动化管理
图表绘制 :TikZ 可以绑制出版级质量的图形
算法排版 :清晰展示算法流程
参考资料