Beginning of L
ATEX
Chiao-Ching Huang
iAgent Lab
August 6, 2012
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 1 / 39
1 Introduction
2 Let’s Start
3 Latex Document
4 Tables, Figures, Math
5 JabRef, .bib
Section Outline
1 Introduction
Preface
Latex Thinking
2 Let’s Start
3 Latex Document
4 Tables, Figures, Math
5 JabRef, .bib
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 3 / 39
About Tex and Latex
Tex
史丹福大學Professor Donald Knuth (“The Art of Computer Programming.”的作者),因為無法忍受當時的排版水準,決定自 創一套新的系統,TEX系統
LaTex
Leslie Lamport基於Tex系統,發展使用上更為便利的Latex系統。
Why Latex?
Latex
Latex = 純文字 + 排版控制程式碼 Editor 6=Compiler 6= Viewer Why..?
純文字編輯,可跨平台
圖片、表格自動排版
易於專注在文章的內容,而非排版
參考文獻整理容易
配合 SVN 方便控制版本差異
許多大型會議與期刊都有排版格式檔 (含論文)
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 5 / 39
Section Outline
1 Introduction
2 Let’s Start
Goal Installation Chinese in Latex Latex in Mac
3 Latex Document
4 Tables, Figures, Math
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 6 / 39
Goal
Use Latex to...
Write a paragraph Use item labels Build tables Include pictures Write math equations Reference , Bibtex
用LaTex實作一份本次Orientation 的科目大綱。
編寫接下來幾天的學習心得。
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 7 / 39
Installation
Latex (Windows)
Miktex (suggested compiler) Google: Miktex
http://miktex.org/2.9/setup Texmaker (suggested Editor)
Google: Texmaker
http://www.xm1math.net/texmaker/download.html
? Options>Configure Texmaker>
? Editor>Editor Font Encoding>UTF-8
? Commands>Pdf Viewer>(your pdf viewer)
? Quick Build>PdfLaTeX+View PDF
If you need Chinese...
Useful Google keywords:
CJK packages Latex 中文 Or...
Follow the instruction in
http://disa.csie.ntu.edu.tw/~alcoholic/Latex/latex_in_Windows.pdf
Using the package at
http://disa.csie.ntu.edu.tw/~alcoholic/Latex/texmf.zip
instead of broken link in the pdf file.
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 9 / 39
about Mac
Well, I’m not a Mac user.... Maybe you can try:
Mactex
http://www.tug.org/mactex/
http:
//guides.macrumors.com/Installing_LaTeX_on_a_Mac
Section Outline
1 Introduction
2 Let’s Start
3 Latex Document
Hello world, structures Title and Table of contents Itemization, Symbols Exercise
4 Tables, Figures, Math
5 JabRef, .bib
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 11 / 39
Hello world
After installation, try:
\documentclass[12pt]{report}
\begin{document}
Hello, world!
\end{document}
and save as a file (with a filename) compile it!
If you use texmaker : press F6, then F7 to look the result.
Exercise : Hello, world!
空白,換行
Area control : {, and} Instruction Command : \
你在 Editor ( Texmaker ) 中按 Enter,不代表排版後就是從這裡 斷行
Latex會依一行應有的寬度經過整體計算後自動補成一整行後再來
斷行。
在 Editor 中的 space (空白) 與 Enter (換行) 跟 Latex 編譯後的 結果是兩回事
You’ll feel it later... especially when you are writing a paper/thesis.
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 13 / 39
Document Structure
\documentclass[12pt]{report}
%preamble area, include packages here. Example: \usepackage{color}
\begin{document}
\section{Section I}
Hello, world!
\end{document}
Comment : %
Exercise: Try structures - chapter, section, subsection, paragraph...
封面,大綱
%Declaration part
\title{your title}
\author{your name}
\date{\today}
\maketitle%make a title page with these information
? With the organized structure, you can use:
\tableofcontents
\listoffigures%圖目錄
\listoftables%表目錄
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 15 / 39
字體大小
Forget about the 10pt, 14pt, 16pt ... when you’re writing in latex.
We use 相對大小 here. (當然也有絕對大小,如有需要,請洽google)
\tiny,\scriptsize, \footnotesize, \small,
\normalsize,
\large, \Large, \LARGE, \huge, \Huge Example: size
{\largethe sentences}
\begin{small}
Sentences
\end{small}
條列項目
\begin{itemize}
\item no.1 statement
\item no.2 statement
\item no.3 statement
\end{itemize}
Try different (and nested) item label:
itemize,enumerate (編號), description(敘述,\item[desc.]) usable package : \usepackage{enumerate}
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 17 / 39
符號,連結
You may ask :
How to writehttp://....?
\url{http://....}
How to write lots of symbols ? Usually, use\
Example: \%
http://disa.csie.ntu.edu.tw/~alcoholic/Latex/latexsheet.pdf
1 Write a paragraph with nested itemize labels under a section under a chapter.
2 Write down your notes of the orientation.
3 Try the difference between \paragraph{} and nextline : \\.
空行在 Latex 中是有其效用的。如只是要在editor空行,建議在空
行前使用%,將整行作為註解。 換行可以使用\\,並可在其後添
加間隔,如\ \ [1cm]
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 19 / 39
Exercise Answer
\documentclass[12pt]{report}
\begin{document}
\chapter{Exercise}
\section{Hi}
Hello, world!
\begin{itemize}
\itemstatement 1
\itemstatement 2
\itemstatement 3
\begin{enumerate}
\itemno.1 statement
\itemno.2 statement
\end{enumerate}
\end{itemize}
\end{document}
Section Outline
1 Introduction
2 Let’s Start
3 Latex Document
4 Tables, Figures, Math
Tables Figures Math Exercise
5 JabRef, .bib
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 21 / 39
表格
Build a Table as: This is a table.
the table in latex.
\begin{tabular}{|l|r|c|c|}
%t : top, b: bottom, c: center與文字並排時排版位置
%— : 直的格線 l : 靠左對齊 c : 置中對齊 r : 靠右對齊
% \hline : 橫的格線, &: 換格,\\: 換行
\hline
This & is & a & table. \\ \hline
the & table &\multicolumn{2}{c}{in latex.} \\ \hline
\end{tabular}
表格浮動環境
浮動環境: 讓 latex 自行安排表格(圖片)位置,僅能‘建議’ latex 放
置的位置。
\begin{table}[h]
%進入浮動環境,h: here,t: top,p: page ,要求latex將表格置於該位置
% !h: 強烈要求
\caption{Title of the table} %表格的標題
\label{引用代碼}
\begin{tabular}{|l|r|c|c|}
\hline
This &is &a&table.\\ \hline
the & table &\multicolumn{2}{c}{in latex.} \\ \hline
\end{tabular}
\end{table}
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 23 / 39
引用,參照
\label{引用代碼}
%設定引用代碼
\ref{引用代碼}
%引用label所標示的圖/表/文句
圖,表,章節 : 自動引用該編號 Ex:
Fig. \ref{yourref}
Section. \ref{yourref}
You may need to compile it TWICE to correct the structures.
插入圖片
\usepackage{graphicx}
%In the preamble area
\includegraphics[width=5cm]{pic.png}
%.png .jpg .pdf
%可設定width = 0.7 \textwidth
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 25 / 39
圖的浮動環境
Almost the same as the tables
\begin{figure}[h]
% \begin{center}
\includegraphics[0.8\textwidth]{pic.png}
% \end{center}
\caption{Title of the Figure} %圖的標題
\label{引用代碼}
\end{figure}
You may need
置中: \begin{center}, \end{center}
調整縱向空間 : 產生空行 \bigskip, \medskip, \smallskip 調整橫向空間 : 產生空白\quad, \qquad
Exercise
Build a table and include a picture
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 27 / 39
數學表示法
The most powerful part of Latex.
a b Y d c
$
∧ a b Y ∧ c d$
%inline mode
\[
∧ a b Y ∧ c d\]
%display mode
Everyone needs different mathematics functions, please check
http://en.wikibooks.org/wiki/LaTeX/Mathematics.
數學表示法
%Different modes of fraction
$f(x,y) = y / ( x-7 ) = \frac{ y }{ (x-7) }$
f (x , y ) = y /(x − 7) = (x −7)y
%Latex provide simple ways to show math function:
$\sqrt [m]{n }, \forall m \in \Re,\exists n$
√m
n, ∀m ∈ <, ∃n
While you need a blank in math mode, use ∼
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 29 / 39
數學式編號,對齊
\usepackage{amsmath}
%數學式編號
\begin{equation}
數學式子
\end{equation}
%數學式對齊
\begin{align}
\alpha&= a + b -c\\
\beta&= 2c
\end{align}
Math Exercise
You must know one thing:
× Wrong Function: x + 1 = y text in a function x − 1 = z Correct Function: x + 1 = y text in a function x − 1 = z
If you need to type text in your function, use\text{your words}
Exercise
Try the different effects of
\sum {i = 0}∧{100}x i
In the inline mode and display mode
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 31 / 39
Exercise
Exercise
Write a math equation to show the following:
α = x2+ y
x − y (1)
β =
100
X
i =1
xiyi + ci (2)
Section Outline
1 Introduction
2 Let’s Start
3 Latex Document
4 Tables, Figures, Math
5 JabRef, .bib
JabRef
Reference and .bib
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 33 / 39
JabRef
A good tool for using bibtex
http://jabref.sourceforge.net/
You can easily manage your references.
參考文獻範例
\usepackage{natbib,hyperref}
%Natbib : for reference
%Hyperref : for hyperlink
\bibliographystyle{plain}
\bibliography{ref}
%引入ref.bib
\cite{yourcitekey}
%yourcitekey = keyword defined by yourself
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 35 / 39
.bib
How to get .bib
.bib format
@article{Knuth2004, ← This is the Key author = “Knuth, Donald E.”,
year = “2004”,
title = “The{\TeX} Journal”, journal = “SayYa-Publisher”, }
http:
//en.wikibooks.org/wiki/LaTeX/Bibliography_Management
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 37 / 39
In Texmaker
You have to compile the .bib file.
If you are using texmaker, compile it several times:
1 pdflatex your.tex (pressF6)
2 bibtex your.tex (pressF11)
3 pdflatex your.tex (pressF6)
4 pdflatex your.tex (pressF6)
Note. Compile twice ⇒ make the correct structure.
Thank you.
If you want to know more, here is your best friend:
http://en.wikibooks.org/wiki/LaTeX If you want to draw something:
http://www.texample.net/tikz/examples/
Please contact me if:
1 You cannot solve your latex problem by Google, your best problem solver.
2 You want to make slides by Latex.
3 You want to draw plots in latex.
Chiao-Ching Huang (iAgent Lab) Beginning of LATEX August 6, 2012 39 / 39