LaTeX常用语法

本文详细介绍了LaTeX的常用语法,包括字体样式设置、空格表示、Solution缩进、枚举格式、数学公式、图片插入、伪代码书写、表格制作等内容,是 LaTeX 学习者的实用参考。
摘要由CSDN通过智能技术生成
1. 设置字体居中、颜色及粗体,斜体
\usepackage{xcolor}
\begin{center}
{
	\color{blue} 
	\textbf{balabala\hspace{1cm} balabala}
	\emph{balabala}
}
\end{center}

设置字体大小:
font

2. 空格的表示

\, 表示空格

\hspace{ 长度 } , 例如 \hspace{1cm}

在数学环境中($........$$$..........$$)生成空格, 则可以使用下面的命令:

两个quad空格 a \qquad b 两个m的宽度

quad空格 a \quad b 一个m的宽度

大空格 a\ b 1/3m宽度

中等空格 a\;b 2/7m宽度

小空格 a\,b 1/6m宽度

紧贴 a\!b 缩进1/6m宽度

3. Solution中进行缩进

引用包:

\usepackage{indentfirst}

然后在\begin{solution}...\end{solution}等环境中使用:

\setlength{\parindent}{2em}

\noindent表示取消首行缩进

4. 枚举格式
\usepackage{enumerate}
\begin{enumerate}[i]
	\item Xidian
	\item Computer
	\item Application
\end{enumerate}

可以使用 AaIi1 作为可选项产生 \Alph\alph\Roman\roman\arabic 的效果。

这两种方式貌似不能并存:

\begin{enumerate}
	\item[(A)] 图灵机是一种抽象的计算模型,它的计算能力与带有两个栈的下推自动机相同。
	\item[(B)] 冯氏机的计算能力的上限由图灵机模型决定。
	\item[(C)] 图灵机是对计算过程的模拟,冯氏机是其工程化实现。
	\item[(D)] 图灵机的下一步的操作完全取决于当前所读取单元格的符号。
\end{enumerate}}

枚举中的缩进

\begin{enumerate}[fullwidth,itemindent=2em]
\end{enumerate}.

1
2

5. 数学公式
\begin{equation}
	T(m)=
	\left\{
	\begin{array}{ll}
	1, & \mbox{\emph{succeed}}\\
	1+T(m'), & \mbox{\emph{failed}}\\
	\end{array}
	\right.
\end{equation}

注意一般使用\left\{来使中括号随内容的扩大而变大,但是\left\right必须配对存在,如果没有配对的中括号,使用\right.进行配对。

求和运算符:
3

向量写法:

\usepackage{esvect}
\vv{a}

分数

\frac{1}{(k+\_)^2}

根号

\sqrt
6. 插入图片

插入一幅图片

\usepackage{graphicx}

\begin{figure}[htbp]
\centering
\includegraphics[width=0.9\textwidth]{Fig-Linearization.pdf}
\caption{$\omega \times \omega \rightarrow \omega$线性化曲线} 
\label{fig-Linearization}
\end{figure}

插入两幅并排图片

\begin{figure}[htbp]
\center
\begin{minipage}[h]{0.46\textwidth}
\centering
\includegraphics[width=\textwidth]{fig-Projection.pdf}
\caption{Matlab示例图片} \label{fig-Projection}
\end{minipage}
\hspace{5mm}
\begin{minipage}[h]{0.46\textwidth}
\centering
\includegraphics[width=\textwidth]{Fig-1b.pdf}
\caption{1b题图片} \label{fig-1b}
\end{minipage}
\end{figure}

插入三幅并排图片

\begin{figure}[htbp]
\hspace{1.5cm}
\begin{minipage}[h]{0.25\textwidth}
\centering
\includegraphics[width=0.9\textwidth]{Fig-Linearization.pdf}
\caption{$\omega \times \omega \rightarrow \omega$线性化曲线} 
\label{Fig-Linearization}
\end{minipage}
\hspace{5mm}
\begin{minipage}[h]{0.28\textwidth}
\centering
\includegraphics[width=\textwidth]{Fig-Projection.pdf}
\caption{Matlab示例图片} \label{Fig-Projection}
\end{minipage}
\hspace{5mm}
\begin{minipage}[h]{0.28\textwidth}
\centering
\includegraphics[width=\textwidth]{Fig-1b.pdf}
\caption{1b题图片} \label{Fig-1b}
\end{minipage}
\end{figure}

插入两幅子图(subfigure)

\usepackage{graphicx}
\usepackage{subcaption}

\begin{figure*}
\centering
    \begin{subfigure}[b]{0.5\textwidth}
            \includegraphics[width=\columnwidth]{figures/mst-train-1.png}
            \caption{Training accuracy.}
            \label{fig-rnn-train1}
    \end{subfigure}%
    \hspace{5mm}
    \begin{subfigure}[b]{0.5\textwidth}
            \centering
            \includegraphics[width=\columnwidth]{figures/mst-test-1.png}
            \caption{Testing accuracy.}
            \label{fig-rnn-test1}
    \end{subfigure}
    \caption{Accuracies in first ten training epochs.}\label{fig-first10}
\end{figure*}

另一种写法:

\usepackage{subfigure}

\begin{figure}
\centering
\begin{minipage}[h]{.80\columnwidth}
\subfigure[Horizontal Splitting]{
\includegraphics[width=.9\textwidth]{pic/h-splitting.pdf}}
\subfigure[Vertical Splitting]{
\includegraphics[width=.9\textwidth]{pic/v-splitting.pdf}}
\caption{\label{fig-intro}Examples of horizontal and vertical splitting.}
\end{minipage}
\end{figure}

去掉图片编号

\usepackage{caption}

图片中图片标题使用\catpion*{fig-name}语句

7. 伪代码书写
\begin{minipage}[t]{0.48\textwidth}
\begin{algorithm}[H]
\caption{伪代码}
\KwIn{$x$, $y$}
\KwOut{$x$, $y$}
\BlankLine
Receive(M)\;
\eIf{$cur = dest$}{
	$Accept(M)$\;
}
{
	\While{$dest/2>cur$}{
		$Dest=dest/2$\;
	}
}
\textbf{output} $x$, $y$\;
\end{algorithm}
\end{minipage}

第二种写法

\usepackage[vlined,ruled,commentsnumbered,linesnumbered]{algorithm2e}

\begin{minipage}[t]{0.48\textwidth}
\begin{algorithm}[H]
\label{alg1}
\BlankLine
\caption{INTERSECT($p_1$, $p_2$)}
\BlankLine
$answer \leftarrow ()$ \\
\While{$p_1 \neq NIL$ \textbf{and} $p_2 \neq NIL$}{
	\If{$docID(p_1) = docID(p_2)$}{
		ADD($answer$, $docID(p_1)$)\
		$p_1 \leftarrow next(p_1)$\
		$p_2 \leftarrow next(p_2)$\
	}
	\Else{
		\If{$docID(p_1) < docID(p_2)$}{
			$p_1 \leftarrow next(p_1)$\
		}
		\Else{
			$p_2 \leftarrow next(p_2)$
		}
	}
}
\Return $answer$
\end{algorithm}
\end{minipage}

4
带END

\usepackage[ruled,lined,boxed,linesnumbered]{algorithm2e}

不带END

\usepackage[vlined,ruled,commentsnumbered,linesnumbered]{algorithm2e}
8. 西文字符转换表

\rm 罗马字体 \it 意大利字体

\bf 黑体 \sl 倾斜体

\sf 等线体 \sc 小体大写字母

\tt 打字机字体 \mit 数学斜体

9. 字号转换命令表

点数(pt) 相应中文字号 控制命令

25 一号 \Huge

20 二号 \huge

17 三号 \LARGE

14 四号 \Large

12 小四号 \large

10 五号 \normalsize

9 小五号 \small

8 六号 \footnotesize

7 小六号 \scriptsize

5 七号 \tiny

10. 矩阵

可以参考这个链接:http://www.360doc.com/content/10/0924/14/175261_55980937.shtml

5


6


7


8


9

11. array属性设置

10

12. 括号控制

在latex下编辑公式时,经常会用到各种括号。如果直接输入括号(花括号需要进行转义),其大小是固定的,如果公式的高度比较大,就会显得很不协调。另外,在括号中换行的话有可能会导致两行的左右括号大小不一致,影响美观。

使用\left\right:

\left 放在左边括号前面,\right 放在右边括号前面。

需要配对使用;能自动控制不同层次括号的大小;需要注意的是在对单括号使用 \left\right命令时,也需要配对使用,没有括号的一端要加点。

比如对左括号进行操作,命令如下

\left[.........\right.
13. 表格制作

第一种写法

\begin{center}
\begin{tabular*}{10cm}{p{3cm}<{\centering} p{3cm}<{\centering} p{3cm}<{\centering}}
dimension 1 & dimension 2 & class\\
-0.0978 & 0.5476 & 1\\
0.0978 & -0.5476 & 0
\end{tabular*}
\end{center}

第二种写法

\begin{center}
\begin{tabular*}{8cm}{p{2cm} p{2cm} p{2cm} p{2cm}}
$P$ & $Q$ & $A$ & $B$  \\
\hline
$F$ & $F$ & $T$ & $T$  \\
$F$ & $T$ & $T$ & $F$  \\
\hline
\end{tabular*}
\end{center}

不带标题,居中

\begin{center}
\begin{tabular}{c|ccccc}
$\alpha$       & 0.01 & 0.05 & 0.08 & 0.1 & 1.8 \\
\cline{1-6}
Accuracy       & 63.54\% & 100.0\% & 100.0\% & 98.96\% & 71.88\% \\
Time  & 16.12 & 16.03 & 15.62 & 16.15 & 16.14 \\
\end{tabular}
\end{center}

带标题,居中

\begin{table}
\center
\caption{the Performance of One-versus-one}
\begin{tabular}{c|cc }
Kernel Func       & Time-consuming & Accuracy \\
\cline{1-3}
Linear       & 3.09 s & 63.6\%   \\
RBF  & 1.86 s & 70.8\% \\
\end{tabular}
\end{table}

tabular貌似不能加标题,外面套一层table才能正常加标题

详情可参考http://jingyan.baidu.com/article/4e5b3e193198f791901e24e0.html

14. 花体字
\mathcal{ABC..}

11

15. 粘贴源代码
\usepackage{listings}

\begin{lstlisting}[language=C++,numbers=left, numberstyle=\tiny,keywordstyle=\color{blue!70},
commentstyle=\color{red!50!green!50!blue!50},frame=shadowbox, rulesepcolor=\color{red!20!green!20!blue!20},escapeinside='']	
#include <iostream>
using namespace std;
int main(){
	int k = 0;
}
\end{lstlisting}

标题,子标题

\documentclass{article} 
\usepackage{ctex}       %载入中文包
\begin{document}
\section{第一部分}
写点什么吧。
\subsection{第一部分的二小部分}
say hello.

\section*{第二部分}
再写点什么吧。

\end{document}

12

16. 波浪线
\sim
  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值