almost 9 years ago
在昨天弄了半天的LaTeX在Mac上的環境建置後,
就要開始用LaTeX來寫文件了,除了網路上有不少Template可以下載:LaTeX Templates、ShareLaTeX
當然最重要的就是要熟悉LaTeX語法啦,這邊就寫了一個簡單的.tex把常用到的功能集結在一起
也算是一個方便的Template給大家參考:[打包下載]、[PDF預覽]
- Title Page (Multi-Purpose Large Font)
- report格式
- 頁碼
- 自動生成:目錄,圖目錄,表目錄
- 引用、項目符號、數學式、表格、外部引入圖片
- 參考文獻
參考資料
以下就不詳盡解釋每行語法的功能,可以自己下載回去研究看看:
\documentclass[12pt,a4paper]{report}
% 中文化
\usepackage{fontspec}
\usepackage{xeCJK} %中英文字型可分開設定
\setmainfont{BiauKai} %設定中文字型
% Title Page
\usepackage{xcolor}
\usepackage{fix-cm}
% 圖目錄,表目錄
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
% 引入圖片
\usepackage{graphicx} %載入圖片
\graphicspath{{images/}} %設定圖檔位置 image/
%============================================
% 封面
%============================================
\begin{document}
%\title{常用LaTex格式}
%\author{MarsW}
%\date{\today}
%\maketitle %預設的title字型太小
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Multi-Purpose Large Font
% http://www.LaTeXTemplates.com
% Original author: Frits Wenneker (http://www.howtotex.com)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setlength{\oddsidemargin}{0mm}
\setlength{\evensidemargin}{0mm}
\newcommand{\HRule}[1]{\hfill \rule{0.2\linewidth}{#1}}
\definecolor{grey}{rgb}{0.9,0.9,0.9}
\thispagestyle{empty} % Remove page numbering on this page
\colorbox{grey}{
\parbox[t]{1.0\linewidth}{
\centering \fontsize{50pt}{80pt}\selectfont
\vspace*{0.7cm}
\hfill \LaTeX \\
\hfill Title \\
\hfill Template\par
\vspace*{0.7cm}
}
}
\vfill % Space between the title box and author information
{\centering \large
\hfill Author \\
\hfill University Name \\
\hfill Department Name \\
\hfill \texttt{email} \\
\HRule{1pt}}
%============================================
% 目錄,圖目錄,表目錄
%============================================
\tableofcontents
\thispagestyle{empty}
\listoffigures
\thispagestyle{empty}
\listoftables
\thispagestyle{empty}
%============================================
% Start
%============================================
% 內文開始:設定頁碼
\newpage
\setcounter{page}{1}
\pagenumbering{arabic}
% --- chapter1 ------------------------------
\chapter{Format}
\section{基本格式}
先來個最簡單的測試文:
\subsection{Hello World}
How to compile basic hello world into a pdf?
Write your favorite text editor create file and copy/paste the following (with hello.tex)\\
強迫換行,這裡不會縮排\\
The output of this command \$latex hello.tex will be a dvi
file (hello.dvi).
\paragraph{}
新的段落,所以這裡會縮排兩格\\
This file (.dvi) can be converted by \$dvipdf
hello.dvi The get an pdf file from tex file, run this
command \$texi2pdf hello.tex
\section{引言Quote}
範例(Example):
\begin{quotation}
引言也會自動縮排The quote and quotation environments are similar, but use different
settings for paragraph indentation and spacing.
\end{quotation}
This file (.dvi) can be converted by \$dvipdf
hello.dvi The get an pdf file from tex file, run this
command \$texi2pdf hello.tex
\section{項目符號}
\begin{enumerate}
\item 第一大項,這裡是第一大項。
\item 第二大項,這裡是第二大項。
\begin{enumerate}
\item 第一小項,這裡是第一小項。
\item 第二小項,這裡是第二小項。
\end{enumerate}
\item 第三大項,這裡是第三大項。
\end{enumerate}
% --- chapter2 ------------------------------
\chapter{Document Structure}
report格式:新的chapter或是list,reference(bibliography)會自動開新頁
\section{參考文獻}
The following symbols characters are reserved by LATEX because
they introduce a command and have a special meaning.
\cite{han2002mining}
\section{數學式}
\subsection{Math in line}
有用數學式$A$ vs. A 沒有用數學式,$y=\beta_0+\beta_1x+\beta_2x^2$
\subsection{Math display mode}
\[
x_{1}^{(k+1)} = \frac{1}{a_{11}}(b_{1} - \sum_{j < 1}{a_{1j}x_{j}^{(k+1)}} - \sum_{j > 1}{a_{1j}x_{j}^{(k)}})
\]
\[
x_{2}^{(k+1)} = \frac{1}{a_{22}}(b_{2} - \sum_{j < 2}{a_{2j}x_{j}^{(k+1)}} - \sum_{j > 2}{a_{2j}x_{j}^{(k)}})
\]
\section{表格}
The following symbols characters are reserved by LATEX because
they introduce a command and have a special meaning.
\begin{table}[H] % 進入Floats環境
\begin{tabular}[t]{lll} %t 前端對齊 c置中對齊
\hline
column1 & column2 & column3 \\
\hline
item1 & item2 & item3 \\
itemA & itemB & itemC \\
\hline
\end{tabular}
\caption{最基本的表格} % 表會自動編號
\end{table}
\begin{table}[H] % 進入Floats環境
\centering
\begin{tabular}[t]{lll} %t 前端對齊 c置中對齊
\hline
column1 & column2 & column3 \\
\hline
item1 & item2 & item3 \\
itemA & itemB & itemC \\
\hline
\end{tabular}
\caption{最基本的表格}
\end{table}
The following symbols characters are reserved by LATEX because
they introduce a command and have a special meaning.
\section{圖片}
\begin{figure}[H] % 進入Floats環境
\centering
\includegraphics[scale=0.5]{image1}
\caption{圖的標題} % 圖會自動編號
\end{figure}
\begin{figure}[H] % 進入Floats環境
\centering
\begin{subfigure}[b]{0.45\textwidth} % 進入Floats環境
\includegraphics[width=\textwidth]{image1}
\caption{aaa} % 圖會自動編號
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth} % 進入Floats環境
\includegraphics[width=\textwidth]{image1}
\caption{bbb} % 圖會自動編號
\end{subfigure}
\caption{圖的標題} % 圖會自動編號
\end{figure}
\begin{figure}[H] % 進入Floats環境
\centering
\begin{subfigure}[b]{0.3\textwidth} % 進入Floats環境
\includegraphics[width=\textwidth]{image1}
\caption{aaa} % 圖會自動編號
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth} % 進入Floats環境
\includegraphics[width=\textwidth]{image1}
\caption{bbb} % 圖會自動編號
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth} % 進入Floats環境
\includegraphics[width=\textwidth]{image1}
\caption{ccc} % 圖會自動編號
\end{subfigure}
\caption{圖的標題} % 圖會自動編號
\end{figure}
The following symbols characters are reserved by LATEX because
they introduce a command and have a special meaning.
% --- References ----------------------------
\renewcommand\bibname{References} %bibname "Bibliography"改名成"References"
\bibliographystyle{plain}
\bibliography{refer}
\thispagestyle{empty}
\end{document}
延伸閱讀
LaTeXDiff+GitLaTeX追蹤修訂