WinEdt(latex)详而简单教程

## 最新的更新见

https://blog.csdn.net/Mr_Cat123/article/details/80215341

1.字体大小

本文是笔者初学WinEdt用以编辑Latex的笔记,只涉及一些简单问题,详细请参考百度文库(点点这几个字看看~~) 
本文的主要参考文献是ta 

1.字体大小

 

options—options interface—Font schemes—Font双击从右边找到FONT_SIZE将10改为自己想要的,如14—-保存—右键单击左边之前的Font—-Load Script—结束

2.分段机制

在原码中空一行,则生成的pdf会换行

3.空格

参考自:seaskying 
这里写图片描述

当然直接空一格也是可以得到一个空格的,如下:

  $a$, $b$, $c$.

  $a,\ b,\ c.$

  The first three letter are a, b, c.
  • 1
  • 2
  • 3
  • 4
  • 5

结果为: 
这里写图片描述 
所以如果要空格直接按空格键即可,即上面代码的1和3方式

4.自动补全

快捷键:Ctrl+Enter

5.数学模式与文本模式(包括行内公式和行间公式)

引入数学宏包{amssyb},American mathematics society symbol.例句如下

% !Mode::"TeX:UTF-8"
\documentclass{article}
\usepackage{amssymb}
\begin{document}
  \section{symbol}
  1+1=2, $$1+1=2$$, $I know 1+1=2,$

  This is in text mode, $This is in math mode,$ $This\ is\ in\ math\ in\ mode.$

\end{document}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

结果如下: 
这里写图片描述
对行内公式和行间公式总结如下: 
这里写图片描述

6.输入函数

输入函数前面加斜杠”\” 
如:

$\frac{10}{11}, \sqrt[3]{x^2+1}, \ldots, \sin x, \cos x.$
  • 1

结果如下: 
这里写图片描述 
可以看到,虽然在上面代码每个逗号之后都输入了空格,但得到的pdf文档并没有逗号,而英文中是习惯在逗号,句号等符号之后加空格的,这个时候可以将上面代码改为:

$\frac{10}{11},$ $\sqrt[3]{x^2+1},$ $\ldots,$ $\sin x,$ $\cos x.$
  • 1

即每个函数单独用美元符号分开,并在两者之间加符号。

  $\sum_{n=1}^{\infty}$

  $$\sum_{n=1}^{\infty}$$

  $$\lim_{n \to \infty}(1+\frac{1}{n})^n = e,$$ 
  $$\int_{-\infty}^{+\infty}\frac{\sin x}{x} \mathrm{d}x=I$$

  $\alpha,\beta,\gamma,\delta\epsilon\varepsilon\xi\pi\rho\sigma\eta\theta\phi\varphi\omega$

  $\Gamma\Phi$

  $|A|,\|a\|,\vec{a},\overleftarrow{AB},\tilde{x},\widetilde{xyz},sin,\mathrm{sin}$

  $\mathbb{AB},\mathbf{abAB}$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

这里写图片描述 
(1)第一行是行内公式和第二行的行间公式是不一样的,这是出于文本美观的目的。 
(2)\mathrm{d}那儿是为了和x不同,因为d是直立的而不是变量,而x是变量,这里mathrm=math roman 
(3)剩下的看到gamma等希腊字母第一个字母大写则表示输出的文本是大写,这里值得注意的是:alpha,beta,varepsilon等是没有大写形式的,因为其大写形式就是ABE,不能输入\Alpha,\Beta…… 
(4)mathbb=math blackboard, mathbf=math boldface 
实际上第行中的括号应该是大括号而不是小括号,细节见下节。

7.矩阵和大括号

先看矩阵

  \begin{equation}
    \left(
    \begin{array}{ccc}
    a_{11}& a_{12} & a_{13} \\
    a_{21} & a_{22} & a_{23} \\
    a_{31} & a_{32} & a_{33}
    \end{array}
    \right)
  \end{equation}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

这里写图片描述 
(1)以上begin{equation}开始了一个公式环境,在这个环境中可以直接输入变量、函数等而不需要加$符号,上面等同于

   $$ \left(
    \begin{array}{ccc}
    a_{11}& a_{12} & a_{13} \\
    a_{21} & a_{22} & a_{23} \\
    a_{31} & a_{32} & a_{33}
    \end{array}
    \right)$$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

(2)\left( and \right) are left bracket and right bracket. 能够通过括号内的内容自动改变括号大小。所以上面6中的第三行应该改为:

$$\lim_{n \to +\infty}\left(1+\frac{1}{n}\right)^n=e$$
  • 1

这里写图片描述 
(3)符号&是用来分隔列的,同一行不同列之间的元素用&分隔开 
(4){ccc}是array中必选参数,为center,center,center,表示三列都居中, 
(5)\是强制换行符号

8.分段函数

分段函数是在矩阵的基础之上的,比如如下的分段函数

  \begin{equation}
    f(x)=
    \left\{
    \begin{array}{cc}
    \int \mathrm{d}^3p\int_{0}^{\infty}\mathrm{d}x x^2 \frac{\delta(E-\sqrt{p^2+m^2})}{2E} , & x \geq 0 \\
    0,& x < 0
    \end{array}
    \right.
  \end{equation}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

这里写图片描述 
这里写图片描述
(1)不需要右括号 
(2)&的作用是使得列对齐

9.加载宏包doc文档

当我们使用一个宏包比如amsmath,想要得到说明文时可以如下操作: 
在控制台上点击终端cmd窗口,输入tex xxx(xxx是宏包名,如amsmath)回车即可。 
终端按钮如下图: 
这里写图片描述

10.输入中文以及宏包安装

输入中文需要用到ctex包,这是专门针对中文而设计的包,使用时在前面将

\document{article}
  • 1

改为

\document[UTF8]{ctexart}
  • 1

即可,(有的不需要加方括号中的内容),或者\document{article}不变,在其下加入一个宏包为

\usepackage[UTF8]{ctex}
  • 1

此外,中文包还可以使用

\usepackage{CJK}
  • 1

当然,前提是已经安装ctex宏包,通常情况都会自动安装好,如果没有安装可以如下(笔者用的是Tex live) 
开始—tex live—tex live manager—找到ctex—点击安装 
这里写图片描述 
值得注意的是:宏包已经都不需要网上下载安装,而是直接从库上安装缺少的宏包,方法就是上面的方法。

11.插入图片

插入图片需要加载宏包

\usepackage{graphicx}
  • 1

\usepackage{graphics}
  • 1

建议前者。 
插入图片的环境为:

  \begin{figure}[ht]
    \centering
    \includegraphics[width=10cm]{hh}
     \caption{这个是图片}\label{bbb}
  \end{figure}
  • 1
  • 2
  • 3
  • 4
  • 5

解释: 
(1)第一句begin{figure}代表开始插入图片,后面的[ht]是可选参数,表示here, top。如果去掉[ht]表示默认的htbp,分别表示“这里,顶部,底部,换一页”(here, top, bottom, page) 
(2)第二句是图片居中,否则自动靠左 
(3)[width=10cm] (有些people不需要加cm,是已经设置单位是cm了,还可以有in英尺),可选的参数还有如下(可参考DreamSeeking的文献): 
这里写图片描述
第三行最后的{hh}表示插入的图片的名字,因此插入的图片一定要放在工作目录下,并命名为hh.xxx(xxx表示后缀,如png,jpg,eps等)

当然也有不在工作目录下的方法,这个google一下by yourself.在此不累赘。(好吧,让我再告诉你好了,其实就是使用绝对路径

\includegraphics[width=10cm]{D:/software/tex/hh.png}
  • 1

当然,.png后缀可以不写)注意,绝对路径中是用的左斜杠“/”而不是右斜杠。 
此外如果图片比较多,最好的方法是在当前工作路径下单独建一个文件夹,命名为fig.然后将图片都放进去,此后要使用里面的图片时只需要使用路径加载即可,这是相对路径方法,如下:

\includegraphics[width=10cm]{fig/hh}
  • 1

(4)caption{这个是图片}表示对图片的描述,将出现在图片的底下。label{bbb}表示对这张图片的标签,相当于给定了这张图片的名字。图片较多时,建议使用容易看懂的名字,如label{fig.sub.1}。这个label的作用是方便以后引用这个图时只需要用其标签就可以,比如

see,figure\ref{fig.sub.1}
  • 1

结果就是:see,figure x(x表示刚刚插入的图的序号,如图3)

(5)这样插入的图片是一个浮动图,也就是latex自动找到最好的位置来放置此图,而不是你代码设置的地方,想要得到不浮动的图可以将

\includegraphics[width=10cm]{fig/hh}
  • 1

这句单独提取出来放置想要放的代码中即可,但这个时候是不能加

\caption{xxx}
  • 1

这一句的,也就是没法加入标题。如果要给不浮动的图形加标题,那么可以看看nonfloat 包或者自己google(这回是朕是真的不打算给你找了)。

12.表格

表格制作可以参考这个 and 这个(点一下试试),后者是英文。 
简单说明: 
表格制作可以使用tabular,简单一个图如下:

  \begin{tabular}{|c|c|}
    \hline
    % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
    Name & score \\
    \hline
    小明 & 50 \\
    小华 & 45 \\
    \hline
  \end{tabular}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

结果如下 
这里写图片描述 
讲解: 
(1)第一句是tabular表格的开始,参数{|c|c|}中的第一个|表示表格中的左边竖,第二、三个分别是中间和右边的竖。而c表示表格中的字体居中,l(left)和r(right)表示表格中字体靠左和靠右。可以尝试将{|c|c|}改为{c|c}即不要两边的竖线。 
(2)\hline(horizontal line)表示画一条水平线 
(3)%是注释,\是换行,\hline可以紧接在\后,如下表示:

\\ \hline
  • 1

会显得更紧凑。 
当然,这个表格是不浮动的,和图片一样,如果想加入\caption的话,可以构成浮动的图片(但毕竟可以写标题了呀,想想还是赚的)。这个时候需要用到table环境。如下

  \begin{table}
  \centering
  \begin{tabular}{|c|c|}
    \hline
    % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
    Name & score \\
    \hline
    小明 & 50 \\
    小华 & 45 \\
    \hline
  \end{tabular}
    \caption{这是一个表格}
  \end{table}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

同样的\centering是表格居中,否则居左。其他都讲过了,很easy.最后可以使用caption宏包,这个需要自行google。

彩色表格和字体

彩色表格

彩色表格需要用到宏包

\usepackage{xcolor}
  • 1

没有需要按照上面的方法先安装。因为是针对表格,所以需要支持表格,使用时要如下:

\usepackage[table]{xcolor}
  • 1

上面的例子可以加入彩色如下:

...
\usepackage[table]{xcolor}
...
...
  \begin{table}
  \centering
  \rowcolors[\hline]{2}{orange}{red!30!yellow}
  \begin{tabular}{|c|c|}
    \rowcolor{red!20}
    Name & score \\
    小明 & 50 \\
    小华 & 45 \\
    \hline
  \end{tabular}
    \caption{这是一个表格}
  \end{table}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

结果为: 
这里写图片描述 
说明: 
(1)第一行使用宏包xcolor,并支持table 
(2)

  \rowcolors[\hline]{2}{orange}{red!30!yellow}
  • 1

这里是表示行颜色的设置,\hline表示每行都加横线,后面表示从第二行开始奇数行用orange颜色,偶数行用30%红色和30%黄色的混合,也可以写成{red!30yellow!30} 
(3)因为我们是从第二行开始加颜色,所以第一行要单独加颜色,如下

\rowcolor{red!20}
  • 1

如果没有则是白色。如果想要单独每行自行设置,也可以如下单独每行设置颜色

  \begin{table}
  \centering
  \begin{tabular}{|c|c|}
  \hline 
  \rowcolor{red!20}
    Name & score \\
    \hline
    \rowcolor{yellow}
    小明 & 50 \\
    \hline \rowcolor{orange}
    小华 & 45 \\
    \hline
  \end{tabular}
    \caption{这是一个表格}
  \end{table}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

彩色字体

同样是xcolor包

{\color{violet}{哇,这是我的第一个 \LaTeX{} Article!}}
  • 1

这里写图片描述 
这一行是通过一个大花括号括起来的(即最左和最后的括号),如果没有则整篇文章都是这种颜色的字体,括起来后就只有这一句话是这个颜色。

更多颜色设置见官网 and it’s pdf article

13.交叉引用(corss-reference)

关于引用部分上面已经提及了一些,上面11的(4)我们用的是\ref {xxx}这个命令。这个命令有一个缺点是它只给出图、定理等的序号,比如“如图2所示”当我们使用\ref时需要写成:

如图\ref{xxx}所示  
  • 1

当我们并不知道这个\ref{xxx}是图还是表格还是定理等等的时候就比较麻烦,或者我们不想输入“图”,“表格”这样的字眼,这时可以使用宏包(同样,如果没有宏包先按照上面的方法安装)

\usepackage{hyperref}
  • 1

然后将\ref {xxx}改为\autoref{xxx},e.g.

......
  \usepackage{hyperref}
  ...
  ...
  \begin{equation}
    f(x)=
    \left\{
    \begin{array}{cc}
    \int \mathrm{d}^3p\int_{0}^{\infty}\mathrm{d}x x^2 \frac{\delta(E-\sqrt{p^2+m^2})}{2E} , & x \geq 0 \\
    0,& x < 0
    \end{array}
    \right.
    \label{myequation}
  \end{equation}
  We all know \autoref{myequation} is a important equation
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

we can get: 
这里写图片描述
可以看到自动加了equation这个词,而且是红色方框,点击可以直接跳到公式2.

14.文章布局

(1)页面大小

使用tex得到的pdf很窄,左右空的地方很大,如果我们想让它跟微软中的word一样的页面,可以在导言部分加入以下命令

\usepackage[top=2.54cm, bottom=2.54cm, left=3.18cm,right=3.18cm]{geometry}
  • 1

(2)页眉页脚

参考文献见这里

使用宏包

\usepackage{fancyhdr}
  • 1

在导言部分加入

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{wudl}
\chead{$wudl's$ $tutorial article$}
\rhead{\thesection}
\cfoot{\thepage}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

上面的结果是,页眉左上边是wudl,中间是chead中的句子,右上边是章节,页脚是页码。实际还有很多可选参数,自行查找需要的。 
当然上面的页码是“1”“2”“3”这样的数,如果想要A of B,即第A页共B页,则要使用lastpage宏包。 
如下:

\usepackage{fancyhdr}
\usepackage{lastpage}
\pagestyle{fancy}
\lhead{wudl}
\chead{$wudl's$ $tutorial article$}
\rhead{\thesection}
\cfoot{Page \thepage of \pageref{LastPage}}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

结果为 
这里写图片描述

 

(3)列举 
这里写图片描述

这里写图片描述

 

(4)参考文献

A.手动输入

手动输入采用thebibliography环境,手动输入适合参考文献比较少的情况

  As is stated in \cite{bibitem1} blahblah\dots
  \begin{thebibliography}{9}

  \bibitem{bibitem1}
天朝. 朕的江山和子民[M]. 朕的天朝:天朝出版社. 2018

  \bibitem{bibitem2}
blahblah(ditto)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

这里\bibitem跟上面的列举中\item是一样的,上面的9表示最多可能有9条参考文献。结果为: 
这里写图片描述

B.使用Bibtex

这个比较复杂,以后再补充

15.超链接

使用

hyperref
  • 1

实际上面都用过这个了。

16.插入代码

参考百度知道

%导言部分
...
...
\usepackage{listings}              %加入宏包
\lstset{language=Python}           %Python语言
\lstset{breaklines}                %自动将长的代码换行排版
\lstset{extendedchars=false}       %解决代码跨页时,章节标题,页眉等汉字不显示的问题
...
...
%需要插入代码的地方
\begin{lstlisting}
放入代码
\end{lstlisting}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

这样的方法是代码是没有彩色的,结果如下 
这里写图片描述 
解决彩色问题可以到网上找到已经修改彩色的代码,放入导言部分即可,实际上就是使用上文讲过的xcolor宏包自定义颜色。 

例:自定义颜色(参考conding算子) 

自定义颜色使用了listings和color两个宏包

 

\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}

\lstset{ %
  language=Octave,                % the language of the code
  basicstyle=\footnotesize,           % the size of the fonts that are used for the code
  numbers=left,                   % where to put the line-numbers
  numberstyle=\tiny\color{gray},  % the style that is used for the line-numbers
  stepnumber=2,                   % the step between two line-numbers. If it's 1, each line 
                                  % will be numbered
  numbersep=5pt,                  % how far the line-numbers are from the code
  backgroundcolor=\color{white},      % choose the background color. You must add \usepackage{color}
  showspaces=false,               % show spaces adding particular underscores
  showstringspaces=false,         % underline spaces within strings
  showtabs=false,                 % show tabs within strings adding particular underscores
  frame=single,                   % adds a frame around the code
  rulecolor=\color{black},        % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. commens (green here))
  tabsize=2,                      % sets default tabsize to 2 spaces
  captionpos=b,                   % sets the caption-position to bottom
  breaklines=true,                % sets automatic line breaking
  breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace
  title=\lstname,                   % show the filename of files included with \lstinputlisting;
                                  % also try caption instead of title
  keywordstyle=\color{blue},          % keyword style
  commentstyle=\color{dkgreen},       % comment style
  stringstyle=\color{mauve},         % string literal style
  escapeinside={\%*}{*)},            % if you want to add LaTeX within your code
  morekeywords={*,...}               % if you want to add more keywords to the set
}
  • 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

 

导入模块 

参考gaojiaxing 和 instant以python为例,下载python版本的hightlighting,地址点这里。下载完成要将pythonhighlight.sty和放在工作目录下。 
可以有两种方法来加载自己写的python代码。其一是将python代码在python自己的编辑器中写完保存为.py文件放到工作目录下(如test.py),之后加载的时候只需要\inputpython…即可,这种方法可以节省大量的WinEdt书写空间

 

...
...
\usepackage{graphicx}
\usepackage{pythonhighlight}
...
...
\inputpython{test.py}{1}{41}#导入python文件test.py第一行到第41行
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

结果如下: 
这里写图片描述

其二,可以通过

\begin{xxx}
代码
\end{xxx}
  • 1
  • 2
  • 3

例如:

  \begin{python}
  #
  from pyx import *
  def f():
  g = graph.graphxy(width=8)
  g.plot(graph.data.function("y(x)=sin(x)/x", min=-15, max=15))
  g.writePDFfile("function")
  print r'\includegraphics{function}'
  return f
  \end{python}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

结果如下; 
这里写图片描述

17.目录

插入目录使用

\tableofcontents
  • 1

注意这句话要在\begin{document}之后,end之前,例如:

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\section{A section}
This is a section
\paragraph{A paragraph}
This is a paragraph
\subsection{A subsection}
This is a subsection
\end{document}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

这里写图片描述 
注意上面的代码使用了超链接

\usepackage{hyerref}
  • 1

如果没有这个超链接是不会有红色部分的。

  • 17
    点赞
  • 166
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值