latex的基本使用

LaTeX使用

基本使用

  • sublime使用latex格式来编辑文件,使用command+B来编译文件,这时候通过skim来浏览生成的PDF文件。
  • 终端里面通过使用latex demo.tex来编译latex生成包括demo.dvi在内的许多文件,这个时候用dvipdfmk demo.dvi命令转成PDF。
  • 终端里面通过使用xelatex demo.tex直接生成PDF文件。还支持中文
    支持中文需要xelatex,utf-8编码,导入ctex包
  • 使用TexStudio来使用Latex

源文件的基本结构

  • Latex里面有文稿区,正文区
  • Latex里面不用显示的内容默认用注释而不是删除
  • \后面跟的都是关键字
  • 一个$包围表示行内数学公式
  • 两个$包围表示行间数学公式
  • 文档类里面有book,report,letter,ctexreport,ctexbook等文档类
%导言区
\documentclass{article} %book,report,letter
\usepackage{ctex}
\title{Latex Introduction}
\author{Shu Kai}
\date{\today}
%文稿区
\begin{document}
    \maketitle
    你好 \LaTeX.

    Here is a formula$f(x)=x^2+2x+1$

    Here is an another formula$$f(x)=2x$$which $x$ denote independent variable.
\end{document}

中文处理办法

  • 命令行中使用texdoc ctex可以查看ctex的使用方法,或者使用texdoc lshort-zh来查看latex的简短的中文介绍。
  • 使用\heiti,\kaishu来选择不同的字体
  • 使用eqution来产生具有序号的数学公式
  • 使用\newcommand\yourcmd{xxxcmd}来定义自己的command
  • 使用ctex开头的文档类,可以不用引入ctex包
%导言区
\documentclass{ctexart} %book,report,letter
%\usepackage{ctex} %or use \documentclass{ctexart}
\title{Latex Introduction}
\newcommand\degree{^\circ}
\author{\heiti 舒凯}
\date{\today}
%文稿区
\begin{document}
	\maketitle
	你好 \LaTeX.
	$C=90\degree$
	\begin{equation}
		AB=BC=CA
	\end{equation}
\end{document}

字体字号设置

下图是Latex的字体属性
latex
* 字体族,对于latex中的字体可以使用不同的字体族,比如说有罗马字体,san serif字体(无衬线字体),typerwriter字体。
* 对于字体的使用可以用命令或者用定义。对于命令有一个括号作为限定范围,对于定义可以有括号也可以没有括号,没有括号表示接下去的内容全部是该字体。
* 我们可以在引言区用newcommand设置自己的字体。

\documentclass{article}
\usepackage{ctex}
\newcommand{\myfont}{\textbf{\textsf{ss}}}
\begin{document}
    %字体族设计 罗马字体 无衬线字体 打印机字体
    \textrm{Roman Family}  \textsf{Sans Serif Family} \texttt{TypeWriter Family}
    %以下的命令表示后续字体的字体族

    \rmfamily{Roman Family} 
    \sffamily{Sans Serif Family} 
    \ttfamily{TypeWriter Family}

    %字体系列设置(粗细,宽度)
    \textmd{Medium Series} \textbf{BoldFace Series}

    %字体形状(直立,斜体,伪斜体,小型大写)
    \textup{Upright Shape} \textit{Italic Shape}
    \textsl{Slanted Shape} \textsc{Small Caps Shape}

    %中文字体
    {\songti 宋体} {\heiti 黑体} {\fangsong 仿宋} {\kaishu 楷书}

    %字体大小设置
    {\tiny                   Hello}\\
    {\scriptsize                   Hello}\\ 
    {\footnotesize                   Hello}\\
    {\small                   Hello}\\
    {\normalsize                   Hello}\\
    {\large                   Hello}\\
    {\Large                   Hello}\\
    {\LARGE                   Hello}\\
    {\huge                   Hello}\\
    {\Huge                   Hello}\\

    %中文字号设置
    \zihao{5} 你好

    \myfont

\end{document}

文章基本结构

  • 对于article类的文档来说里面有section,subsection,subsubsection等等命令。对于book类的文档来说,有chapter,section等,此时subsection和subsubsection等等命令就不能发挥作用
  • 可以在文档区也就是正文区的前面使用tableofcontents这个命令
  • 利用好引言区,尽量在引言区里面设置好格式。
\documentclass{book}
\usepackage{ctex}
\begin{document}
	\tableofcontents
	\section{引言}
	\section{摘要}
	\section{实验}
	\subsection{实验}
	\subsubsection{图表}
	\chapter{章节}
	\section{引言}
	\section{摘要}
	\section{实验}
	\subsection{实验}
	\subsubsection{图表}
\end{document}

特殊字符处理

\documentclass{book}
\usepackage{ctex}
\usepackage{xltxtra}
\usepackage{texnames}
\usepackage{mflogo}
\begin{document}
    \section{空白字符}
    %空行分段,多个空行等于一个空行
    %自动缩进,绝对不能使用空格代替
    %英文中多个空格为一个空格,中文中空格无效
    %汉字与其它字符的间距会自动由XeLeTex自动处理
    %禁止使用中文全角空格
    Are you      OK!

    我爱      你!Do you love me !滚

    %1em(相当于字体中M的宽度)
    a\quad b

    %2em
    a\qquad b

    %约为1/6个em
    a\,b a\thinspace b

    %0.5em
    a\enspace b

    %空格
    a\ b

    %硬空格 不能分割的空格
    a~b

    %1pc=12pt=4.218mm
    a\kern 1pc b

    a\kern -1em b

    a\hskip 1em b

    %根据参数留出空白
    a\hspace{35pt}b

    %根据xyz的宽度得到占位宽度的空白
    a\hphantom{xyz}b

    %弹性宽度
    a\hfill b
    \section{\LaTeX 控制符}
    %双反斜杠表示换行,所以要显示反斜杠需要用\textbackslash
    \# \$ \% \{  \}  \~{} \_{} \^{} \textbackslash \&
    \section{排版符}
    \S \P \dag \ddag \copyright \pounds
    \section{\TeX 标志符号}
    %基本符号
    \TeX \LaTeX \LaTeXe

    %XeLaTex符号,使用xltxtra宏包
    \XeLaTeX

    %texnames宏包提供
    \AmSTeX{} \AmS-\LaTeX{}
    \BibTeX{} \LuaTeX{}

    %由mflogo提供
    \METAFONT{} \MF{} \MP{}
    \section{引号}
    ` ' `` ''   ``你好''
    \section{连字符}
    - -- ---
    \section{非英文字符}
    \oe \OE \ae \AE \aa \AA \o \O \l \L \ss \SS !` ?`
    \section{重音符号}
    \`o \'o \^o \' 'o \~o \=o \.o \u{o} \v{o} \H{o} \r{o} \t{o} \b{o}
    \c{o} \d{o}
    \section{实验}
    \subsubsection{图表}
\end{document}

效果输出:
1
2

图片的使用

  • 需要在导言区里面导入graphicx这个包
  • 插入图片的时候,使用以下命令,\includegraphics[<选项>]{文件名}
  • 支持以下格式的图片 EPS,PDF,PNG,JPEG,BMP,在导入图片的时候可以不用加后缀名。
  • 选项有scale,width,height,angle等选项,而且支持相对值
\documentclass{article}
\usepackage{ctex}
%导言区 \usepackage{graphicx}
%语法 \includegraphics[<选项>]{文件名}
%格式 EPS,PDF,PNG,JPEG,BMP
\usepackage{graphicx}
\graphicspath{{figures/},{pics/}} %图片在当前目录下的figures目录

%正文区(文稿区)
\begin{document}
	\LaTeX{} 中的插图
	\includegraphics{1.png}
	\includegraphics{2.png}
	\includegraphics{3.png}
	\includegraphics[scale=0.3]{1.png}
	\includegraphics[scale=0.5]{2.png}
	\includegraphics[scale=0.8]{3.png}
	\includegraphics[width=1cm]{1.png}
	\includegraphics[width=2cm]{2.png}
	\includegraphics[width=3cm]{3.png}
	\includegraphics[height=1cm]{1.png}
	\includegraphics[height=2cm]{2.png}
	\includegraphics[height=3cm]{3.png}
	\includegraphics[width=0.1\textwidth]{1.png}
	\includegraphics[width=0.2\textwidth]{2.png}
	\includegraphics[width=0.3\textwidth]{3.png}
	\includegraphics[height=0.1\textheight]{1.png}
	\includegraphics[height=0.2\textheight]{2.png}
	\includegraphics[height=0.3\textheight]{3.png}
	\includegraphics[angle=-45,width=0.2\textwidth]{1.png}
	\includegraphics[width=0.2\textwidth]{2.png}
	\includegraphics[angle=45,width=0.2\textwidth]{3.png}
\end{document}

表格的使用(Texstduio的导入表格功能会更快)

  • 在begin和end里面使用tabular可以创建表格
  • l,c,r 左,中,右;p指示宽度,不够就换行
  • \\表示换行
  • \hline表示行线,可以有多个叠加
  • |是竖线,可以有多个叠加
\documentclass{article}
\usepackage{ctex}

%正文区(文稿区)
\begin{document}
    \LaTeX{} 中的表格

    \begin{tabular}{l|c|c|p{1.5cm}|r} %l,c,r 左,中,右;p指示宽度,不够就换行
		\hline %使用两个\hline表示双横线
		姓名 & 语文 & 数学 & 英语 & 备注 \\ % \\表示换行
		\hline 
		张三 & 90 & 86 & 93 & 优秀 \\
		\hline
 		李四 & 60 & 70 & 80 &\\
 		\hline
 		王五 & 50 & 80 & 66 &\\
 		\hline
	\end{tabular}

\end{document}

浮动体的使用

  • 浮动体可以实现灵活分页,比如figure,table(避免无法分割的内容产生的页面的空白)
  • 给图表添加标题
  • 交叉引用
  • 允许位置的参数,h(here),表示此处,代码所在的上下文位置;t(top)代码所在页面或之后页面的顶部;b(bottom)代码所在页面或之后页面的底部;p(page)独立页面——浮动页面
  • 标题控制,caption,bicaption等宏包
  • 并排与子图表 subcaption,subfig,floatrow等宏包
  • 绕排 picinpar,wrapfig等宏包
\documentclass{article}
\usepackage{ctex}
\usepackage{graphicx}
\graphicspath{{figures/}}
%正文区(文稿区)
\begin{document}
    \LaTeX{} 中的图片,如图\ref{天线} 所示%交叉引用
    \begin{figure}[htbp] %允许位置
        \centering
        \includegraphics[scale=0.3]{1}
        \caption{天线衰减图}\label{天线}
    \end{figure}

    以下是2014年我们班的成绩,如表格\ref{grade}所示

    \begin{table}[h]
		\centering
		\caption{成绩单}\label{grade}
			\begin{tabular}{l|c|c|p{1.5cm}|r} %l,c,r 左,中,右;p指示宽度,不够就换行
			\hline %使用两个\hline表示双横线
			姓名 & 语文 & 数学 & 英语 & 备注 \\ % \\表示换行
			\hline 
			张三 & 90 & 86 & 93 & 优秀 \\
			\hline
			李四 & 60 & 70 & 80 &\\
			\hline
			王五 & 50 & 80 & 66 &\\
			\hline
		\end{tabular}
	\end{table}
\end{document}

数学公式初步

  • 行内数学用 , $
  • 希腊字母用相应的发音
  • 注意交叉引用
  • \frac{}{}用来表示分式
\documentclass{article}
\usepackage{ctex}
\usepackage{graphicx}
\graphicspath{{figures/}}
%正文区(文稿区)
\begin{document}
\section{行内公式}
\subsection{美元符号}
交换公式是$a+b=b+a$所示
\subsection{小括号}
交换公式是\(a+b=b+a\)所示
\subsection{math环境}
交换公式是\begin{math}a+b=b+a\end{math}所示
\section{上标}
$a^2$
\section{下标}
$a_2$
\section{希腊字母}
$\alpha$
$\beta$
$\gamma$
$\epsilon$
$\pi$
$\omega$

$\Gamma$
$\Delta$
$\Theta$
$\Pi$
$\Omega$
\section{数学函数}
$\log$
$\sin$
$\cos$
$\arcsin$
$\arccos$
$\ln$

$\sin^2 x+\cos^2 x=1$

$y=\sin^{-1} x$

$y=\sqrt{2}$

$y=\sqrt[4]{5x}$
\section{分式}
体积大约是原来的$3/4$
体积大约是原来的$\frac{5}{100}$
\section{行间公式}
\subsection{美元符号}
交换律是
$$a+b=b+a$$$$1+2=2+1=3$$
\subsection{中括号}
\[a+b=b+a\]
如
\[1+2=2+1=3\]
\subsection{displaymath环境}
\begin{displaymath}
	1+2=2+1=3
\end{displaymath}
\subsection{自动编号公式equation环境}
交换律见式\ref{eq:commutative}
\begin{equation}
	a+b=b+a \label{eq:commutative}
\end{equation}
公式的编号与交叉引用是自动实现的,大家在排版中,要习惯采用自动化的方式处理诸如图,表,公式的编号与交叉引用。
\end{document}

矩阵的使用(TexStudio里面的矩阵模板功能)

参考文献(使用BibTex)

一次管理,一次使用,thebibliography环境(不推荐),推荐使用BibTex文件把文献单独管理,方便后续使用

\documentclass{article}
\usepackage{ctex}

%正文区(文稿区)
\begin{document}
%一次管理,一次使用,
%参考文献格式
%\begin{thebibliography}{widestlabel}
%  \bibitem[记号]{引用标志}文献条目1
%  \bibitem[记号]{引用标志}文献条目2
%  ...
%\end{thebibliography}
%其中文献条目包括:作者,题目,出版社,年代,版本,页码等
%引用文章的使用采用: \cite{引用标志1,引用标志2}
\end{document}
  • 自己编辑一个bib文件,然后进行引用,或者用google学术搜索,然后点击引用的按钮,选择BibLatex的格式

下面是一个Bib文件

@BOOK{mittebach2004,
title={The {{\LaTeX}} Companion},
publisher = {Addison-Wesley},
year={2004},
author={Frank Mittelbach and Michel Goossens},
series={Tools and Techniques for Computer Typesetting},
address={Boston},
edition={Second}
}
@article{comaniciu2003kernel,
    title={Kernel-based object tracking},
    author={Comaniciu, Dorin and Ramesh, Visvanathan and Meer, Peter},
    journal={IEEE Transactions on pattern analysis and machine intelligence},
    volume={25},
    number={5},
    pages={564--577},
    year={2003},
    publisher={IEEE}
}

然后引入该文件,并在相应的地方进行引用

\documentclass{article}
\usepackage{ctex}
\bibliographystyle{plain} %plain unsrt alpha abbrv
%正文区(文稿区)
\begin{document}
%一次管理,一次使用,
%参考文献格式
%\begin{thebibliography}{widestlabel}
%  \bibitem[记号]{引用标志}文献条目1
%  \bibitem[记号]{引用标志}文献条目2
%  ...
%\end{thebibliography}
%其中文献条目包括:作者,题目,出版社,年代,版本,页码等
%引用文章的使用采用: \cite{引用标志1,引用标志2}
\bibliography{literacy}
\cite{mittebach2004}
\cite{comaniciu2003kernel}
\end{document}

定义自己的命令

  • 使用newcommand命令来定义自己的命令
  • 可以在方括号里面设置默认参数,然后默认参数在花括号里面放在第一个
\documentclass{article}
\usepackage{ctex}
\newcommand\PRC{Public of \emph{China}}
%最多有9个#的参数
\newcommand\loves[2]{#1 喜欢 #2}
\newcommand\hatedby[2]{#1 不受 #2 喜欢}
%默认参数,放第一个位置
\newcommand\love[3][喜欢]{#2#1#3}
%正文区(文稿区)
\begin{document}
\PRC

\loves{猫}{鱼}

\hatedby{狗}{猫}

\love{猪}{喜欢}{狗}
\end{document}
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值