Latex 문법 정리
1. \documentclass[a]{b}
[a]
( = document class ) 의 예시 :
-
book, report, article, letter, slides
-
반드시
\begin{document}
~\end{document}
안에 내용 넣어줘야
{b}
( = document class 옵션 ) 의 예시 :
- 폰트 크기 : 10pt, 11pt, 12pt
- 페이퍼 크기 : letterpaper, a4paper
- 2개의 칼럼 사용 : twocolumn
- 양쪽 여백 : twoside
- 기타 : landsacape, draft
2. 기본 규칙
- multiple space : SINGLE space
- empty line : a PARAGRAPH SEPARATOR
- enter만으로 새로운 문단 되는거 아니다!
- special character : “\”
- “\” 자체를 쓰고 싶으면 : \textbackslash
-
commands : \command[optional parameter]{parameter}
- comments : %
(1) 스페이스
\documentclass{article}
\begin{document}
Hello World!
% Hello World! (동일하다)
\end{document}
(2) 줄바꿈
- 줄 바꿈 없음
\documentclass{article}
\begin{document}
ABC
DEF
\end{document}
ABC DEF
- 줄 바꿈 몇줄이든, 1줄
\documentclass{article}
\begin{document}
ABC
DEF
\end{document}
ABC
DEF
(3) 특수문자
\documentclass{article}
\begin{document}
\# \$ \% \^{a} \& \_ \{ \} \~{a} \textbackslash ~
\end{document}
(4) 주석
\documentclass{article}
\begin{document}
%this is comment
this is not comment
\textbackslash
\end{document}
(5) 문서 구조
-
\documentclass[…]{…}
- [11pt, twoside, a4paper] : fontsize, papersize, format … (predefined in the class file)
- {article} : ex) article, book, report, or a journal class file
-
\usepackage{…}
- ex) amsmath, graphicx, hyperref, math-tax ….
-
\begin{document}
- main text here
\end{document}
- Sections 틀
\part
\chapter
\appendix
\tableofcontents
- Sections 작성
\section{}
\subsection{}
\subsubsection{}
\paragraph{}
- 기타
\title{}
,\author{}
,\date{}
\maketitle
필수
\begin{abstract}
~\end{abstract}
\documentclass[a4paper, 11pt]{article}
%----------------------------------------------------%
\author{H.~Part1}
\title{Minimalism}
\maketitle
%----------------------------------------------------%
\begin{document}
%----------------------------------------------------%
\tableofcontents
%----------------------------------------------------%
\section{Sub title1}
Well, and here begins my lovely article
\subsection{Sub Sub title1}
11111
\subsection{Sub Sub title2}
11111
\section{Sub title2}
\ldots{} and here it ends
\section{Sub title3}
\ldots{} and here it ends
%----------------------------------------------------%
\end{document}
3. 추가 문법
(1) Qutation Mark ( 따옴표 )
- 여 & 닫는 따옴표가 다르다
- 여는 따옴표 : ``
- 닫는 따옴표 : ‘’
\documentclass{article}
\begin{document}
``Please press `x' key. ''
\end{document}
“Please press ‘x’ key
(2) Space, Line Break, Upper Letter, URL
- 스페이스바 vs
~
:~
를 사용함으로써, 앞에거를 하나의 단어로 만들어줌- Ex) Fig. 5 : 2개의 단어
- Ex) Fig.~5 : 1개의 단어
- “대”문자를 쓰고, 끝에 마침표를 넣을 경우 문장으로 인식을 안함.
- ex) I really love IT!
- ex) I really love IT\@!
\documentclass{article}
\begin{document}
indent due to first sentence\\
cf.Fig.~5\\
cf.~Fig.~5\\ % cf. Fig. 5는 줄바꿈되면서, 짤리면 안되므로!
cf. Fig.~5\\
I like BASIC. What about you? \\
I like BASIC\@. What about you?\\
\end{document}
indent due to first sentence
cf.Fig. f.Fig. ㅊ5
cf. Fig. 5
cf. Fig. 5
I like BASIC. What about you?
I like BASIC. What about y
\usepackage{hyperref}
\documentclass{article}
\begin{document}
http://www.rich.edu/\~{}bush\\
\url{http://www.rich.edu/\~{}bush}
\end{document}
(3) 점 (…), 특별한 알파벳
\documentclass{article}
\begin{document}
read\slash write \\
\ldots \\
H\^{o}tel, na\"\i ve, Stra\ss e \\
\end{document}
read/write
. . .
Hˆotel, na ̈ıve, Straße
(4) 긴 대쉬
- dash
- underline
- emphasize
Dash
\documentclass{article}
\begin{document}
I like B-A-S-I-C\@. \\
I like B--A--S--I--C\@.\\
\underline{I like BASIC}. \\
\emph{I like BASIC}.
\end{document}
for indent
I like B-A-S-I-C.
I like B–A–S–I–C.
I like BASIC.
I like BASIC.
4. Packages 사용
사용 방법 / 조건
- 사용 방법 :
\usepackage{패키지명}
- 조건 :
\begin{document}
“전”에 사용할 것
예시
- fullpage : 1인치 여백
- anysize :
\marginsize{l}-{r}-{t}-{b}
- multicol : n개의 칼럼 사용
\begin{multicols}{n}
- graphics :
- ex) 이미지 보여주기 :
includegraphics[width=x]{file}
- ex) 이미지 보여주기 :
- url :
\url{http://…}
5. 목록, 인용구, 코드
( 해당 리스트 안의 내용은 \item
붙여줘야! )
( \item[x]
를 사용하게 되면, 앞의 문자표는 1,2,3이나, . . . 등이 아닌, 무조건 x로 사용됨 )
\begin{enumerate}
: 1,2,3. ..\begin{itemize}
: . . .\begin{description}
(1) enumerate & itemize
\documentclass[a4paper, 11pt]{article}
\begin{document}
\begin{enumerate}
\item A
\item B
\item C
\end{enumerate}
\begin{itemize}
\item a
\item[*] b
\item c
\end{itemize}
\end{document}
1. A
2. B
3. C
• a
* b
• c
\documentclass[a4paper, 11pt]{article}
\begin{document}
\begin{enumerate}
\item A
\begin{itemize}
\item Aa
\item[*] Ab
\item[-] Ac
\end{itemize}
\item C
\end{enumerate}
\end{document}
1. A
• Aa
* Ab
- Ac
2. C
(2) description
\documentclass[a4paper, 11pt]{article}
\begin{document}
\begin{description}
\item[Word1] definition of word1
\item[Word2] definition of word2
\item[Word3] definition of word3
\end{description}
\end{document}
(3) 정렬
\begin{flushleft}
\begin{flushright}
\begin{center}
(4) 인용
\begin{quote}
: 인용\begin{quotation}
: 인용 ( with 새 문단 indentation )\begin{verse}
뒤에 반드시 \end{}
도 해줘야
\documentclass[a4paper, 11pt]{article}
\begin{document}
%------------------------------------%
\begin{quote} % 문단 X
This is quote. This is quote.This is quote.This is quote.This is quote.This is quote.This is quote.This is quote.
\end{quote}
\\
%------------------------------------%
\begin{quotation} % 문단 O
This is quotation ( with indented paragraph ). This is quotation ( with indented paragraph ).This is quotation ( with indented paragraph ). This is quotation ( with indented paragraph )
\end{quotation}
\\
%------------------------------------%
\begin{verse} % 내여쓰기
This is verse.This is verse.This is verse.This is verse.This is verse.This is verse.This is verse.This is verse.This is verse.This is verse.This is verse.This is verse.This is verse.
\end{verse}
%------------------------------------%
\end{document}
This is quote. This is quote.This is quote.This is quote.This is
quote.This is quote.This is quote.This is quote.
This is quotation ( with indented paragraph ). This is quo-
tation ( with indented paragraph ).This is quotation ( with in-
dented paragraph ). This is quotation ( with indented paragraph
)
This is verse.This is verse.This is verse.This is verse.This is verse.This
is verse.This is verse.This is verse.This is verse.This is verse.This
is verse.This is verse.This is verse.
6. 그림 & 표
(1) 기본 소개
(용어) Floating Bodies = 그림 & 표
그림 : \begin{figure}[place specifier]
표 : \begin{table}[place specifier]
- place specifier :
h
: heret
: topb
: bottomp
: on a special page!
: do it forcefully!
(2) 그림
반드시 아래의 패키지를 불러와야!
\usepackage{graphicx}
\includegraphics[key=value, …]{file-name}
[key=value, …]
- width=0.48\textwidth ( 전체 페이지 width의 0.48배 만큼의 크기 )
{file-name}
- ex) png, eps, png, jpeg 형식의 파일
\caption[short]{long}
\label{fig:label}
\begin{figure}[t] % top, here, bottom ....
%----------------------------------------------------%
\centering
\includegraphics[width=0.48\textwidth]{fig1.png}
\caption{your figure captionhere}
\label{fig1}
%----------------------------------------------------%
\end{figure}
......
% \label{fig1} 의 활용
Figure-\ref{fig1} displays a figure of ...
(3) 표
\begin{tabular}[pos]{table spec}
[pos]
: t, b, c-
[table spec]
l r c p{width}- l이 4개 : “왼쪽”정렬 칼럼 “4개”
-
: 칼럼 사이를 구분할 지 여부
자주 사용 기호 :
&
,\\
,\hline,
\cline{i-j}
@{…}
: 셀 내부 여백 없애주기 위해
예시 1)
\begin{table}[b]
\begin{tabular}{|r|l|}
\hline
1 & A \\
2 & B \\ \cline{2-2}
3 & C \\
\hline
\hline
\hline
\hline
1984 & decimal \\
\hline
\hline
\end{tabular}
\caption{This is a table}
\end{table}
- 칼럼 2개
- (1번 칼럼) Right 정렬
- (2번 칼럼) Left 정렬
\hline
통해 수평선\cline{2-2}
통해 2번째 열의 시작 ~2번째 열의 끝- cline = hline의 “부분” 버전
예시 2)
\begin{tabular}{|p{4.7cm}|}
\hline
Welcome \\
\hline
\end{tabular}
예시 3)
\begin{tabular}{c r @{.} l} % 3개의 칼럼
Pi expression & \multicolumn{2}{c}{Value} \\ % 2개를 하나로 묶은 뒤 (c) 중앙정렬
\hline
\hline
$\pi$ & 3 & 1416 \\ % 3 & 1416 두 개의 칼럼으로 "."으로 묶음
$\pi^{\pi}$ & 36 & 46 \\
$(\pi^{\pi})^{\pi}$ & 80662 & 7 \\
\end{tabular}
예시 4)
\begin{tabular}{|c|r|l|}
\hline
\multicolumn{3}{|c|}{ABC}\\
\hline
A & B & C \\
\hline
\end{tabular}
예시 5)
\begin{tabular}{|c|r|l|}
\hline
\multicolumn{2}{|c|}{ab} & c \\
\hline
A & B & C \\
\hline
\end{tabular}
7. 수식
-
(1) Inline :
$
~$
………. 글 & 글씨 함께 -
(2) Online :
\begin{equation}
……… 글 & 글씨 따로 -
(3) Multiline :
\begin{eqnarray}
,\begin{align}
…….. 글 & 글씨 따로 + 여러 줄(
*
를 붙으면, equation number (뒤에 붙는 숫자) 가 없음 )(
\nonumber
~ , 특정 줄에만 ~ 없음 )
기타
- 분수 :
\frac{}{}
- 띄어쓰기 :
\
,\:
,\u
,\quad
,\qquad
,\!
\lim
,\int
,\sum
\hbar
,\infty
,\to
,\in
,\neq
(1) Inline& Online (equation)
\documentclass{article}
\usepackage{amsmath}
\begin{document}
%---------------------------------------------%
\begin{equation}
E = mc^2 \label{clever}
\end{equation}
%---------------------------------------------%
He didn't say
\begin{equation}
1 + 1 = 3 \tag{dumb}
\end{equation}
%---------------------------------------------%
This is a reference to \eqref{clever}.
%---------------------------------------------%
\end{document}
예시 ) \begin{equation*}
vs \begin{equation}
: 뒤에 숫자 붙냐/안붙냐
\documentclass{article}
\usepackage{amsmath}
\begin{document}
%---------------------------------------------%
\begin{equation*}
\int_1^2 \ln x \mathrm{d}x
\qquad
\int_1^2 \ln x, \mathrm{d}x
\end{equation*}
\begin{equation}
\int_1^2 \ln x \mathrm{d}x
\qquad
\int_1^2 \ln x, \mathrm{d}x
\end{equation}
%---------------------------------------------%
\end{document}
주의
<
,>
대신,\langle
,\rangle
<<
,>>
대신,gg
,ll
[]
,()
대신,\left(
&\right)
,\left[
&\right]
(2) (Multi-line) Equation
eqnarray
\begin{eqnarray}
a & = & b + c \\
& = & d + e + f + g \nonumber \\
&& + \: h + i \\
& = & j + k + l
\end{eqnarray}
\begin{eqnarray}
a & = & a = a
\end{eqnarray}
Array
\documentclass{article}
\usepackage{amsmath}
\begin{document}
%---------------------------------------------%
\begin{equation*}
\mathbf{X} = \left(
\begin{array}{ccc}
x_1 & x_2 & \ldots \\
x_3 & x_4 & \ldots \\
\vdots & \vdots & \ddots
\end{array}
\right)
\end{equation*}
%---------------------------------------------%
\end{document}
\(\begin{equation*} \mathbf{X} = \left( \begin{array}{ccc} x_1 & x_2 & \ldots \\ x_3 & x_4 & \ldots \\ \vdots & \vdots & \ddots \end{array} \right) \end{equation*}\).
\documentclass{article}
\usepackage{amsmath}
\begin{document}
%---------------------------------------------%
\begin{equation*}
\begin{bmatrix}
p_{11} & p_{12} & \ldots & p_{1n} \\
p_{21} & p_{22} & \ldots & p_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
p_{m1} & p_{m2} & \ldots & p_{mn}
\end{bmatrix}
\end{equation*}
%---------------------------------------------%
\end{document}
\(\begin{equation*} \begin{bmatrix} p_{11} & p_{12} & \ldots & p_{1n} \\ p_{21} & p_{22} & \ldots & p_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ p_{m1} & p_{m2} & \ldots & p_{mn} \end{bmatrix} \end{equation*}\).
(8) 조건식
\begin{equation*}
|x| = \left\{
\begin{array}{rl}
-x & \text{if } x < 0,\\
0 & \text{if } x = 0,\\
x & \text{if } x > 0.
\end{array}
\right.
\end{equation*}
\begin{equation*}
|x| = \begin{cases}
-x & \text{if } x < 0,\\
0 & \text{if } x = 0,\\
x & \text{if } x > 0.
\end{cases}
\end{equation*}