LaTex 學(xué)習(xí)筆記

原文地址

LaTeX(/?lɑ?t?x/,常被讀作/?lɑ?t?k/或/?le?t?k/),排版時(shí)通常使用LATEX,是一種基于TeX排版系統(tǒng),由美國(guó)計(jì)算機(jī)科學(xué)萊斯利·蘭伯特在20世紀(jì)80年代初期開(kāi)發(fā),利用這種格式系統(tǒng)的處理,即使用戶(hù)沒(méi)有排版和程序設(shè)計(jì)的知識(shí)也可以充分發(fā)揮由TeX所提供的強(qiáng)大功能,不必一一親自去設(shè)計(jì)或校對(duì),能在幾天,甚至幾小時(shí)內(nèi)生成很多具有書(shū)籍質(zhì)量的印刷品。對(duì)于生成復(fù)雜表格和數(shù)學(xué)公式,這一點(diǎn)表現(xiàn)得尤為突出。因此它非常適用于生成高印刷質(zhì)量的科技和數(shù)學(xué)、物理文檔。這個(gè)系統(tǒng)同樣適用于生成從簡(jiǎn)單的信件到完整書(shū)籍的所有其他種類(lèi)的文檔。

Mac 使用使用 LaTeX 可以下載 MacTeX ,也可使用 Sublime Text 編輯器配合 LaTeXTools 插件。

基本語(yǔ)法

序言

編寫(xiě)文檔的序言部分,可以使用如下代碼實(shí)例:

\documentclass{article}

\title{標(biāo)題}
\author{作者}
\date{February 2017} 

\begin{document}

% 顯示序言部分內(nèi)容
\maketitle

\end{document}

\documentclass{article} 表明文檔的類(lèi)型是 article 類(lèi)型,其他可供選擇的值有:article 、book、report 等。

\title{標(biāo)題} 表示文檔的標(biāo)題

\author{作者} 表示文檔的作者

\date{February 2017} 表示文檔的時(shí)間, 還可以用\today 表示當(dāng)前的時(shí)間。

文檔的正文部分放在 \begin{document}\end{document} 之間。

\maketitle 表示打印序言部分的內(nèi)容。

% 開(kāi)頭的內(nèi)容表示注釋

粗體、斜體、下劃線(xiàn)

\textbf{} 命令會(huì)把大括號(hào)里面的內(nèi)容以粗體的方式顯示。

\textit{} 命令會(huì)把大括號(hào)里面的內(nèi)容以斜體的方式顯示。

\underline{} 命令會(huì)把大括號(hào)里面的內(nèi)容以添加寫(xiě)劃線(xiàn)的方式顯示。

圖片
\documentclass{article}
\usepackage{graphicx}
\graphicspath{ {images/} }
 
\begin{document}
The universe is immense and it seems to be homogeneous, 
in a large scale, everywhere we look at.
 
\includegraphics{universe}
 
There's a picture of a galaxy above
\end{document}

LaTeX 自己本身不能管理圖片,需要引用 graphicx 宏包 (package), \graphicspath{ {images/} } 表示圖片位于當(dāng)前目錄下的 images 文件夾下, \includegraphics{universe} 表示使用 universe 這樣圖片。

更多圖片用法,請(qǐng)參考 insert-images

列表

列表分為有序列表和無(wú)序列表,列表的每一個(gè)子項(xiàng)都使用 \item 來(lái)表示。

無(wú)序列表通過(guò) itemsize 環(huán)境變量來(lái)生成。

\begin{itemize}
  \item The individual entries are indicated with a black dot, a so-called bullet.
  \item The text in the entries may be of any length.
\end{itemize}

有序列表通過(guò) enumerate 環(huán)境變量來(lái)生成。

\begin{enumerate}
  \item This is the first entry in our list
  \item The list numbers increase with each entry we add
\end{enumerate}

有序列表和無(wú)序列表還可以互相嵌套。

更多列表用法,請(qǐng)參考 Lists 。

數(shù)學(xué)公式

數(shù)學(xué)公式有兩種顯示方式: 內(nèi)聯(lián)(inline) 和 展示(display)。

內(nèi)聯(lián)數(shù)學(xué)公式:

In physics, the mass-energy equivalence is stated 
by the equation $E=mc^2$, discovered in 1905 by Albert Einstein.

內(nèi)聯(lián)的數(shù)學(xué)公式可以使用: \( … \) 、$ ... $ 、\begin{math} ... \end{math} 等三種命令來(lái)表示。

展示數(shù)學(xué)公式:

The mass-energy equivalence is described by the famous equation
 
\[E=mc^2\]
 
discovered in 1905 by Albert Einstein. 
In natural units ($c = 1$), the formula expresses the identity
 
\begin{equation}
E=m
\end{equation}

展示數(shù)學(xué)公式可以使用: \[ ... \] 、 \begin{equation} ... \end{equation} 、\begin{displaymath} ... \end{displaymath} 等三種命令來(lái)表示。

其他數(shù)學(xué)公式常用的宏包是: amsmath。

更多數(shù)學(xué)公式的用法,請(qǐng)參考 Mathematical-expressions

章節(jié)片段

有如下常見(jiàn)章節(jié)片段:

\part{part} 只是適用于 documentclass 類(lèi)型是 bookreprot

\chapter{chapter} 只是適用于 documentclass 類(lèi)型是 bookreprot

\section{section}

\subsection{subsection}

\paragraph{paragraph}

\subparagraph{subparagraph}

表格

創(chuàng)建一個(gè)簡(jiǎn)單的表格

\begin{center}
\begin{tabular}{ |c| c| c| }
\hline
cell1 & cell2 & cell3 \\ 
\hline
cell4 & cell5 & cell6 \\  
\hline
cell7 & cell8 & cell9 \\
\hline
\end{tabular}
\end{center}

\tabular 環(huán)境變量表示創(chuàng)建表格。{|c|c|c|} 表示表格有 3 列,每一列都居中顯示,每一列之間的分隔符是 | 。c 表示居中對(duì)齊,l 表示居左對(duì)齊,r 表示居右對(duì)齊。 \\ 表示換行, \hline 表示水平線(xiàn)。\center 環(huán)境變量,表示列表居中對(duì)齊。

更多表格用法,請(qǐng)參考 Tables 。

常見(jiàn)宏包

數(shù)學(xué) - amsmath

圖片- graphicx

顏色 - xcolor

表格 - array

中文 - ctexxecjk

字體 - fontspec

支持中文

1. TeXShop 支持中文

TexShow 偏好設(shè)置 --> 編碼 --> Unicode(UTF-8)

排版 --> XeLaTeX

引入 ctex

\documentclass{article}
\usepackage{ctex}

或者使用 ctexart 文檔格式

\documentclass{ctexart}
2. 編譯 tex 文件

引入 ctex 包,使用如下命令編譯 tex 文件。

xelatex xxx.tex

參考資料

Lear LaTeX in 30 minutes

Support Chinese

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容