在寫論文,甚至有些課程的報告的時候,latex是常用的工具。這篇博文簡單的記錄了latex常用的一些内容。
最近發現一個線上latex網站 https://www.sharelatex.com/ 以後就不用在電腦上安裝CTEX了。
1 基本子產品
沒用過latex的讀者,最想問的問題莫過于latex的 “hello world”程式長什麼樣。那麼下面就貼一張圖檔來展示:

latex就是通過一些列指令來控制排版的。 一些一目了然的參數我就不解釋了。第一行的\documentclass{article},article就是指一般的文檔格式。可以換成,其他的,比如book,就是書的版式,分成很多章節chapter,還有一些論文的版式,例如IEEEtran,sig-alternate,這兩種都是一頁分兩列的,看着很高端。
%這是我的一個作業報告的前奏部分
\documentclass[a4paper,11pt]{article}
\author{leavingseason}
\title{Hello World}
\date{\today}
\usepackage[english]{babel}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{xcolor}
\usepackage{float}
\usepackage{geometry}
\geometry{left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}
\usepackage指需要使用一些宏包。 交代封面和版式的指令完之後,就開始了文檔内容。用
\begin{document} 和\end{document}\begin{document} 和\end{document}
包圍起來。 裡面可以有摘要,很多個section等等常見的東西。
好了,大體上latex的流程就是這樣。下面,我們要做的,就是實際中需要用哪些東西,再亡羊補牢。
2 常用指令
2.1一篇文章通常很長。那麼就需要把它分成多個子檔案。每個檔案都是以.tex為字尾,用指令\input 或者\include 把它們添加進主檔案中。
\input{introduction}
\input{model1}
\input{model2}
\input{model3}
\input 在插入子檔案的時候不換頁,\include在插入子檔案的時候強制換頁
2.2 引用參考文獻
\bibliographystyle{plain}
\bibliography{bib/tex}
把參考文獻寫入一個以.bib為字尾名的檔案中,例如bib/tex.bib,然後用上面的兩條語句就可以了。.bib檔案的内容如下
@article{KDE,
title = {Estimating the helpfulness and economic impact of product reviews: Mining text and reviewer characteristics},
author = {Ghose, Anindya and Ipeirotis, Panagiotis G},
journal = {Knowledge and Data Engineering, IEEE Transactions on},
volume = {23},
number = {10},
pages = {1498--1512},
year = {2011},
publisher = {IEEE}
}
@inproceedings{ICDM,
title={Modeling and predicting the helpfulness of online reviews},
author={Liu, Yang and Huang, Xiangji and An, Aijun and Yu, Xiaohui},
booktitle={Data Mining, 2008. ICDM'08. Eighth IEEE International Conference on},
pages={443--452},
year={2008},
organization={IEEE}
}
@inproceedings{ICEC,
title={Designing novel review ranking systems: predicting the usefulness and impact of reviews},
author={Ghose, Anindya and Ipeirotis, Panagiotis G},
booktitle={Proceedings of the ninth international conference on Electronic commerce},
pages={303--310},
year={2007},
organization={ACM}
}
擷取這樣的内容有一個小技巧:在谷歌學術中輸入你要引用的論文名字,然後點開“引用”那個連結,再點選"導入BibTeX",引用的格式就出來了。
@article{KDE,article={}... 在這個指令中,KDE是這篇引用文章的索引号,是你自己定義的。在你的正文中要引用他的話,就用 \cite{KDE}
值得注意的是,如果你的正文沒有引用該文章,那麼即使在.bib中有該文章的資訊,生成的pdf的reference清單中也不會有該文章的。
2.3 章節
\section{model1}, \subsection{...}, \subsubsection{...}等等
2.5 縮進
每段開頭想要縮進,或者不要縮進: \indent \noindent
2.6 換行: \\
2.7 數學公式
記得用$ $把公式的内容包圍起來,或者用
。 公式中粗體表示向量,用\mathbf{}:
\begin{equation}\label{eq:rbf}
\phi(\mathbf{x}|\mathbf{\mu},\Sigma) = f(\frac{(\mathbf{x}-\mathbf{\mu})^T(\mathbf{x}-\mathbf{\mu})}{\sigma^2})
\end{equation}
指數用 ^{指數部分}, 下标用 _{下标部分} , 分數用 \frac{分子}{分母} , WinEdit 上也有很好用的快捷按鈕:
2.8 清單
\begin{enumerate}
\item ..
\item ..
\end{enumerate}
這個是帶序号的清單。 把enumerate 換成itemize, 就是不帶序号的。例如:
2.9 插入圖檔:
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{pic/timeliness.JPG}
\caption{An example of review helpfulness vs. time of review.}
\label{fig:timeliness}
\end{figure}
???
???。 圖檔可以裁剪,用法如:\includegraphics[trim={0 4cm 0 2cm},clip,width=0.5\textwidth]{char_cate2.pdf}
如果版面是雙欄的,圖檔比較大想跨雙欄的話,可以用\begin{figure*}
并排顯示多張圖:
\begin{figure*}[htbp]
\centering
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={1cm 4cm 1cm 3cm},clip,width=1\textwidth]{charts/geo_auc.pdf}
\caption{Gpredictors}
\label{fig:g_auc}
\end{subfigure}%
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={1cm 4cm 1cm 3cm},clip,width=1\textwidth]{charts/mobility_auc.pdf}
\caption{U predictors}
\label{fig:u_auc}
\end{subfigure}
\begin{subfigure}{.33\textwidth}
\centering
\includegraphics[trim={1cm 4cm 1cm 3cm},clip,width=1\textwidth]{charts/ratings_auc.pdf}
\caption{R predictors. }
\label{fig:r_auc}
\end{subfigure}
\caption{AUC performance comparison for individual predictors of different groups..}
\label{fig:heatmap}
\end{figure*}
2.10 表格
實質上是用指令控制表格框。注意 (1) \label{tab:d2}要放在\end{table}之前,不能放在\begin{table}之後,不然引用\ref{tab:d2}的時候會出問題 (2)表格等某些元素裡面不能用footnote,要用footnotemark+footnotetext代替
\begin{table}
\centering
\caption{Basic statistics of three cities}
\begin{tabular}{|c|c|c|l|} \hline
City&\#column1&\#column2&\#column3\footnotemark\\ \hline
Shanghai&127,503 & 80,914& 7,190 \\ \hline
Beijing&10,396 & 6,772&5,917\\ \hline
Guangzhou & 1,273 & 1,844 & 1,747 \\
\hline\end{tabular}
\label{tab:d2}
\end{table}\begin{table} \centering \caption{Basic statistics of three cities} \begin{tabular}{|c|c|c|l|} \hline City&\#column1&\#column2&\#column3\footnotemark\\ \hline Shanghai&127,503 & 80,914& 7,190 \\ \hline Beijing&10,396 & 6,772&5,917\\ \hline Guangzhou & 1,273 & 1,844 & 1,747 \\ \hline\end{tabular} \label{tab:d2} \end{table}
\footnotetext{We only count the shops which has at least one review in 2012.}
好了,我上次用到的就這麼多了。希望以後回頭看看的時候,可以作為回憶的參考。 長期更新。
其他:
一份不太簡短的 LATEX 介紹 http://www.mohu.org/info/lshort-cn.pdf
數學符号: