latex 常用小結


在寫論文,甚至有些課程的報告的時候,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} 包圍起來。 里面可以有摘要,很多個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}。 同時引用兩篇:\cite{KDE,Another}注意逗號前后都不要有空格,不然會報錯。

值得注意的是,如果你的正文沒有引用該文章,那么即使在.bib中有該文章的信息,生成的pdf的reference列表中也不會有該文章的。

2.3 章節

\section{model1}, \subsection{...}, \subsubsection{...}等等

2.5 縮進

每段開頭想要縮進,或者不要縮進: \indent \noindent

2.6 換行: \\

2.7 數學公式

記得用$ $把公式的內容包圍起來,或者用 \begin{equation}  \end{equation} 。 公式中粗體表示向量,用\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 上也有很好用的快捷按鈕:

公式的高級用法,例如連等號對齊,多個公式只用一個label:

\usepackage{eqnarray}

\begin{eqnarray}\label{eq:eq1}
r_{ij} &=& \widetilde{U}_i \cdot \widetilde{V}_j \nonumber \\
&=& U_{ia} \cdot V_j + U_{ib} \cdot (A_j \mathbf{B})
\end{eqnarray}

 

2.8 列表

\begin{enumerate} 

\item ..

\item ..

\end{enumerate}  

這個是帶序號的列表。 把enumerate 換成itemize, 就是不帶序號的。例如:

如果想要縮進,需要\usepackage{enumitem}  ,然后:

\begin{enumerate}[label=(\roman*),leftmargin=3\parindent]
\item 。。。
\item 。。。
\item 。。。
\end{enumerate}

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}

要引用圖片的時候,就用 \ref{fig:timeliness}。 圖片可以裁剪,用法如:\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}

 \footnotetext{We。。。.}

更多用法可以參考:https://en.wikibooks.org/wiki/LaTeX/Tables  。 注意可能要引用一些包,例如

\usepackage{caption}
\usepackage{multirow}

 

 2.11 字體

意大利斜體: \textit{文本}
slanted斜體: \textsl{文本}

加粗命令: \textbf{文本}

 

好了,我上次用到的就這么多了。希望以后回頭看看的時候,可以作為回憶的參考。 長期更新。

其他:

一份不太簡短的 LATEX  介紹 http://www.mohu.org/info/lshort-cn.pdf

數學符號:

 

 一個很全面的數學符號集: http://blog.sina.com.cn/s/blog_4df4d74401014qxb.html

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM