LaTeX 入门-语法

LaTeX 入门 - 语法

一、使用 LaTeX 优点

这里首先说明,并不是因为 Word 排版不好才使用 LaTeX。之所以 Word 排版不美观,很大一部分是因为上手太简单,很少有人在使用 Word 时会像学习 LaTeX 时一样逛论坛、看文档,结果排出难看的文档后怪工具不方便。这里只列一下 LaTeX 的优点,并无对 Word 的特意中伤(但从开源角度是可以喷的,这取决于个人的价值观念)。

  • 完全自定义,自主设计,比 Word 更专业的排版超文本标记语言;
  • 设计效率高,不需频繁操作鼠标;
  • 复用性强,利用已有模板可实现快速专业的论文排版;
  • 对数学公式的支持性更好,不会像 Word 跑版;
  • 可更加专注于文章内容本身;
  • 大部分期刊要求 LaTeX 版本;
  • 可进行注释,且不显示在 pdf 中;
  • 不会像 Word 一样崩掉,不会因版本问题跑版;
  • 方便代码插入,可插入热门语言代码;
  • 开源。

二、LaTeX 官方文档

三、LaTeX 常用语法总结

  1. Hello World !
\documentclass{article}%文章类型-article,book,letter等
\title{My first Latex document}%文章标题 
\author{Suancaiyu1806}%作者姓名 
\date{\today}%日期,"\today"表示今天
\begin{document}%文档正文开始 
\maketitle%控制序列,将文字按预定格式打印 

Hello world! 

\end{document}%文档正文结束

在这里插入图片描述

  1. 文章类型

\documentclass[options]{class} 指明文档的类型及格式。

 \documentclass[11pt,twoside,a4paper]{article}
 %[]中参数使用','隔开
 %11pt文章主体字体大小,默认10pt
 %twoside双边编排,奇偶页左右边距相反
 %a4paper文档长宽同A4纸
 %{}中指出文章类型,article为论文格式

文档类型

class 参数文章类型
article论文类型
book书籍类型
letter信件类型
slides幻灯片
IEEEtranIEEE Transactions格式的文章
proc诉讼、议程
minimal主要调试用
report较长的报告
memoir可更改文档的输出类型,基于book
beamer自我介绍、业务陈述

自定义选项

option 参数含义
10pt,11pt,12pt正文字体大小,默认10pt
a4paper, letterpaper…纸张大小
fleqn公式左对齐
leqno公式编号置于公式左
titlepage, notitlepage指定文章标题后是否启用新页面,默认情况下,article类不启动新页面,而report和book启动
onecolumn, twocolumn指定此文件要以单列或双列进行排版
twoside, oneside单、双边编排,奇偶页左右边距相同、相反。book 类默认双边编排
landscape横向打印
openright, openany仅在右侧页或下一页开始新章节,report 默认下一页开始,book 默认右侧页开始
draft草稿模式
  1. 目录

\tableofcontents 添加在导言区,即可显示目录。目录要编译两遍以上才正常:第一遍在.aux 辅助文件中记录位置,第二遍根据辅助文件的内容输出目录。如果目录本身会影响后续内容的页码,那么还要编译第三遍。(因此将配置时的 "latex-workshop.latex.autoClean.run": "onBuilt", 注释掉)

 \documentclass{article}  
 \title{My first Latex document} 
 \author{Suancaiyu1806} 
 \date{\today} 
 \begin{document} 
 \maketitle 
 \tableofcontents%目录添加在导言区
 Hello world! 
 
 \end{document}
  1. 章节、段落
 %边距
 \usepackage{geometry}
 \geometry{a4paper,left=2cm,right=2cm,top=1cm,bottom=1cm}%设置纸张及边距(之前设置过纸张这里可不设置)
 
 %缩进与行间距
 \usepackage{indentfirst}
 \indent 
 
 \linespread{1}%行间距
 
 %章节
 \section{}%一级
 \subsection{}%二级 
 \subsubsection{}%三级
 
 \usepackage[section]{placeins}%这一个包可以避免图或表在浮动时跨过section
 
 \renewcommand\thesection{\chinese{section}}%此句可设置一级章节标题为中文,如:一、一级
 
 %段落
 \paragraph{}%一级
 \subparagraph{}%二级 
 \subsubparagraph{}%三级
 
 %注脚
 \footnote{FootNote}%注脚
 
 %页眉页脚
 \pagestyle{type}%全部页
 \thispagestyle{type}%当前页
 %type: empty-无页眉页脚;
 	%plain-没有页眉,页脚包含一个居中的页码;
 	%headings-没有页脚,页眉包含章/节或者字节的名字和页码;
 	%myheadings-没有页脚,页眉包含有页码
 \setcounter{page}{number}%手动设置页码编号

示例

 \documentclass{article}  
 \title{My first Latex document} 
 \author{Suancaiyu1806} 
 \date{\today} 
 \begin{document} 
 \maketitle 
 \tableofcontents 
 
 \newpage%创建新页面
 
 \section{Chapter 1} 
 \subsection{Section 1} 
 \paragraph{I have a dream that one day this nation will rise up and live out the true meaning of its creed: We hold these truths to be self-evident that all men are created equal.}
 \subsection{Section 2}
 \paragraph{I have a dream that one day on the red hills of Georgia the sons of former slaves and the sons of former slave owners will be able to sit down together at the table of brotherhood.}
 
 \section{Chapter 2} 
 \subsection{Section 1} 
 \paragraph{I have a dream that one day even the state of Mississippi, a state sweltering with the heat of injustice, sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice.} 
 \subsection{Section 2}
 \paragraph{I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character. I have a dream today!}
 
 \end{document}

在这里插入图片描述

  1. 字体
\usepackage{fontspec}%使用fontspec包
\setmainfont{Times New Roman}%设置主字体
\setsansfont{DejaVu Sans}%无衬线字体
\setmonofont{Latin Modern Mono}%等宽字体
\setsansfont{[font.ttf]}%使用当前目录下的字体文件
%%字体大小
\tiny \scriptsize \footnotesize \small \normalsize \large \large \LARGE \huge \Huge

\title{\heiti The First Demo}%标题使用 The First Demo
\author{\kaishu 酸菜鱼}%作者使用楷书
\paragraph{\kaishu 酸菜鱼}%段落使用楷书
\paragraph{\huge I have a dream!}%段落字号huge
  1. 数学公式
Einstein 's $E=mc^2$.   %行内公式
\[ E=mc^2. \]   %行间公式
$m^{n}$ %上标 
$m_{n}$ %下标
\frac{m}{n} %分式,n分之m
\sqrt{} %开平方 
\sqrt[m]{n} %n开m次方
\sum_{i=m}^{n}  %累计求和,从m到n求和
\prod_{i=m}^{n} %累计求积,从m到n求积
\int_{i=m}^{n}  %从m到n积分
\vec a  %a向量 
\overrightarrow{AB} %A到B的向量
a+b+\cdots+z    %a+b++z
\underbrace{a+b+\cdots+z}_{26}  %a+b++z
\overline{m+n}  %m+n公式上面加上横杠 
\underline{m+n} %m+n公式下面加上横杠

%%一行几个公式
\begin{displaymath} 
S_{n+1} = S_{n} + S_{n},  
S_{n}=1=2^{n} 
\end{displaymath}
%%对行间公式进行标号
\begin{equation} 
... 
\end{equation}

在这里插入图片描述

  1. 方程组
$$
\left\{ 
\begin{array}{c}
a_1x+b_1y+c_1z=d_1 \\ 
a_2x+b_2y+c_2z=d_2 \\ 
a_3x+b_3y+c_3z=d_3
\end{array}
\right. 
$$

在这里插入图片描述

  1. 矩阵
\usepackage{amsmath}

$ \begin{matrix} 1 & 2 \\ 3 & 4 \\ \end{matrix} $%默认无括号
$ \begin{pmatrix} 1 & 2 \\ 3 & 4 \\ \end{pmatrix} $%圆括号
$ \begin{bmatrix} 1 & 2 \\ 3 & 4 \\ \end{bmatrix} $%方括号
$ \begin{Bmatrix} 1 & 2 \\ 3 & 4 \\ \end{Bmatrix} $%花括号
$ \begin{vmatrix} 1 & 2 \\ 3 & 4 \\ \end{vmatrix} $%行列式
$ \begin{Vmatrix} 1 & 2 \\ 3 & 4 \\ \end{Vmatrix} $%双竖线

在这里插入图片描述
使用 \cdots ⋯ , \ddots ⋱ , \vdots ⋮ 来输入省略符号

$$
    \begin{pmatrix}
        1      & a_1    & a_1^2  & \cdots & a_1^n  \\
        1      & a_2    & a_2^2  & \cdots & a_2^n  \\
        \vdots & \vdots & \vdots & \ddots & \vdots \\
        1      & a_m    & a_m^2  & \cdots & a_m^n  \\
    \end{pmatrix}
$$
$$
    \left[
        \begin{array}{cc|c}%分列
            1 & 2 & 3 \\
            4 & 5 & 6
        \end{array}
        \right]
$$

This is a line: $\bigl( \begin{smallmatrix} a & b \\ c & d \end{smallmatrix} \bigr)$

在这里插入图片描述

  1. 表格
\usepackage{booktabs}

%%三线表
\begin{table}[htbp]
    \centering
    \caption{\label{tab:test}示例表格}%题注
    \setlength{\tabcolsep}{2cm}{%设置表格宽度
    	\begin{tabular}{rccl}%对齐方式右 中 中 左
        	\toprule
        	head1 & head2 & head3 & head4 \\
        	\midrule
        	1 & 2 & 3 & 4 \\
        	1 & 2 & 3 & 4 \\
        	1 & 2 & 3 & 4 \\
        	1 & 2 & 3 & 4 \\
        	\bottomrule
    	\end{tabular}
   	}
\end{table}

在这里插入图片描述

\usepackage{booktabs}

\begin{table}[htbp]
    \centering
    \caption{\label{tab:test}示例表格}
    \begin{tabular}{|rccl|}%左右有框线
        \hline
        head1 & head2 & head3 & head4 \\
        \hline
        1 & 2 & 3 & 4 \\
        1 & 2 & 3 & 4 \\
        1 & 2 & 3 & 4 \\
        1 & 2 & 3 & 4 \\
        \hline
    \end{tabular}
\end{table}

在这里插入图片描述

\usepackage{amsmath}

$$
\begin{array}{c|lcr}%分列,对齐方式左 中 右
n & \text{左对齐} & \text{居中对齐} & \text{右对齐} \\
\hline
1 & 1 & 2 & 3 \\
2 & 4 & 5 & 6 \\
3 & 7 & 8 & 1+10i
\end{array}
$$

在这里插入图片描述

$$
% outer vertical array of arrays 外层垂直表格
\begin{array}{c}
    % inner horizontal array of arrays 内层水平表格
    \begin{array}{cc}
        % inner array of minimum values 内层"最小值"数组
        \begin{array}{c|cccc}
        \text{min} & 0 & 1 & 2 & 3\\
        \hline
        0 & 0 & 0 & 0 & 0\\
        1 & 0 & 1 & 1 & 1\\
        2 & 0 & 1 & 2 & 2\\
        3 & 0 & 1 & 2 & 3
        \end{array}
        &%同行间
        % inner array of maximum values 内层"最大值"数组
        \begin{array}{c|cccc}
        \text{max}&0&1&2&3\\
        \hline
        0 & 0 & 1 & 2 & 3\\
        1 & 1 & 1 & 2 & 3\\
        2 & 2 & 2 & 2 & 3\\
        3 & 3 & 3 & 3 & 3
        \end{array}
    \end{array}
    % 内层第一行表格组结束
    \\%换行
    % inner array of delta values 内层第二行Delta值数组
        \begin{array}{c|cccc}
        \Delta&0&1&2&3\\
        \hline
        0 & 0 & 1 & 2 & 3\\
        1 & 1 & 0 & 1 & 2\\
        2 & 2 & 1 & 0 & 1\\
        3 & 3 & 2 & 1 & 0
        \end{array}
        % 内层第二行表格组结束
\end{array}
$$

在这里插入图片描述

  1. 图片
 \usepackage{graphicx}%使用graphicx包
   
 \includegraphics[width=3cm]{images/img2.jpg}%引入图片并设置大小
 \caption{Suancaiyu 1806}%题注

在这里插入图片描述

  1. 参考文献
  %%引用参考文献
  \cite{ref1}
  
  %%插入参考文献
  \begin{thebibliography}{99}
      \bibitem{ref1}Suancaiyu. LaTeX 入门.CSDN,202005):0-1.
      \bibitem{ref2}Suancaiyu. LaTeX 入门.CSDN,202005):0-1.
      \bibitem{ref3}Suancaiyu. LaTeX 入门.CSDN,202005):0-1.
      \bibitem{ref4}Suancaiyu. LaTeX 入门.CSDN,202005):0-1.
  \end{thebibliography}

在这里插入图片描述
12. 代码块

 \usepackage{xcolor}%高亮
 \usepackage{listings}%代码块
 \lstset{}%添加代码格式配置,文末%附录%中有有关python代码的配置
 
 \begin{lstlisting}[language=langue]
 \end{lstlisting}

在这里插入图片描述

  1. 插入附录
 \usepackage{appendix}

 \begin{appendices}
 	\section{Appendice 1}
 		\subsection{Appendice}
 	\section{Appendice 2}
 		\subsection{Appendice}
 \end{appendices}

在这里插入图片描述
附录

%%本段是对代码块有关格式配置,可直接添加在文档开始前
\definecolor{mygreen}{rgb}{0,0.6,0}  
\definecolor{mygray}{rgb}{0.5,0.5,0.5}  
\definecolor{mymauve}{rgb}{0.58,0,0.82}  
  
\lstset{ %  
  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}  
  basicstyle=\footnotesize,        % the size of the fonts that are used for the code  
  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace  
  breaklines=true,                 % sets automatic line breaking  
  captionpos=bl,                   % sets the caption-position to bottom  
  commentstyle=\color{mygreen},    % comment style  
  deletekeywords={...},            % if you want to delete keywords from the given language  
  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code  
  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8  
  frame=single,                    % adds a frame around the code  
  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)  
  keywordstyle=\color{blue},       % keyword style  
  %language=Python,                % the language of the code  
  morekeywords={*,...},            % if you want to add more keywords to the set  
  numbers=left,                    % where to put the line-numbers; possible values are (none, left, right)  
  numbersep=5pt,                   % how far the line-numbers are from the code  
  numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers  
  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))  
  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'  
  showstringspaces=false,          % underline spaces within strings only  
  showtabs=false,                  % show tabs within strings adding particular underscores  
  stepnumber=1,                    % the step between two line-numbers. If it's 1, each line will be numbered  
  stringstyle=\color{orange},      % string literal style  
  tabsize=2,                       % sets default tabsize to 2 spaces  
  %title=myPython.py               % show the filename of files included with \lstinputlisting; also try caption instead of title  
}  
  • 27
    点赞
  • 174
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
一份不太简短的 LATEX 2ε 介绍LATEX[1] 是一种排版系统,它非常适用于生成高印刷质量的科技和数学 类文档。这个系统同样适用于生成从简单的信件到完整书籍的所有其他种 类的文档。LATEX 使用 TEX[2] 作为它的格式化引擎。 这份短小的介绍描述了 LATEX 2ε 使用,对 LATEX 的大多数应用来说应 该是足够了。参考文献 [1, 3] 对 LATEX 系统提供了完整的描述。 对大多数计算机,从个人计算机(PC)和 Mac 到大型的 UNIX 和 VMS 系统,LATEX 都有适用版本。在许多大学的计算机机房,你会发现系 统中已经安装了 LATEX 并能够使用。在 Local Guide [4] 中应该提供了关于 如何存储本地的 LATEX 安装的信息。如果你对如何入门有疑问,向提供这 个小册子的人咨询。这份文档的职责不是告诉你如何安装并设置一个 LATEX 系统,而是教你如何编写你的文档,使得它们可以被 LATEX 处理。 这份介绍分成了五个章节: 第一章 告诉你关于 LATEX 2ε 文档的基本结构。你也会了解一点 LATEX 的历 史。阅读这一章后,你应该对 LATEX 有了一个粗略的印象。这个印象 仅仅是一个框架,但是它可以使你整合在其他章节中提供的信息成为 一个完整的画面。 第二章 探究排版文档的细节。它解释了大部分基本的 LATEX 命令和环境。 在阅读完这一章之后,你就能够编写你的第一份文档了。 第三章 解释了如何使用 LATEX 排版公式。同时,大量的例子会帮助你理解 如何使用 LATEX 的一个主要能力。在这个章节的结尾,你会找到列写 了 LATEX 中所有可用的数学符号的表格。
LaTeX是一种专业的排版软件,常被用于书籍、论文、报告等文档的排版。在美赛中,使用LaTeX可以帮助我们更好地展示数学模型和结果。 LaTeX的基本语法包括以下几个方面: 1. 文档结构:使用\documentclass定义文档类型,比如article、report或者book等。然后使用\begin{document}和\end{document}来标记文档的开始和结束。 2. 标题和章节:使用\title、\author、\date等命令定义标题信息,并使用\maketitle命令生成标题。使用\section、\subsection和\subsubsection命令来定义章节和子章节。 3. 数学公式:使用$符号或者\[\]来表示行内和行间的数学公式。使用\begin{equation}和\end{equation}来显示带编号的数学公式。 4. 列表和序号:使用\begin{itemize}和\end{itemize}来创建无序列表,使用\begin{enumerate}和\end{enumerate}来创建有序列表。使用\item命令来标记每一项。 5. 图片和表格:使用\includegraphics命令来插入图片,使用\begin{figure}和\end{figure}来设置图片的位置和标题。使用\begin{tabular}和\end{tabular}来创建表格,使用\hline来画水平线。 6. 参考文献:使用\begin{thebibliography}和\end{thebibliography}来创建参考文献列表。使用\cite命令在正文中引用文献。 总之,掌握LaTeX的基本语法有助于我们在美赛中更好地描述问题、推导公式和展示结果,提高报告的专业性和可读性。在实践中,通过不断的练习和尝试,我们可以逐渐熟悉和掌握LaTeX的使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SuanCaiyu1806

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值