A. はじめに
この章では、LaTeXを使う上で最低限知っておくべき、ベーシックな知識をまとめました。
B. 雛形の解説
4. コンパイルをしてみよう!
で紹介した雛形について説明します。
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{Sample Project}
\author{Masumi Morishige}
\date{April 2021}
\begin{document}
\maketitle
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{document}
上記の雛形における各コマンドの意味は以下の通りです。
コード | 概要 |
---|---|
\documentclass{article} |
文書クラス |
\usepackage[utf8]{inputenc} |
UTF-8の設定 |
\title{Sample Project} |
タイトルの設定 |
\author{Masumi Morishige} |
著者の設定 |
\date{April 2021} |
日付の設定 |
\begin{document} ~ \end{document} |
本文の開始タグ、終了タグ |
\maketitle |
タイトルの挿入 |
\section{Introduction} |
セクションの挿入 |
B-1. 文書クラス / documentclass
文書の種類
文書クラスとしては、大きく分けて「論文 / 本 / 報告書」
の3つから選ぶことができます。また、「欧文 / 和文 / 和文(縦書き)」
なども選ぶことができます。
文書クラス | 欧文 | 和文 | 和文(縦書き) |
---|---|---|---|
論文 | article |
jsarticle |
tarticle |
本 | book |
jsbook |
tbook |
報告書 | report |
jreport |
treport |
欧文における文書クラスの違いは以下の通りです。
文書のサイズ
2. 環境構築【macOS】にて、説明していたようにA4サイズへのデフォルト設定を行うこともできますが、documentclass
にて以下のように指定することもできます。
documentclass{article} % デフォルト設定
documentclass[a4paper]{article} % オプション設定でA4を指定
B-2. パッケージの読み込み / usepackage
今回、読み込んだinputeencパッケージに限らず、パッケージの読み込みに用います。
inputencパッケージは、UTF-8の設定を行うためのパッケージなのですが、最近は読み込まなくてもUTF-8になるという話もあります。
B-3. タイトルの設定 / title
ここでタイトルの設定が行われ、maketite
で表示されます。
B-4. 著者の設定 / author
ここで著者の設定が行われ、maketite
で表示されます。
B-5. 日付の設定 / date
ここで日付の設定が行われ、maketite
で表示されます。
B-6. 本文の開始タグ・終了タグ / begin ~ end
本文の開始と終了を明示するためのコードです。
HTMLでいう<body> ~ </body>
タグにあたります。
B-7. タイトルの挿入 / maketitle
maketitle
コードをdocumentの中に入れることで、タイトルを生成できます。
B-8. セクションの挿入 / section
節(セクション)の見出しを生成するコードです。
C. 見出しまとめ
見出しはドキュメンテーションにおいて、非常に重要な要素なため、この項目でまとめたいと思います。
C-1. 見出しの種類
コード | 概要 |
---|---|
\part{title} |
Part(部)の見出し |
\chapter{title} |
Chapter(章)の見出し(bookとreportのみ有効) |
\section{title} |
Section(節)の見出し |
\subsection{title} |
Subsection(小節)の見出し |
\subsubsection{title} |
Subsubsection(小々節)の見出し |
\paragraph{title} |
Paragraph(段落)の見出し |
\subparagraph{title} |
Subparagraph(小段落)の見出し |
以下のコードの場合は、次のように表示されます。
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{Sample Project}
\author{Masumi Morishige}
\date{April 2021}
\begin{document}
\maketitle
\part{Part}
\section{Section}
Section(節)の見出し
\subsection{Subsection}
Subsection(小節)の見出し
\subsubsection{Subsubsection}
Subsubsection(小々節)の見出し
\paragraph{Paragraph}
Paragraph(段落)の見出し。
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\subparagraph{Subparagraph}
Subparagraph(小段落)の見出し。
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{document}
C-2. 見出しのカウンター
深さレベルの指定
見出しの番号をどの深さの見出しまでつけるかを指定するために、以下のようにして「深さレベル」を設定できます。
\setcounter{secnumdepth}{5}
C-1. 見出しの種類
で作成したsample_article.tex
に対して、上記のコードで深さレベルを3,4,5のパターンでそれぞれ指定したところ、以下のようになります。
以下の結果から、\setcounter{secnumdepth}{5}
を指定すると、paragraph
とsubparagraph
に番号をつけたい時に有効なことがわかります。
カウンターの書式設定
カウンターは、1.1.1
以外にもIII
のようにローマ数字などで表示することもできます。
\renewcommand{\thesection}{\Roman{section}}
上記のローマ数字以外にも以下のような表記を指定できます。
コード | 概要 |
---|---|
\arabic{section} |
アラビア数字(1,2,3...) |
\roman{section} |
ローマ数字(i,ii,iii...) |
\Roman{section} |
ローマ数字(I,II,III...) |
\alph{section} |
アルファベット(a,b,c...) |
\Alph{section} |
アルファベット(A,B,C...) |
D. タイポグラフィーまとめ
D-1. 強調の設定
基本的な強調の書式設定は以下の通りです。
コード | 概要 | 表示 |
---|---|---|
\textrm{text} |
ローマン体(標準) | |
\textbf{text} |
ボールド体(太字) | |
\textit{text} |
イタリック体 |
D-2. フォントサイズの設定
基本的なフォントサイズの書式設定は以下の通りです。
コード | 概要 | 表示 |
---|---|---|
{\tiny text} |
極小(5pt) | |
{\small text} |
小(9pt) | |
{\normalsize text} |
中(10pt) | |
{\large text} |
大(12pt) | |
{\huge text} |
極大(20.74pt) | |
上記のサイズ以外にも、scriptsize / footnotesize / Large / LARGE / Huge サイズなどがあります。 |
また、カスタムのフォントサイズにしたい場合は、fontsize
コードが有効です。
\fontsize{10pt}{0pt}\selectfont
text
\fontsize{20pt}{0pt}\selectfont
text
\fontsize{20pt}{20pt}\selectfont
text
D-3. 色文字の設定
基本的な色文字の書式設定は以下の通りです。
コード | 概要 | 表示 |
---|---|---|
\textcolor{red}{text} |
赤文字(レッド) | |
\textcolor{green}{text} |
緑文字(グリーン) | |
\textcolor{blue}{text} |
青文字(ブルー) |
また、もしも特定の箇所だけではなく、全体に対して色をつけたいときは、以下のようにcolor
パッケージを使う方法があります。
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{Sample Project}
\author{Masumi Morishige}
\date{April 2021}
\usepackage{color} % 1. この行を追加
\begin{document}
\maketitle
\color{red} % 2. この行を追加
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\color{blue} % 3. この行を追加
\section{Methods}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{document}
D-4. LaTeX / LaTeX文字
TeXとLaTeXの特殊文字は、以下のようにして表示できます。
\TeX
\LaTeX
E. フォーマットまとめ
E-1. 余白のフォーマット
文内(In-text)での余白・空白・改行・改ページなどのフォーマットの基本的な編集方法は以下の通りです。
コード | 概要 | 表示 |
---|---|---|
\, |
空白(微小) | |
~ |
空白(1文字分) | |
\hspace{20pt} |
横方向の空白 | |
\par |
段落(インデントあり) | (下記参照) |
\newline or \\
|
改行 | |
\newline* or \\*
|
改行(改ページ禁止) | --- |
\vspace{20pt} |
縦方向の空白 | (下記参照) |
\newpage |
改ページ | --- |
Lorem\,\,\,ipsum~~~dolor\hspace{20pt}sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\par
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. \newline
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. \vspace{20pt} \\
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
E-2. アラインメントのフォーマット
右寄せ / 左寄せ / 中央寄せなどのAlignmentの設定方法は以下の通りです。
\section{Introduction}
標準の文章。
\begin{flushright}
右寄せの文章。
\end{flushright}
\begin{center}
中央寄せの文章。
\end{center}
\begin{flushleft}
左寄せの文章。
\end{flushleft}
F. 挿入系オブジェクトまとめ
F-1. 目次 / Table of Contents
目次の挿入方法は以下の通りです。
コード | 概要 |
---|---|
tableofcontents |
目次 |
listoftables |
表目次 |
listoffigures |
図目次 |
F-2. 引用 / Quotation
引用の挿入方法は以下の通りです。
コード | 概要 |
---|---|
\begin{quote}~\end{quote} |
引用(段落なし) |
\begin{quotation}~\end{quotation} |
引用(段落あり) |
\begin{quote}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \par
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{quote}
\begin{quotation}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \par
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{quotation}
F-3. ページ番号 / Page Number
ページ番号の挿入方法は以下の通りです。
コード | 概要 |
---|---|
\pagestyle{empty} |
ページ番号なし |
\pagestyle{plain} |
フッターにページ番号を挿入 |
\pagestyle{headings} |
ヘッダーにページ番号を挿入 |
\thispagestyle{empty} |
ページ番号なし(そのページのみ) |
\thispagestyle{plain} |
フッターにページ番号を挿入(そのページのみ) |
\thispagestyle{headings} |
ヘッダーにページ番号を挿入(そのページのみ) |
ドキュメント全体のページ番号設定は、pagestyle
をプリアンブルに記述し、一部のページだけを変更したい場合はそのページにthispagestyle
を記述します。1ページ目は、プリアンブルのスタイルが反映されないことがあるため、その時は、thispagestyle
を1ページ目に記述しましょう。
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{Sample Project}
\author{Masumi Morishige}
\date{April 2021}
\pagestyle{headings} % 1. この行を挿入
\begin{document}
\maketitle
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \par
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\thispagestyle{headings} % 2. この行を挿入
\end{document}
また、ページ番号のフォーマットを変更することもできます。
コード | 概要 |
---|---|
\pagenumbering{arabic} |
アラビア数字(1,2,3) |
\pagenumbering{roman} |
小文字のローマ数字(i,ii,iii) |
\pagenumbering{Roman} |
大文字のローマ数字(I,II,III) |
\pagenumbering{alph} |
小文字のアルファベット数字(a,b,c) |
\pagenumbering{Alph} |
大文字のアルファベット数字(A,B,C) |
\documentclass{article}
\usepackage[utf8]{inputenc}
\title{Sample Project}
\author{Masumi Morishige}
\date{April 2021}
\pagenumbering{roman} % この行を挿入
\begin{document}
\maketitle
\section{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \par
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{document}
F-4. 箇条書き / List
箇条書き(リスト)の挿入方法は以下の通りです。
HTMLでいうところの<ol>
/ <ul>
/ <li>
などにあたるものがそれぞれあります。
コード | 概要 | HTML対応 |
---|---|---|
\begin{itemize}~\end{itemize} |
箇条書きのラッパー(番号なし) | <ul> |
\begin{enumerate}~\end{enumerate} |
箇条書きのラッパー(番号あり) | <ol> |
\begin{description}~\end{description} |
箇条書きのラッパー(見出し付き) | <dl> |
\item text |
箇条書きのアイテム | <ol> |
\begin{itemize}
\item text 1
\item text 2
\item text 3
\end{itemize}
\begin{enumerate}
\item text 1
\item text 2
\item text 3
\end{enumerate}
\begin{description}
\item[heading 1] text 1
\item[heading 2] text 2
\item[heading 3] text 3
\end{description}
F-5. 図 / Figure
図の挿入方法は以下の通りです。
コード | 概要 |
---|---|
\usepackage[dvipdfmx]{graphicx} |
usepackageを用いて、dvipdfmxからgraphicxパッケージを読み込み(推奨) |
\usepackage[dvipdfm]{graphicx} |
usepackageを用いて、dvipdfmからgraphicxパッケージの読み込み(非推奨) |
\begin{figure}{option}~\end{figure} |
figureの出力ラッパー |
\centering |
中央揃え |
\raggedleft |
右揃え(左側に空白ができる) |
\raggedright |
左揃え(右側に空白ができる) |
\includegraphics[option]{PATH} |
figureの挿入 |
\Caption{text} |
キャプションの挿入 |
以下に、実際の例を示します。
figure.tex
と同じ階層に、sample.png
というファイルを置いていることを前提としています。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[dvipdfmx]{graphicx}
\title{Sample Project}
\author{Masumi Morishige}
\date{April 2021}
\begin{document}
\maketitle
\section{Introduction}
The profile picture is shown in fig.\ref{fig:profile}.
\begin{figure}[htbp]
\centering
\includegraphics[clip,width=7.0cm]{./sample.png}
\caption{Profile}
\label{fig:profile}
\end{figure}
\end{document}
上記のコードに出てきたオプションについての解説は以下の通りです。
まず\begin{figure}
のオプションでは、位置指定を行うことができるのですが、htbp
と複数文字入力すると、hを優先して表示するが、それが難しかったらtで表示するという風な優先順位を指定できます。
コード | 概要 |
---|---|
h |
記述されている場所にそのまま表示 |
t |
ページ上端に表示 |
b |
ページ下端に表示 |
p |
表専用のページに表示 |
次に、\includegraphics
のオプションでは、figureの大きさなどを指定できます。
コード | 概要 |
---|---|
width |
横幅 |
height |
高さ |
scale |
拡大縮小率 |
angle |
回転角 |
clip |
はみ出し部分の切り取り |
F-6. 表 / Table
表の挿入方法は以下の通りです。
コード | 概要 |
---|---|
\begin{table}[option]~\end{table} |
表のラッパー |
\begin{tabular}[option]~\end{tabular} |
表形式の設定 |
\hline |
横方向の線(horizontal line) |
\& |
行内の区切り |
また、\begin{tabular}{|l|c|r|}
と記述することで、1列目は左寄せ(left)
、2列目は中央寄せ(center)
、3列目は右寄せ(right)
に表形式を指定しています。
\section{Introduction}
\begin{table}[htbp]
\begin{center}
\caption{Sample}
\begin{tabular}{|l|c|r|} \hline
Col.1 & Col.2 & Col.3 \\ \hline \hline
Row.1-1 & Row.1-3 & Row.1-3 \\
Row.2-1 & Row.2-3 & Row.2-3 \\ \hline
Row.3-1 & Row.3-3 & Row.3-3 \\
Row.4-1 & Row.4-3 & Row.4-3 \\ \hline
\end{tabular}
\end{center}
\end{table}
F-7. 注釈 / Thanks
以下のようにmeta情報に付随する形で\thanks
を入れ込むと注釈をつけることができます。
\title{Sample Project \thanks{Title Annotation}}
\author{Masumi Morishige \thanks{Author Annotation}}
\date{April 2021 \thanks{Date Annotation}}
G. 数式まとめ
G-1. 数式の埋め込み方
数式の埋め込み方は何通りか手法があります。
コード | 概要 |
---|---|
$text$ |
インライン数式 |
\begin{math}~\end{math} |
インライン数式 |
\begin{equation}~\end{equation} |
番号付き数式(1行) |
\usepackage{amsmath} |
amsmathパッケージの読み込み(alignを用いるために必要) |
\begin{align}~\end{align} |
番号付き数式(複数行)(推奨) |
\begin{align*}~\end{align*} |
番号なし数式(複数行)(推奨) |
\begin{eqnarray}~\end{eqnarray} |
番号付き数式(複数行)(非推奨) |
\begin{eqnarray*}~\end{eqnarray*} |
番号なし数式(複数行)(非推奨) |
\setcounter{equation}{0} |
番号付き数式のカウンターをリセット |
\nonumber |
番号付き数式なし(その行のみ) |
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\begin{document}
$y=ax+b$
\begin{math}
y=ax+b
\end{math}
\begin{equation}
a + b + c = 5
\end{equation}
\begin{align}
a + b + c = 5 \\
b + c = 3
\end{align}
\begin{align*}
a + b + c = 5 \\
b + c = 3
\end{align*}
\setcounter{equation}{0}
\begin{align}
a + b + c = 5 \\
b + c = 3
\end{align}
\begin{align}
a + b + c = 5 \nonumber \\
b + c = 3
\end{align}
\end{document}
G-2. 数式の記法
数式の記法は、たくさんあるため、基本的なもののみ以下にまとめました。
コード | 概要 | 表示 |
---|---|---|
x^a |
上付き文字(Superscript) | |
x_a |
下付き文字(Subscript) | |
x^a_b |
上+下付き文字 | |
x^{a+b} |
複雑な上付き文字 | |
\overline{a+b} |
上線 | |
\underline{a+b} |
下線 | |
\hat{a} |
ハット | |
\bar{a} |
バー | |
A \cap B |
キャップ | |
A \cup B |
カップ | |
a \pm b |
プラスマイナス | |
a \times b |
掛け算 | |
a \div b |
割り算 | |
a \le b |
小なりイコール | |
a \ge b |
大なりイコール | |
\x=frac{a}{b} |
分数 | |
\sin x |
サイン | |
\cos x |
コサイン | |
\tan x |
タンジェント | |
\sqrt{x^2+y^2} |
平方根 / square root | |
\sqrt[n]{x^2+y^2} |
n乗根 / root of n-th power | |
\log x |
対数(底なし) | |
\log_2 x |
対数(底あり) | |
\ln{x} |
自然対数 | |
\sum_{i=0}^n x_i |
総和、シグマ / Summation | |
\prod_{i=0}^n x_i |
総乗、パイ / Product | |
\lim_{x \to \infty} f(x) |
極限、リミット / Limit | |
\int_a^b f(x)dx |
積分 / Integral | |
\overrightarrow{A} |
ベクトル / Vector | |
{}_n C _r |
組み合わせ / Combination | |
{}_n P _r |
順列 / Permutation |
推奨コマンドについて
発刊にあたり、Twitterにて以下のような貴重なご意見をいただき、本編の改訂を行いました。ご親切なアドバイスに大変感謝致します。その際に活用したリンクも共有しておきます。
参考文献
宣伝:もしもよかったらご覧ください^^
『AIとコミュニケーションする技術(インプレス出版)』という書籍を出版しました🎉
これからの未来において「変わらない知識」を見極めて、生成AIの業界において、読まれ続ける「バイブル」となる本をまとめ上げました。
かなり自信のある一冊なため、もしもよろしければ、ご一読いただけますと幸いです^^