LaTeX学习记录

LaTeX下载安装

详细的操作说明请看这个Install-LaTeX.pdf
只需要最后在Options>Configure texstudio>General>language>zh-cn改换成中文环境

LaTeX介绍

LaTeX(LATEX,音译“拉泰赫”)是一种基于ΤΕΧ的排版系统,由美国计算机学家莱斯利·兰伯特(Leslie Lamport)在20世纪80年代初期开发,利用这种格式,即使使用者没有排版和程序设计的知识也可以充分发挥由TeX所提供的强大功能,能在几天,甚至几小时内生成很多具有书籍质量的印刷品。对于生成复杂表格和数学公式,这一点表现得尤为突出。因此它非常适用于生成高印刷质量的科技和数学类文档。这个系统同样适用于生成从简单的信件到完整书籍的所有其他种类的文档。

  • 分为导言区\documentclass{文章类型}

  • 必须以\begin{document}开头,以\end{document}结束

  • 控制序列可以是作为命令:以\开头,参数:必须参数{}和可选参数[]

  • LATEX可以排版公式与文字,分为:数学模式和文本模式。

  • 如果你想要在公式中排版普通的文本(直立字体和普通字距),那么你必须要把这些文本放在\textrm{...} 命令中

LaTeX编译

首先,以下两种形式都可以

\documentclass{ctexart}
\begin{document}
hello LaTeX
\end{document}

或者

\documentclass{article}
\usepackage{ctex}
\begin{document}
hello LaTeX
\end{document}

LaTeX的字体属性

字体编码

  • 正文字体编码:OT1,T1,EU1等

  • 数学字体编码:OML,OMS,OMX等

字体族

  • 罗马字体(Roman Family):笔画起始处有装饰

  • 无衬线字体(Sans Serif Family):笔画起始处无装饰

  • 打字机字体(Typewriter Family):每个字符宽度相同(又称等宽字体)

    \text--:字体命令(作用于命令的参数)

    \--family:字体声明(作用于后续的文本)

    可以用大括号对文本进行分组,从而限定字体声明的范围

\documentclass{ctexart}
  \begin{document}
  
  \textrm{Roman Family}
  \textsf{Sans Serif Family}
  \texttt{Typewriter Family}
  
  \rmfamily Roman Family
  \sffamily Sans Serif Family
  \ttfamily Typewriter Family
  
  {\rmfamily Roman Family} {\sffamily Sans Serif Family} {\ttfamily Typewriter Family}
  
  \sffamily How old are you?Where do you come from?Which school are you in?
  
  \end{document}

显示如下图

字体系列

  • 粗细

  • 宽度

\documentclass{ctexart}
  \begin{document}
  \textmd{Medium Series}
  \textbf{Boldface Series}
  
  {\mdseries Medium Series}
  {\bfseries Boldface Series}
  \end{document}

显示如下图

字体形状

  • 直立(\textup)

  • 斜体(\textit)

  • 伪斜体(\textsl)

  • 小型大写(\textsc)

  • 中文字体设置

    \text--字体设置命令

    \--shape字体设置声明

\documentclass{ctexart}
  
  \begin{document}
  \textup{Upright Shape}
  \textit{Italic Shape}
  \textsl{Slantes Shape}
  \textsc{Small Caps Shape}
  
  {\upshape Upright Shape}
  {\itshape Italic Shape}
  {\slshape Slantes Shape}
  {\scshape Small Caps Shape}
  
  %中文字体设置要使用ctex宏包,否则无法使用相关设置
  {\songti 宋体}
  {\heiti 黑体}
  {\fangsong 仿宋}
  {\kaishu 楷书}
  {\youyuan 圆体}
  {\lishu 隶书}
  {\yahei 微软雅黑}
  
  中文字体的{\textbf{粗体}}与{\textit{斜体}}
  %中文中的粗体用黑体表示,斜体用楷书表示
  \end{document}
  
  

显示如下图

字体大小

\documentclass{article}
\usepackage{ctex}
\begin{document}
\tiny          Hello\\
\scriptsize    Hello\\
\footnotesize  Hello\\
\small         Hello\\
\normalsize    Hello\\
\large         Hello\\
\Large         Hello\\
\LARGE         Hello\\
\huge          Hello\\
\Huge          Hello\\
\end{document}

显示如下图

LaTeX的篇章结构

详细文档请看这里ctex.pdf.lnk

  • \section\subsection\subsubsection来写小节

  • \chapter产生章节(但\chapter要在ctexbook中才会起作用,即把ctexart换为ctexbook),且\subsubsectionctexbook中不起作用

  • \tableofcontents产生整篇文档的目录,收录section

  • \\表示段内换行

  • \par+空格+内容开启换行(通常换行就是用空行代替,一个空行和多个空行的效果一致)

  • 关于这个的具体理解,请移步我的另一篇博客形式与内容分离

\documentclass{ctexart}
%==========设置标题的格式=========
\ctexset{
	section = {
	format+ = \zihao{-4} \heiti \raggedright,
	name = {,、},
	number = \chinese{section},
	beforeskip = 1.0ex plus 0/2ex minus .2ex,
	afterskip = 1.0ex plus 0.2ex minus .2ex,
	aftername = \hspce{0pt}
},
	subsection = {
	format+ = \zidao{5} \heiti \raggedright,
	% name={\thesubsection、},
	name = {,、},
	number = \ 1.0ex plus 0.2ex minus .2ex,
	beforeskip = 1.0ex plus 0.2ex minus .2ex,
	afterskip = 1.0ex plus 0.2ex minus .2ex,
	aftername = \hspace(0pt)
	}
\begin{document}
\tableofcontents
\section{导言}
打算写一些LaTeX的文档,也是自己在学习中的记录。希望自己在不断的进步吧。\\不断更,学到哪里就更到哪里。\par 希望给好评哦

打算写一些LaTeX的文档,也是自己在学习中的记录。希望自己在不断的进步吧。不断更,学到哪里就更到哪里。

希望给好评哦
\subsection{子小节}
\subsubsection{下一级小节}
\end{document}

LaTeX中的特殊字符

空白符号

\documentclass{ctexart}
\begin{document}
\section{空白符号}
第一点要注意LaTeX在英文中中输入一个空格和输入很多空格效果相同,在中文中输入一个空格和很多空格都不显示。在中文中插入英文时,中英文之间会自动产生一个空格。

第二点,如果需要换行,那么就在中间保持一个空行。

第三点,禁止使用中文全角空格。  

第四点,自动缩进,绝对不能使用空格代替。(什么开头空两行之类的不需要)

第五点,汉字与其他字符的间距会自动由XeLaTeX处理。

第六点,真的要打空格的话可以使用 a\quad b 实现\\
%具体效果可以直接复制这段代码(需要稍作改动,比如把\+空格变成实际操作)自己观察效果。
另外还有其他的比如 a\qquad b (两个空格的宽度)\\
a\thinspace b (相当于1/6个字母宽度)\\
a\enspace b (相当于1/2个字母宽度)\\
a\+空格 b (直接表示空格)\\
a~b(表示硬空格,即不能分割的空格)\\
a\kern -1em b\\
a\kern 1pc b\\
a\hskip 1em b\\
%\kern和\hskip可以打出指定宽度的空格长度,比如-1em即负距离
%\hspace命令根据参数指定的值产生空白
% em 字体相关尺寸,相当于大写字母M的宽度
% ex 字体相关尺寸,相当于字母x的高度
a\hspace{35pt}b\\
a\hphantom{xyz}b\\
%\hpantom命令可以根据占位符所产生的宽度来产生这个宽度的空格。
a\hfill b\\
%\hfill命令产生弹性长度空白,hfill可以充满整个空间(就是纸张这头到纸张那头)
\end{document}

控制符

\documentclass{ctexart}
\begin{document}
\section{\LaTeX 控制符}
\# \$ \% \{\} \~{} \_{} \^{} \textbackslash
%文本模式中 \\ 表示换行,为了不使 # 等被转义,我们用 \textbackslash产生 \
\textbackslash\#
\end{document}

排版符号

\documentclass{ctexart}
\begin{document}
\section{排版符号}
\S \P \dag \ddag \copyright \pounds
\end{document}

TeX标志符号

\documentclass{ctexart}
\usepackage{xltxtra}
\usepackage{texnames}
\usepackage{mflogo}
\begin{document}     
\section{\TeX 标志符号}
%用以下命令产生LaTeX的一些标志符号
\TeX{} \LaTeX{} \LaTeXe{} \XeLaTeX{}
%\XeLaTeX命令需要引用宏包xltxtra,上面已引入对应宏包,可以加载XeLaTeX的logo
\AmSTeX{} \AmS-\LaTeX{}
\BibTeX{} \LuaTeX{}
%同样的,以上四个由texnames宏包提供
\METAFONT{} \MF{} \MP{}
%以上三个由mflogo提供 
\end{document}

引号

\documentclass{ctexart}    
\begin{document}
\section{引号}
` ' `` ''
%详细结果自己编译就可以看出来了,`+'=一对单引号,``+''=一对双引号
\end{document}

连字符

\documentclass{ctexart}   
\begin{document}
\section{连字符}
- -- ---
%用一个两个三个减号来生成长度不同的连字符
\end{document}

非英文字符

\documentclass{ctexart}
\begin{document}
\section{非英文字符}
\oe \OE \ae \AE \aa \AA \o \O \l \L \ss \SS !` ?`
%注意直接查看效果
\end{document}

重音符号

\documentclass{ctexart}
\begin{document}
\section{重音符号(以o为例)}
\`o \'o \^o \''o \=o \.o \u{o} \v{o} \H{o} \r{o} \t{o} \c{o} \d{o}
%注意直接查看效果
\end{document}

插入图片

图片格式.jpg,必须将图片放在.tex所在文件夹内。

\documentclass[12pt]{article}
\usepackage{graphicx} %use graph format
\usepackage{epstopdf}
\begin{document}
\begin{figure}
\centering
\includegraphics[height=10cm,width=15cm]{1.jpg}
\caption{JPG}
\label{1}
\end{figure}
\end{document}