LaTex排版(一)

一、LaTex運行環境的安裝與配置
1.LaTex具體軟件安裝
https://zhuanlan.zhihu.com/p/41855480

B站 LaTex入門視頻
2.安裝版本確認
通過如下代碼可確定該軟件是否已經安裝成功

tex -v
latex -v
xelatex -v
pdflatex -v

3.簡單的文件構建
在任務欄搜索到命令行工具後,以管理員方式打開

windows+r

C:\WINDOWS\system32>cd\

C:\>mkdir testLatex

C:\>cd testLatex

C:\testLatex>notepad

C:\testLatex>notepad test.tex

4.LaTex中具體信息解釋

{}	中通常爲參數

(1).簡單的Hello實例代碼及運行結果
test.tex記事本中的內容

\documentclass{article}
\begin{document}
Hello \LaTeX.
\end{document}

命令行中的運行結果

C:\testLatex>latex test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(d:/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(d:/texlive/2020/texmf-dist/tex/latex/base/size10.clo))
(d:/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-dvips.def)
(./test.aux) [1] (./test.aux) )
Output written on test.dvi (1 page, 328 bytes).
Transcript written on test.log.

(2).該目錄下的文件類型

C:\testLatex>dir
 驅動器 C 中的卷沒有標籤。
 卷的序列號是 2E08-445A

 C:\testLatex 的目錄

2020/06/17  22:59    <DIR>          .
2020/06/17  22:59    <DIR>          ..
2020/06/17  22:59                 8 test.aux
2020/06/17  22:59               328 test.dvi
2020/06/17  22:59             2,695 test.log
2020/06/17  22:59                72 test.tex
               4 個文件          3,103 字節
               2 個目錄 28,962,951,168 可用字節

編譯形成了dvi文件。
(3).dvipdfmx實現將生成的dvi文件轉換爲相應的pdf文件

C:\testLatex>dvipdfmx test.dvi
test.dvi -> test.pdf
[1]
3616 bytes written

(4).xelatex實現將生成的tex文件轉換爲相應的pdf文件

C:\testLatex>xelatex test.tex
This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020/W32TeX) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(d:/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(d:/texlive/2020/texmf-dist/tex/latex/base/size10.clo))
(d:/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-xdvipdfmx.def)
(./test.aux) (d:/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd) [1]
(./test.aux) )
Output written on test.pdf (1 page).
Transcript written on test.log.

(5)新建build.bat(批處理文件)來運行三行程序,即將程序中的無用處的文件格式進行刪除
build.bat文件中的內容:

latex test.tex
dvipdfmx test.dvi
del *.aux  *.dvi  *.log

在命令行中通過 build 命令,得到的相應的運行結果

C:\testLatex>latex test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/W32TeX) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(d:/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(d:/texlive/2020/texmf-dist/tex/latex/base/size10.clo))
(d:/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-dvips.def)
(./test.aux) [1] (./test.aux) )
Output written on test.dvi (1 page, 328 bytes).
Transcript written on test.log.

C:\testLatex>dvipdfmx test.dvi
test.dvi -> test.pdf
[1]
3613 bytes written

C:\testLatex>del *.aux  *.dvi  *.log

(6)新建buildx.bat(批處理文件)來運行三行程序,即將程序中的無用處的代碼刪除
build.bat文件中的內容:

xelatex test.tex
del *.aux  *.dvi  *.log

在命令行中通過 buildx 命令,得到的相應的運行結果:

C:\testLatex>xelatex test.tex
This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020/W32TeX) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(d:/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(d:/texlive/2020/texmf-dist/tex/latex/base/size10.clo))
(d:/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-xdvipdfmx.def)
No file test.aux.
(d:/texlive/2020/texmf-dist/tex/latex/base/ts1cmr.fd) [1] (./test.aux) )
Output written on test.pdf (1 page).
Transcript written on test.log.

C:\testLatex>del *.aux  *.dvi  *.log

(7)解決中文不顯現的問題
首先將test.tex文件另存爲UTF-8的格式,並在文件中加入 \usepackage{ctex} 這個宏包。

\documentclass{article}
\usepackage{ctex}
\begin{document}
你好 \LaTeX 。
\end{document}

其次通過 xelatex test.tex來進行編譯運行

C:\testLatex>xelatex test.tex
This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020/W32TeX) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(d:/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(d:/texlive/2020/texmf-dist/tex/latex/base/size10.clo))
(d:/texlive/2020/texmf-dist/tex/latex/ctex/ctex.sty
(d:/texlive/2020/texmf-dist/tex/latex/l3kernel/expl3.sty
(d:/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-xdvipdfmx.def))
(d:/texlive/2020/texmf-dist/tex/latex/l3packages/xparse/xparse.sty)
(d:/texlive/2020/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty)
(d:/texlive/2020/texmf-dist/tex/latex/ctex/ctexhook.sty)
(d:/texlive/2020/texmf-dist/tex/latex/ctex/ctexpatch.sty)
(d:/texlive/2020/texmf-dist/tex/latex/base/fix-cm.sty
(d:/texlive/2020/texmf-dist/tex/latex/base/ts1enc.def))
(d:/texlive/2020/texmf-dist/tex/latex/ms/everysel.sty)
(d:/texlive/2020/texmf-dist/tex/latex/ctex/config/ctexopts.cfg)
(d:/texlive/2020/texmf-dist/tex/latex/ctex/engine/ctex-engine-xetex.def
(d:/texlive/2020/texmf-dist/tex/xelatex/xecjk/xeCJK.sty
(d:/texlive/2020/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.sty)
(d:/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec.sty
(d:/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(d:/texlive/2020/texmf-dist/tex/latex/base/fontenc.sty)
(d:/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
(d:/texlive/2020/texmf-dist/tex/xelatex/xecjk/xeCJK.cfg))
(d:/texlive/2020/texmf-dist/tex/xelatex/xecjk/xeCJKfntef.sty
(d:/texlive/2020/texmf-dist/tex/generic/ulem/ulem.sty)))
(d:/texlive/2020/texmf-dist/tex/latex/zhnumber/zhnumber.sty
(d:/texlive/2020/texmf-dist/tex/latex/zhnumber/zhnumber-utf8.cfg))
(d:/texlive/2020/texmf-dist/tex/latex/ctex/scheme/ctex-scheme-chinese.def
(d:/texlive/2020/texmf-dist/tex/latex/ctex/config/ctex-name-utf8.cfg))
(d:/texlive/2020/texmf-dist/tex/latex/tools/indentfirst.sty)
(d:/texlive/2020/texmf-dist/tex/latex/ctex/ctex-c5size.clo)
(d:/texlive/2020/texmf-dist/tex/latex/ctex/fontset/ctex-fontset-windows.def
(d:/texlive/2020/texmf-dist/tex/latex/ctex/fontset/ctex-fontset-windowsnew.def)
)) (d:/texlive/2020/texmf-dist/tex/latex/ctex/config/ctex.cfg) (./test.aux)
ABD: EverySelectfont initializing macros [1] (./test.aux) )
Output written on test.pdf (1 page).
Transcript written on test.log.

安裝軟件後的操作
在這裏插入圖片描述
二、Latex源文件的基本結構
1.數學公式兩種不同表示($ 與 $$的區別)
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
2.總結
在一個LaTeX文件中 ,通常由兩部分組組成:導言區和正文區。在導言區中,主要是進行一些全文的設置;在正文區中(有且僅有一個document),我們輸入相應的正文內容,例如文本、命令、數據公式等。
三、LaTex的中文處理方法
1.前提準備
(1)針對latex進行中文處理,首先應當確保該文件的格式是UTF-8,其次在文章的內容中加入 \usepackage{ctex}
(2)在撰寫中文時,應當設置相應的字體格式,比如黑體和楷體等。
(3)用於產生帶有編號的行間公式

	\begin{equation}
		AB^2=BC^2+AC^2.
	\end{equation}

具體顯示結果爲:
在這裏插入圖片描述
(4)\usepackage{ctex} 的具體內容中
在這裏插入圖片描述
出現下圖所示的文檔,共有157頁
在這裏插入圖片描述

\documentclass{article} %book,report,letter
\usepackage{ctex}
或者
\documentclass{ctexart} 

補充:C:\WINDOWS\system32>texdoc lshort-zh可以得到latex的簡單使用文件,共有136頁。
在這裏插入圖片描述
(2)最終的運行結果
在這裏插入圖片描述
四、LaTex的字體設置
(1)字體屬性:
在這裏插入圖片描述
(2)具體代碼實現

% 導言區
\documentclass [10pt]{article}%文檔大小一般僅有10 11 12 pt
\usepackage{ctex}
\newcommand{\myfont}{\textit{\textbf{\textsf{Fancy Text}}}}

% 正文區(文檔區)
\begin{document}
	% 字體族設置(羅馬字體、無襯線字體、打字機字體)
	\textrm{Roman Family} \textsf{Sans Serif Family} \texttt{Typerwriter Family}
	
	%字體聲明,後續的字體爲羅馬字體;{}可以限定字體聲明的作用範圍
	{\rmfamily Roman Family} {\sffamily Sans Family} {ttfamily Typerwriter Family}
	
	%sffamily後續的所有字體均爲無襯線字體。
	\sffamily who you are? you find self on everyone around.take you as the same as others!
	
	Are you wiser than others? definitely no. in some ways,may it is true. What can you achieve? a luxurious house? abrilliant car? an admirable career? who knows?
	
	%字體系列設置(粗細、寬度)
	\textmd{Medium Series} \textbf{Boldface Series}
	
	{\mdseries Medium Series} {\bfseries Medium Series} 
	
	%字體系列設置(自立、斜體、僞斜體、小型大寫)
	\textup{Upright Shape}  \textit{Italic Shape} \textsl{Slanted Shape} \textsc{Small Caps Shape}
	
	{\upshape Upright Shape}  {\itshape Italic Shape} {\slshape Slanted Shape} {\scshape Small Caps Shape}
	
	%中文字體
	{\songti 宋體} \quad {\heiti 黑體} \quad {\fangsong 仿宋} \quad{\kaishu 楷書}
	
	中文字體的\textbf{粗體}與\textit{斜體} %對於中文粗體是用黑體表示的,斜體是用楷書表示的
	
	%字體大小
	{\tiny	Hello}\\
	{\scriptsize Hello}\\
	{\footnotesize Hello}\\
	{\small Hello}\\
	{\normalsize Hello}\\ %這些size是於normalsize所相對的大小,是由文檔類的參數所控制的,如在開頭設置normalsize的大小爲10pt
	{\Large Hello}\\
	{\Large Hello}\\
	{\LARGE Hello}\\
	{\huge Hello}\\
	{\Huge Hello}\\
	
	%中文字號設置命令
	\zihao{5} 你好!
	
	\myfont %開頭定義一個字體設置命令
\end{document}

(3)最終結果顯示
在這裏插入圖片描述
五、LaTex的篇章結構
1.標題的排版
(1)初步文章架構構建
在這裏插入圖片描述
(2)含有段落的文章排版
在這裏插入圖片描述
(3)標題居中顯示的模板
在這裏插入圖片描述
2.帶有章節信息的排版
(1)具體代碼

% 導言區
\documentclass{ctexbook} %ctexbook,ctexrep

%\usepackage{ctex}

%======設置標題的格式=======
\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=\hspace{0pt}
	},
	subsection={
		format+=\zihao{5} \heiti \raggedright,
		name={,、},%切記此時的逗號是英文的,而頓號卻是中文的
		number=\arabic{subsection},
		beforeskip=1.0ex plus 0.2ex minus .2ex,
		afterskip=1.0ex plus 0.2ex minus .2ex,
		aftername=\hspace{0pt}
	}
}
% 正文區(文檔區)
\begin{document}
	%運用\section來構建小節,運用\subsection來構建子小節,運用\subsubsection來構建下一節
	% \\可以實現換行卻無法實現首行的縮進,可通過 \par
	% 利用\chapter產生帶章節的大綱,需要注意的是\documentclass{ctexbook}
	\chapter{緒論}
	\section{研究的目的與意義}
	\section{國內外研究現狀}
	\subsection{國內研究現狀}
	\subsection{國外研究現狀}
	\section{研究內容}
	\section{研究方法與技術路線}
	\subsection{研究方法}
	\subsection{技術路線}
	
	\chapter{實驗與結果分析}
	\section{引言}
	\section{實驗方法}
	\section{實驗結果}
	\subsection{數據}
	\subsection{圖表}
	\subsubsection{實驗條件}此時的subsubsection命令不起作用
	\subsubsection{實驗過程}
	\subsection{結果分析}
	\section{結論}
	\section{致謝}

\end{document}

(2)顯示結果
在這裏插入圖片描述
3.章節目錄的生成
(1)命令

\tableofcontents %用於生成全文的目錄

(2)具體效果
在這裏插入圖片描述
六、LaTex中的特殊字符

%導言區
\documentclass{article}

\usepackage{ctex} %中文處理宏包
\usepackage{xltxtra}
%正文區
\begin{document}
	\section{空白字符}
	%空行分段,多個空行等同1個
	%自動縮進(段落的分段是自動產生的 ),絕對不能使用空格代替
	%英文中多個空格處理爲1個空格,中文中空格將被忽略
	%漢字與其它字符的間距會自動由 Xelatex處理
	%禁止使用中文全角空格
	Are you wiserthan others? definitely. in some ways, may it is true. What canyou achieve? a luxurious house? a brillilantcar? an admirable career who knows?
	
	%當需要輸入空格這樣的空白字符時,可通過如下方式來實現
	% 1em(當前字體中的M寬度)
	a\quad b
	
	% 2em
	a\qquad b
	
	% 約爲1/6個em
	a\,b  a\thinspace b
	
	% 0.5個em
	a\enspace b
	
	% 空格(反斜槓+空格)
	a\ b
	
	% 硬空格(不能分割的空格)
	a~b
	
	% 1pc=12pt=4.218mm(kern hskip可產生指定寬度的空白)
	a\kern 1pc b
	
	a\kern -1em b
	
	a\hskip 1em b
	
	a\hspace{35pt} b %指定參數
	
	% 佔位寬度(根據參數所產生的佔位字符的寬度)
	a\hphantom{xyz}b
	
	%彈性長度
	a\hfill b
	
	\section{\LaTeX 控制符}
	\# \$ \% \{ \} \_{} \^{} \textbackslash \&
	%輸出結果爲:# $ % { } _ ^ \ &
	
	\section{排版字符}
	\S \P \dag \ddag \copyright \pounds
	
	\section{\TeX 標誌符號}
	\TeX{} \LaTeX{} \LaTeXe{}
	% xltxtra宏包提供
	\XeLaTeX  %編譯錯誤,說明沒有這個命令,可通過引入package來解決 \usepackage{xltxtra}
	\section{引號}
	`%數字鍵1左邊的符號,稱撇號
	'%單引號
	``%兩個連續的撇號
	''%兩個連續的單引號
	%最終的結果爲 ‘’ “ ”
	
	\section{連字符}
	- -- ---
	
	\section{非英文字符}
	\oe \OE \ae \AE \aa \AA \o \O \l \L \ss \SS 
	!` ?`  
	\section{重音字符(以o爲例)}
	\`o \'o  \^o \''o \~o \=o \.o \u{o} \v{o} \H{o} \r{o} \t{o}
	\b{o} \c{o} \d{o}
\end{document}

七、LaTeX中的插圖
1.運用命令來查看幫助文檔

texdoc graphicx

在這裏插入圖片描述
2.圖標類結果
(1)具體代碼

% 導言區
\documentclass{ctexart}

% 導言區 \usepackage{graphics}
% 語法 \includegraphics[<選項>]{<文件名>}  可選參數指定圖像的縮放比例,旋轉等
% 格式:EPS,PDF,PNG,JPEG,BMP
\usepackage{graphicx}
\graphicspath{{figures/},{pics/}]}%圖片在當前目錄下的figure目錄,指定圖像文件的搜索路徑
% 正文區(文稿區)
\begin{document}
	\LaTeX{}的插圖:
	
	\includegraphics{lion}
	
	%scale指定縮放因子
	\includegraphics[scale=0.3]{lion}%寫lion或lion.png均可以
		
	%height指定固定值的圖像高度,angle指定旋轉角度
	\includegraphics[height=2cm,angle=-45]{lion}
	
	%width指定固定值的圖像寬度
	\includegraphics[width=2cm]{lion}
	
	%版型0.2倍的圖像高度
	\includegraphics[height=0.2\textheight]{lion}
	
	%版型0.2倍的圖像寬度
	\includegraphics[width=0.2\textwidth]{lion}
\end{document}

(2)具體結果
在這裏插入圖片描述
八、LaTeX中的表格
1.相關代碼

%導言區
\documentclass{ctexart}

%正文區
\begin{document}
	\begin{tabular}{|l|c|c|c|p{1.5cm}|}%營造表格的構建環境,形成一個五列的表格;|用於產生單豎線,||用於產生雙豎線  
		\hline %\hline命令用於產生單橫線
		姓名 & 語文 & 數學 & 外語 & 備註 \\%\\用於實現文章的換行
		\hline \hline %	\hline \hline用於產生雙橫線
		張三 & 87 & 100 & 93 & 優秀 \\
		\hline
		李四 & 75 & 64 & 52 & 補考另行通知 \\
		\hline
		王二 & 80 & 82 & 78 & 良好 \\
		\hline
	\end{tabular}
\end{document}

2.相關表示結果
在這裏插入圖片描述
3.具體文檔詳見

textdoc booktab

在這裏插入圖片描述
九、LaTeX中的浮動體
1.加入環境信息後,表格和圖片信息發生浮動
在這裏插入圖片描述
3.設置文章標題以及相應的排版位置
(1)具體代碼

%導言區
\documentclass{ctexart}

\usepackage{graphicx}
\graphicspath{{figures/},{pics/}]}

%正文區
\begin{document}
	\LaTeX{}的插圖:
	\begin{figure}[htbp]%firgure環境  htbp指定浮動體的位置
		\centering%隻影響環境中的內容
		\includegraphics[scale=0.3]{lion}
		\caption{\TeX 系統的吉祥物--小獅子}
	\end{figure}
	
	
	在\LaTeX{}中的表格
	\begin{table}[h] %table環境
		\centering
		\caption{考試成績單}
		\begin{tabular}{|l|c|c|c|r|}%營造表格的構建環境,形成一個五列的表格;|用於產生單豎線,||用於產生雙豎線  
			\hline %\hline命令用於產生單橫線
			姓名 & 語文 & 數學 & 外語 & 備註 \\%\\用於實現文章的換行
			\hline \hline %	\hline \hline用於產生雙橫線
			張三 & 87 & 100 & 93 & 優秀 \\
			\hline
			李四 & 75 & 64 & 52 & 補考另行通知 \\
			\hline
			王二 & 80 & 82 & 78 & 良好 \\
			\hline
		\end{tabular}
	\end{table}

\end{document}

(2)相應的結果
在這裏插入圖片描述
在這裏插入圖片描述
4.實現了交叉引用

%<允許位置>參數(默認tbp)
%h,此處(here)一代碼所在的上下文位置
%t,頁頂(top)-代碼所在頁面或之後頁面的頂部
%b,頁底( bottom)-代碼所在頁面或之後頁面的底部
%p,獨立一頁(page)-浮動頁面

在這裏插入圖片描述

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