大神做的WinEdt(latex)快速掌握教程及詳細筆記

 

目錄


本文是筆者初學WinEdt用以編輯Latex的筆記,只涉及一些簡單問題,詳細請參考百度文庫(點點這幾個字看看~~)
本文的主要參考文獻是ta

0 包文件


這裏主要給出本文所有的頭文件,即需要使用的包。在運行本文中的事例之前在開頭複製以下代碼

% !Mode::"TeX:UTF-8"
%\documentclass[prd,aps,onecolumn,preprintnumbers,amsmath,amssymb,superscriptaddress]{article}
\documentclass{article}
%\usepackage[UTF8]{ctex}
\usepackage{listings}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{subfigure}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[table]{xcolor}
\usepackage{fancyhdr}
\usepackage{footnote}
\usepackage{lastpage}
%\usepackage{pythonhighlight}
\usepackage{indentfirst}
\usepackage{multirow}
\usepackage{authblk}
\usepackage{comment}
\usepackage{url}
\usepackage{float}
\usepackage{cite}
\usepackage{caption}
%\usepackage{graphix}
\setlength{\parindent}{1em}
%\pagestyle{fancy}
%設置頁面大小
%\chead{LSPE}
%\rhead{\thesection}
%\cfoot{Page \thepage of \pageref{LastPage}}
\usepackage[top=2.54cm, bottom=2.54cm, left=3.18cm,right=3.18cm]{geometry}


1.字體


1.1 字體大小


1 設置latex/winedt代碼中字體大小
options—options interface—Font schemes—Font雙擊從右邊找到FONT_SIZE將10改爲自己想要的,如14----保存—右鍵單擊左邊之前的Font----Load Script—結束
2 設置文章字體大小

 

\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge


比如:

{\small Hello word}


花括號框住的地方都變小

1.2 字體加粗


文本加粗

\textbf{這裏放文本}


既要加粗又要變小:(爲毛感覺有點邪惡~~ 2333333 認真臉)

{\textbf{\small Hello word}}


數學符號加粗

$\boldsymbol 直接接數學符號 $


1.3 字體顯示形式


1.3.1 刪除字體

\usepackage{cancel}
\cancel{abc}


1.3.2 下標線


這裏解決的問題是下標線導致的問題,如

f_x


結果爲:fxf_xf 
x
​    
而我想要的結果是下劃線一起輸出,我們需要一個轉義字符\即可,

f\_x
f_xf\_xf_x

1.3.3 其他形式

\cancel{abe}
\textbar{abc}
\textcircled{acbd}

更多形式可以在\text…自動補全查看

2.分段機制


1, 在原碼中空一行,則生成的pdf會換行
2, 在文後使用雙斜槓\
3, 使用命令

\newparas
舉例:

Life is too short so that I use python\\
me too.

Life is too short so that I use python

me too.

Life is too short so that I use python
\newparas
me too.


3.空格


參考自:seaskying


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

 

 $a$, $b$, $c$.
  
  $a,\ b,\ c.$
  
  The first three letter are a, b, c.


結果爲:

所以如果要空格直接按空格鍵即可,即上面代碼的1和3方式

4.自動補全


快捷鍵:Ctrl+Enter

5.數學模式與文本模式


5.1 行內公式和行間公式


引入數學宏包{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}


結果如下:

對行內公式和行間公式總結如下:

上面的方法是無法給公式編號的

5.2 數學公式編號


手動編號
通過採用\tag來編號,當引用公式時手動輸入。缺點是當更改公式裏的編號時引用中的編號不能自動更改,其二,不同通過點擊引用的編號回到公式

$$y=1+e^x \tag{1.1}$$
我們今天要討論這個方程$(1.1)$
y=1+ex(1.1)y=1+e^x \tag{1.1}
y=1+e 
x
 (1.1)

我們今天要討論這個方程(1.1)(1.1)(1.1)
這個好處是在處理文章比較長,有很多節,如寫書等時,可以手動寫(1.1),(2.1)(2.1.1)等公式,而自動則是(1)(2)這樣排序,沒有分小節。

自動編號
建立公式環境,如下:

\begin{equation}\label{加入標記}
xxx
\end{equation}


不同的平臺渲染不一樣,比如爲知筆記, latex等可以通過以下方法渲染自動編號

爲知筆記

$$\begin{equation}\label{my_equ1}
a^2+b^2=c^2
\end{equation}$$
We will use equation \eqref{my_equ1} 

Latex
對於latex而言,不需要$$這樣的符號

\begin{equation}\label{time_pixel}
  t_\text{pix}=\frac{\Delta T}{N_\text{pix}}\times N_\text{det}.
\end{equation}

Substituting \autoref{time_pixel}

馬克飛象

(馬克飛象有時候渲染會失敗,跟官方人員問過,給的辦法是:失敗的時候重新打開就可以看到自動編號,但是遺憾的是,當你嘗試改動時又會出錯,因此官方建議先編寫完,再渲染,這樣就不會去動它了。。。。呵呵噠。)

5.3 數學公式對齊


採用{aligned}如下:

\begin{equation}\label{information gain}
\begin{aligned}
  Gain(X,Y)&=H(Y)-H(Y|X)\\
  &=H(X)-H(X|Y)\\
  &=H(X)+H(Y)-H(X,Y)
\end{aligned}
\end{equation}


結果爲:

\begin{equation}\label{lagrangian}
\begin{aligned}
  w_{ij}&=\frac{1}{(N_i+R_i)(N_j+R_j)\frac{1}{2}(1+\delta_{ij})}\\
  Var[\mathbb{\hat{C}}_\ell]&=\frac{2}{2\ell+1}\left(\sum_{i,j,j\ge i}\frac{1}{(N_i+R_i)(N_j+R_j)\frac{1}{2}(1+\delta_{ij})}\right)^{-1}
\end{aligned}
\end{equation}

爲止筆記的對齊
跟上面一樣,但是爲知筆記這樣的缺點是,不能再使用(???)(???)的方法引用了,所以也是一大缺點

\begin{equation}\label{cos_age}
\begin{aligned}
t_0&=\int \ dt\\\
&=\frac{1}{H_0}\int_{0}^{1}\frac{da}{a\sqrt{\Omega_{\Lambda0}+\Omega_{k0}(a_0/a)^2+\Omega_{m0}(a_0/a)^3+\Omega_{r0}(a_0/a)^4}}
\end{aligned}
\end{equation}


5.4 公式之間空格


沒有空格

\begin{equation}\label{add_prior}
  \frac{\sigma(A_s^p)}{A_s^p}=0.17, \sigma(\beta_s)=0.17, \frac{\sigma(A_d^p)}{A_d^p}=0.015, \sigma(\beta_d)=0.02
\end{equation}

發現上面的公式之間捱得太近了,想要空格,可以使用第3部分提到的空格方法,將上面的代碼增加\quad:

\begin{equation}\label{add_prior}
  \frac{\sigma(A_s^p)}{A_s^p}=0.17,\quad \sigma(\beta_s)=0.17,\quad \frac{\sigma(A_d^p)}{A_d^p}=0.015,\quad \sigma(\beta_d)=0.02
\end{equation}


6.輸入函數


輸入函數前面加斜槓""
如:

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

結果如下:

可以看到,雖然在上面代碼每個逗號之後都輸入了空格,但得到的pdf文檔並沒有逗號,而英文中是習慣在逗號,句號等符號之後加空格的,這個時候可以將上面代碼改爲:

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

即每個函數單獨用美元符號分開,並在兩者之間加符號。 

$\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)\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}


如果需要寫 “函數=矩陣” 的形式,只需要在\left前加入即可,如:

\begin{equation}
    f=
    \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)以上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)$$


(2)\left( and \right) are left bracket and right bracket. 能夠通過括號內的內容自動改變括號大小。所以上面6中的第三行應該改爲:

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

(3)符號&是用來分隔列的,同一行不同列之間的元素用&分隔開
(4){ccc}是array中必選參數,爲center,center,center,表示三列都居中,
(5)\是強制換行符號

\begin{equation}\label{Cx1}
  C_{X\ell}^{R_1}=\frac{A^2}{16\pi}\sum_{\ell_1}(2\ell_1+1)C_{X\ell_1}^f\sum_{\ell_2}(2\ell_2+1)C_{\ell_2}^\beta\left(
  \begin{array}{ccc}
  \ell&\ell_1&\ell_2\\
  2&-2&0
  \end{array}
  \right)
\end{equation}
\begin{equation}\label{Cx1}
  C_{X\ell}^{R_1}=\frac{A^2}{16\pi}\sum_{\ell_1}(2\ell_1+1)C_{X\ell_1}^f\sum_{\ell_2}(2\ell_2+1)C_{\ell_2}^\beta\left(
  \begin{array}{ccc}
  \ell&\ell_1&\ell_2\\
  2&-2&0
  \end{array}
  \right)
\left(
\begin{array}{ccc}
\ell&\ell_1&\ell_2\\
2&-2&0
\end{array}
\right)
\end{equation}


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)&的作用是使得列對齊

9.加載宏包doc文檔


當我們使用一個宏包比如amsmath,想要得到說明文時可以如下操作:
在控制檯上點擊終端cmd窗口,輸入tex xxx(xxx是宏包名,如amsmath)回車即可。
終端按鈕如下圖:


10.輸入中文以及宏包安裝


輸入中文需要用到ctex包,這是專門針對中文而設計的包,使用時在前面將

\document{article}
改爲

\document[UTF8]{ctexart}
即可,(有的不需要加方括號中的內容),或者\document{article}不變,在其下加入一個宏包爲

\usepackage[UTF8]{ctex}
此外,中文包還可以使用

\usepackage{CJK}
當然,前提是已經安裝ctex宏包,通常情況都會自動安裝好,如果沒有安裝可以如下(筆者用的是Tex live)
開始—tex live—tex live manager—找到ctex—點擊安裝

值得注意的是:宏包已經都不需要網上下載安裝,而是直接從庫上安裝缺少的宏包,方法就是上面的方法。

11.插入圖片


插入圖片可以引用命令:

\ref{fig} or \autoref{fig}
前者只給圖片序號,而後者爲Figure + 序號
插入圖片需要加載宏包

\usepackage{graphicx}
或\usepackage{graphics}
建議前者。
插入圖片的環境爲:

  \begin{figure}[ht]
    \centering
    \includegraphics[width=10cm]{hh}
     \caption{這個是圖片}\label{bbb}
  \end{figure}


解釋:
(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}
當然,.png後綴可以不寫)注意,絕對路徑中是用的左斜槓“/”而不是右斜槓。
此外如果圖片比較多,最好的方法是在當前工作路徑下單獨建一個文件夾,命名爲fig.然後將圖片都放進去,此後要使用裏面的圖片時只需要使用路徑加載即可,這是相對路徑方法,如下:

\includegraphics[width=10cm]{fig/hh}
(4)caption{這個是圖片}表示對圖片的描述,將出現在圖片的底下。label{bbb}表示對這張圖片的標籤,相當於給定了這張圖片的名字。圖片較多時,建議使用容易看懂的名字,如label{fig.sub.1}。這個label的作用是方便以後引用這個圖時只需要用其標籤就可以,比如

see,figure\ref{fig.sub.1} or \autoref{fig.sub.1}
結果就是:see,figure x(x表示剛剛插入的圖的序號,如圖3)

(5)這樣插入的圖片是一個浮動圖,也就是latex自動找到最好的位置來放置此圖,而不是你代碼設置的地方,想要得到不浮動的圖可以將

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

這句單獨提取出來放置想要放的代碼中即可,但這個時候是不能加

\caption{xxx}
這一句的,也就是沒法加入標題。如果要給不浮動的圖形加標題,那麼可以看看nonfloat 包或者自己google(這回是朕是真的不打算給你找了)。

12.表格


12.1普通表格


表格製作可以參考這個 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)第一句是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}


同樣的\centering是表格居中,否則居左。其他都講過了,很easy.最後可以使用caption宏包,這個需要自行google。
在表格中換行

比如兩個表格(table)是要構成一個table的,想統一做一個說明,而不是每個table單獨說明,此時需要將兩個表格分開,這個時候可以用命令:

\vspace{0.35cm}   #表示上下空0.35cm的空間
1
比如

\begin{table}
  \centering
  %\footnotesize
  Case 0: 95+150
  
  \begin{tabular}{|c|c|c|c|c|c|}
  \hline
  $r$ & $\sigma_r(\sigma_F=1)$ & $\sigma_r(\sigma_F=0.1)$ & $\sigma_r(\sigma_F=0.01)$ & $N_{95}$ & $N_{150}$\\
  \hline
  0.01 & 0.01094 & 0.00228 & 0.00106 & 8701 & 1299 \\
  0 & 0.01084 & 0.00216 & 0.00091 & 8701 & 1299 \\
  \hline
  \end{tabular} 
  \vspace{0.35cm}    #空0.35cm
  
 Case 1: 41+95+150

  \begin{tabular}{|c|c|c|c|c|c|}
  \hline
  $r$ & $\sigma_r(\sigma_F=1)$ & $\sigma_r(\sigma_F=0.1)$ & $\sigma_r(\sigma_F=0.01)$ & $N_{95}$ & $N_{150}$\\
  \hline
  0.01 & 0.00787 & 0.00203 & 0.00106 & 8701 & 1299 \\
  0 & 0.01084 & 0.00216 & 0.00091 & 8701 & 1299 \\
  \hline
  \end{tabular}
  \caption{table 1}\label{anser1}
\end{table}

如果要改變字體大小,只要在第二行即\centering下加入改變字體大小的代碼即可,(如我已經註釋掉的\footnotesize),更多字體大小的代碼見第一部分。

調整表格和標題/標註的距離
可以使用以下兩個命令,關於調節距離多少,可以嘗試調節裏面的數字

\setlength{\abovecaptionskip}{0.cm}

\setlength{\belowcaptionskip}{-0.9cm}


多行
現在要將上面的tabe2設置爲如下形式,即對應r=0.01有多個σF\sigma_Fσ 
F
​    
 可選。

代碼如下:

\begin{table}
  \centering
  \footnotesize
  Case 0: 95+150

  \begin{tabular}{|c|c|c|c|c|c|c|}
  \hline
  \multirow{2}{0.25cm}{\centering $r$} & \multirow{2}{1.2cm}{\centering $\sigma_r$\\$(\sigma_F=1)$} & \multirow{2}{1.4cm}{\centering $\sigma_r$\\$(\sigma_F=0.1)$} & \multirow{2}{1.6cm}{\centering $\sigma_r$\\$(\sigma_F=0.01)$} & \multirow{2}{1cm}{\centering $N_{95}$} & \multirow{2}{1cm}{\centering $N_{150}$}\\
  & & & & & \\
  \hline
  \multirow{2}*{0.01} & 0.01279 & & & 8601 & 1399 \\
    & & 0.00329 & & 8701 & 1299 \\
    & & & 0.00180 & 9201 & 1299 \\
  \hline
  \multirow{2}*{0} & 0.01268 & & & 8701 & 1299 \\
   & & 0.00315 & &8701 & 1299\\
   & & & 0.00164 & 9201 & 799 \\
   \hline
  \end{tabular}
  \vspace{0.35cm}

  Case 1: 41+95+150

  \begin{tabular}{|c|c|c|c|c|c|c|}
  \hline
  $r$ & $\sigma_r(\sigma_F=1)$ & $\sigma_r(\sigma_F=0.1)$ & $\sigma_r(\sigma_F=0.01)$ & $N_{41}$ & $N_{95}$ & $N_{150}$\\
  \hline
   & 0.01057 &  &  & 4001 & 5201 & 798 \\
  0.01 &  & 0.00323 & & 1101 & 7801 & 1098 \\
   & & & 0.00180 & 1 & 9201 & 798 \\
  \hline
   & 0.01045 & & & 4001 & 5201 & 798 \\
   0 & & 0.00310 & & 1201 & 7701 & 1098 \\
    & & & 0.00164 & 1 & 9101 & 898 \\
  \hline
  \end{tabular}
  \caption{table 1}\label{anser1}
\end{table}


12.2合併行列


1,合併行


使用

\multirow{n}*{text}   #n表示要合併的行數,*是必須的,否則無法編譯成功,text是此行中要輸入的內容
注意,使用\multirow一定要在導言區,也就是在最開頭使用包\usepackage{multirow}
舉例如下:

% !Mode::"TeX:UTF-8"
\documentclass{article}
\usepackage[UTF8]{ctex}
\usepackage{listings}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[table]{xcolor}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{pythonhighlight}
\pagestyle{fancy}
\usepackage{enumitem}
\setlist[trivlist]{topsep=\baselineskip}
\usepackage{multirow}

%這裏以上都是導言區

\begin{document}
\begin{tabular}{|c|c|c|}
  \hline
  \multirow{3}*{朕} & 尚書省 & 工部  刑部  兵部  禮部  戶部  吏部 \\
  \cline{2-3}
    & 中書省 & ... \\
  \cline{2-3}
    & 門下省 & ... \\ 
  \hline
\end{tabular}
\end{document}


得到如下圖:

上面中 \cline{a-b}表示從第a列畫一條到第b列的線,與\hline的區別在於可以指定線的起始位置。

2,合併列


使用

\multicolumn{n}{x}{text}  #n爲合併列的數量,x爲字體的排版樣式,比如r,l,c分別表示右對齊,左對齊,居中,text爲內容
1
例子

\begin{document}
\begin{tabular}{|c|c|}
  \hline 
  \multicolumn{2}{|c|}{成績} \\
  \hline
  語文 & 數學 \\ 
  98 & 100 \\
  \hline
\end{tabular}
\end{document}

 

3,行列都存在

\begin{document}
\begin{tabular}{|c|r|r|}
\hline
\multirow{2}*{姓名} & \multicolumn{2}{c|}{成績}  \\
\cline{2-3}
  & 語文 & 數學 \\
\hline
 小明 & 60 &  55 \\
\hline
\end{tabular}
\end{document}


12.3表格下標註釋和字體大小設置


給定一個表格後,表下可能會有表格的介紹,而介紹的字體通常比文章字體小,可以用

\small{}

  \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{\small{This is a simple table for testing}}
  \end{table}


設置表格(字體)大小
同樣,可以通過\small來修改,但是放置的位置和上面不同,而是放在\begin{table}之後,如:

  \begin{table}
  \centering
  \small    #改變表格字體大小,同時表格大小也會變
  \rowcolors[\hline]{2}{orange}{red!30!yellow}
  \begin{tabular}{|c|c|}
    \rowcolor{red!20}
    Name & score \\
    小明 & 50 \\
    小華 & 45 \\
    \hline
  \end{tabular}
    \caption{\small{This is a simple table for testing}}
  \end{table}


此外還有

 

\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge


彩色表格和字體
彩色表格
彩色表格需要用到宏包

\usepackage{xcolor}

沒有需要按照上面的方法先安裝。因爲是針對表格,所以需要支持表格,使用時要如下:

\usepackage[table]{xcolor}

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

...
\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)第一行使用宏包xcolor,並支持table
(2)

  \rowcolors[\hline]{2}{orange}{red!30!yellow}
這裏是表示行顏色的設置,\hline表示每行都加橫線,後面表示從第二行開始奇數行用orange顏色,偶數行用30%紅色和30%黃色的混合,也可以寫成{red!30yellow!30}
(3)因爲我們是從第二行開始加顏色,所以第一行要單獨加顏色,如下

\rowcolor{red!20}
如果沒有則是白色。如果想要單獨每行自行設置,也可以如下單獨每行設置顏色

 

 \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}


彩色字體
同樣是xcolor包

{\color{violet}{哇,這是我的第一個 \LaTeX{} Article!}}
 

這一行是通過一個大花括號括起來的(即最左和最後的括號),如果沒有則整篇文章都是這種顏色的字體,括起來後就只有這一句話是這個顏色。

更多顏色設置見官網 and it’s pdf article

12.4 圖片表格並列


可以參考 https://tex.stackexchange.com/questions/377998/how-to-make-table-and-figure-side-by-side-appear-at-the-same-height

\begin{figure}   %開始圖片(圖片和表格合成一個大的圖片,這裏指的是整體的大圖片)
\begin{minipage}[b]{.5\linewidth}     %開闢一個小頁面,即用來放第一個圖片
\centering
\includegraphics[width=6cm]{Figure_1.eps}
\caption{Image}
\end{minipage}%
\begin{minipage}[b]{.5\linewidth}    %開闢第二個小頁面,用來放表格
\centering
\begin{tabular}{|c|c|}
\hline
aa & bb \\ \hline
cc & dd \\ \hline
\end{tabular}
\captionof{table}{Table}
\end{minipage}
%\caption{pic and table side by side}
\end{figure}

注意上面表格和圖片合成了一個大的圖片,同時可以對上面兩個一起寫註釋,即將上面的

%\caption{pic and table side by side}

去掉註釋即可

12.5 圖片和圖片並列


受上面的啓發,我們可以將兩張圖片並列

\begin{document}

\begin{figure}
\begin{minipage}[b]{.5\linewidth}
\centering
\includegraphics[width=6cm]{large_full.eps}
\caption{Image}
\end{minipage}%
\begin{minipage}[b]{.5\linewidth}
\centering
\includegraphics[width=6cm]{large_part}
\caption{image2}
\end{minipage}
\end{figure}

\end{document} 

除此之外,也可以使用另一種方法,如下:

\begin{figure}[htb]
  \centering
  \subfigure[]{\includegraphics[width=6.5cm]{large_part.eps}}  %[ ]裏面不填就會默認爲(a)
  \quad
  \subfigure[]{\includegraphics[width=6.5cm]{large_full.eps}}    %[ ]裏面不填默認爲(b)
  \caption{\small{The changing of uncertainty $\sigma_r$ on tensor-to-scalar ratio $r$ with the distribution of detectors on focal plane for different frequency combinations with $r$=0.01 and $\sigma_F$=0.1. Contour (a), (b) and (c) correspond to the case 0, case 1 and case 1*, respectively. }}\label{large_fig1}
\end{figure}

 

更新。。。。

跟第一個方法有點像:

\begin{figure}[htb]
\centering
\subfigure[the first subfigure]{
\begin{minipage}[c]{0.4\textwidth}
\includegraphics[width=1\textwidth]{41_95_220_large_corre2.eps} \\
\end{minipage}
}
\subfigure[the second subfigure]{
\begin{minipage}[c]{0.4\textwidth}
\includegraphics[width=1\textwidth]{41_95_220_large_corre2.eps} \\
\end{minipage}
}
\end{figure}



如要修改圖片大小,改變的是0.4的那個值,比如改爲0.7

12.5 圖片上下並排


只要將上面的方法使用//來換行即可,

\begin{figure}[htb]
\centering
\subfigure[the first subfigure]{
\begin{minipage}[c]{0.4\textwidth}
\includegraphics[width=1\textwidth]{41_95_220_large_corre2.eps} \\
\end{minipage}
}\\   #這是唯一不同的地方,增加了//
\subfigure[the second subfigure]{
\begin{minipage}[c]{0.4\textwidth}
\includegraphics[width=1\textwidth]{41_95_220_large_corre2.eps} \\
\end{minipage}
}
\end{figure}


如要修改圖片大小,改變的是0.4的那個值,比如改爲0.7

12.6 表格和表格並列


兩個表格並列

 

\begin{figure}   %開始圖片(表格和表格合成一個大的圖片,這裏指的是整體的大圖片)
\begin{minipage}[b]{.5\linewidth}    %開闢第一個小頁面,用來放第一個表格
\centering
  \begin{tabular}{|c|c|c|c|c|}
  \hline
  $r$ & $\sigma_r$ & $N_{95}$ & $N_{150}$ & $N_{220}$\\
  \hline
  \multirow{1}*{0} & 0.00765 & 4200 & 3000 & 2800 \\
  \hline
  \multirow{1}*{0.01} & 0.00778 & 4200 & 3000 & 2800 \\
  \hline
  \end{tabular}
\captionof{table}{Table}
\end{minipage}
\begin{minipage}[b]{.5\linewidth}    %開闢第二個小頁面,用來放表格
\centering
\begin{tabular}{|c|c|}
\hline
aa & bb \\ \hline
cc & dd \\ \hline
\end{tabular}
\captionof{table}{Table}
\end{minipage}
\caption{table and table side by side}
\end{figure}



可以看到有三個標註,可以通過加%去掉。另外,上面圖中最後標註是figure 1 xxx, 然而我們是圖表,所以只要將begin{figure}和end{figure}括號改爲table即可,我就不再改了。

多個表格並列

 

\begin{table}   %開始圖表
\begin{minipage}[b]{.5\linewidth}    %開闢第一個小頁面,用來放第一個表格
\centering
Case I, $f_\text{sky}=0.7$
  \begin{tabular}{|c|c|c|c|c|}
  \hline
  $r$ & $\sigma_r$ & $N_{41}$ & $N_{95}$ & $N_{220}$\\
  \hline
  \multirow{1}*{0} & 0.00405 & 800 & 7200 & 2000 \\
  \hline
  \multirow{1}*{0.01} & 0.00422 & 800 & 7200 & 2000 \\
  \hline
  \end{tabular}
\end{minipage}
\vspace{0.35cm}     %調節表格間距
\begin{minipage}[b]{.5\linewidth}    %開闢第二個小頁面,用來放第二個表格
\centering
Case II, $f_\text{sky}=0.7$
  \begin{tabular}{|c|c|c|c|c|c|c|}
  \hline
%  \caption{The first table}
  $r$ & $\sigma_r$ & $N_{30}$ & $N_{41}$ & $N_{95}$ & $N_{220}$ & $N_{270}$\\
  \hline
  \multirow{1}*{0} & 0.00765 & 400 & 400 & 7200 & 1000 & 1000 \\
  \hline
  \multirow{1}*{0.01} & 0.00778 & 400 & 400 & 7200 & 1000 & 1000 \\
  \hline
  \end{tabular}
\end{minipage}
\begin{minipage}[b]{.5\linewidth}    %開闢第三個小頁面,用來放第三個表格
\centering
Case III, $f_\text{sky}=0.05$
  \begin{tabular}{|c|c|c|c|c|}
  \hline
  $r$ & $\sigma_r$ & $N_{41}$ & $N_{95}$ & $N_{220}$\\
  \hline
  \multirow{1}*{0} & 0.00256 & 600 & 7400 & 2000 \\
  \hline
  \multirow{1}*{0.01} & 0.00319 & 600 & 7400 & 2000 \\
  \hline
  \end{tabular}
  \end{minipage}
  \vspace{0.35cm}
\begin{minipage}[b]{.5\linewidth}    %開闢第四個小頁面,用來放第四個表格
\centering
Case IV, $f_\text{sky}=0.05$
  \begin{tabular}{|c|c|c|c|c|c|c|}
  \hline
%  \caption{The first table}
  $r$ & $\sigma_r$ & $N_{30}$ & $N_{41}$ & $N_{95}$ & $N_{220}$ & $N_{270}$\\
  \hline
  \multirow{1}*{0} & 0.00765 & 400 & 400 & 7200 & 1000 & 1000 \\
  \hline
  \multirow{1}*{0.01} & 0.00778 & 400 & 400 & 7200 & 1000 & 1000 \\
  \hline
  \end{tabular}
\end{minipage}
\caption{table and table side by side}
\end{table}


注意,表格之間不要出現空行,因爲空行表示換一段,所以表格會打亂。

12.7 更多關於表格的舉例


這個內容可以參考Latex各種表格
舉例1:

先在開始加入兩個包

\usepackage{xcolor}
\usepackage{colortbl,booktabs}

\begin{table}
\centering
\caption{long}  
\begin{tabular*}{13cm}{lllllll}
\hline
Parameter & $A_s$ & $\alpha_s$ & $\beta_s$ & $A_d$& $\alpha_d$& $\beta_d$ \\
\hline
95+150 & 0.15302 & 0.86156 & 0.16135 & 2.09115 & 0.01381 & 0.00763\\
41+95+150 & 0.05307 & 0.16478 & 0.06017 & 2.08459 & 0.01368 & 0.00726\\
95+150+220 & 0.14988 & 0.85729 & 0.14835 & 1.66287 & 0.00820 & 0.00435\\
41+95+220 & 0.04459 & 0.14222 &  0.04750 & 1.81426 & 0.01406 & 0.00448\\
85+105+135+155 & 0.15213 & 0.95646 &  0.16026 & 2.06439 & 0.01259 & 0.00756\\
\hline
\end{tabular*}
  \caption{Foreground model parameters. Here only polarized BB spectral parameters are considered.}\label{foreground parameters}
\end{table}


上面有兩個caption可以選擇去掉其一,其中{13cm}表示表格的長度是13cm,可以自行設定。

13.交叉引用(corss-reference)


關於引用部分上面已經提及了一些,上面11的(4)我們用的是\ref {xxx}這個命令。這個命令有一個缺點是它只給出圖、定理等的序號,比如“如圖2所示”當我們使用\ref時需要寫成:

如圖\ref{xxx}所示  

當我們並不知道這個\ref{xxx}是圖還是表格還是定理等等的時候就比較麻煩,或者我們不想輸入“圖”,“表格”這樣的字眼,這時可以使用宏包(同樣,如果沒有宏包先按照上面的方法安裝)

\usepackage{hyperref}
然後將\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



we can get:

可以看到自動加了equation這個詞,而且是紅色方框,點擊可以直接跳到公式2.

14.文章佈局


(1)頁面大小
使用tex得到的pdf很窄,左右空的地方很大,如果我們想讓它跟微軟中的word一樣的頁面,可以在導言部分加入以下命令

\usepackage[top=2.54cm, bottom=2.54cm, left=3.18cm,right=3.18cm]{geometry}
(2)頁眉頁腳
參考文獻見這裏

使用宏包

\usepackage{fancyhdr}
在導言部分加入

\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{wudl}
\chead{$wudl's$ $tutorial article$}
\rhead{\thesection}
\cfoot{\thepage}


上面的結果是,頁眉左上邊是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}}


結果爲


(3)列舉


(4)參考文獻
A.手動輸入
手動輸入採用thebibliography環境,手動輸入適合參考文獻比較少的情況

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

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

  \bibitem{bibitem2}
blahblah(ditto)

這裏\bibitem跟上面的列舉中\item是一樣的,上面的9表示最多可能有9條參考文獻。結果爲:


B.使用Bibtex
這個比較複雜,以後再補充

15.超鏈接


使用

hyperref

實際上面都用過這個了。

16.插入代碼


參考百度知道

%導言部分
...
...

\usepackage{listings}              %加入宏包
\lstset{language=Python}           %Python語言
\lstset{breaklines}                %自動將長的代碼換行排版
\lstset{extendedchars=false}       %解決代碼跨頁時,章節標題,頁眉等漢字不顯示的問題
...
...
%需要插入代碼的地方
\begin{lstlisting}
放入代碼
\end{lstlisting}


這樣的方法是代碼是沒有彩色的,結果如下

解決彩色問題可以到網上找到已經修改彩色的代碼,放入導言部分即可,實際上就是使用上文講過的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
}


導入模塊
參考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行
...

結果如下:


其二,可以通過

\begin{xxx}
代碼
\end{xxx}

例如:

  \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}

結果如下;


17.目錄生成


插入目錄使用

\tableofcontents
注意這句話要在\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}


 

注意上面的代碼使用了超鏈接

\usepackage{hyerref}
如果沒有這個超鏈接是不會有紅色部分的。

18. 段落空行, 換行和首部縮進


在latex中,默認回車是不換行的,比如在latex中輸入

A: Hello, how are you?
B: Hi, i'm fine.

結果爲

我們實際想要的是B另起一行,此時可以通過加\來實現

A: Hello, how are you?\\
B: Hi, i'm fine.

另外,如果我們希望B換行之後行首縮進,比如寫段落的時候希望前面縮進兩個字符等,可以直接在latex中空一行

A: Hello, how are you?

B: Hi, i'm fine.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章