三つの環境、一つのカーネルマクロ、一つの規則
itemize、enumerate、description ——素の LaTeX が持つ列挙の語彙はこの三つです。三つともカーネルマクロ \list を薄く包んだものなので、字下げも空きもエラー文も共有しています。itemize が記号を、enumerate がカウンタを、description は各 \item の省略可能引数に打ったラベルを供給します。
規則は一つ、リストの中身は項目の連なりでなければならない、です。すべての項目は \item で始まり、最初の要素が \item でない環境——からっぽのリストも含む——は LaTeX でもっとも分かりにくいエラーを出します、! LaTeX Error: Something's wrong--perhaps a missing \item.。記述は正確でも原因は正確でないことが多く、迷い込んだ空行、コメント化された \item、\begin{document} の直後に中身なしで始まったリスト、どれも同じ報告になります。
どれを選ぶかは、あとでそのリストについて何を言いたいかの質問です。順序に参照すべき意味が無くただの集まりなら itemize。項目を参照しなければならないなら enumerate——カウンタが載っているので \label{itm:power} と \ref{itm:power} が印字済みの番号として解決します。用語と説明の組なら description、ラベルは生成物ではなく内容そのものです。
初心者がリストで解決しがちですが、避けるべき四つ目のケースがあります。短い定義を二列に並べる、解答用紙を組む、ページ幅いっぱいに検査項目を広げる——あれらは表か tasks パッケージの仕事で、入れ子にした記号の並べ書きではありません。この課の最後の節でまた戻ります。
\begin{array}{l|l}\text{environment} & \text{what it contributes} \\\hline \texttt{itemize} & \text{a symbol, no counter} \\ \texttt{enumerate} & \text{a counter you can \textbackslash ref} \\ \texttt{description} & \text{a label you type per item}\end{array}
enumerate だけなので、相互参照の意味をなす項目も enumerate のものに限られます。ラベル梯階:四段とその下のカウンタ
標準クラスは一つのリストにつき四段までの入れ子を許し、段ごとに既定のラベルが決まっています。article の記号は一段目が埋めた丸、二段目が太い en ダッシュ、三段目が中央寄せのアスタリスク、四段目が中央寄せのピリオド。report と book は一段目が em ダッシュなので、同じソースが学位論文のクラスでは別の見た目になります。数字の梯階は 1.、(a)、iii.、A. です。
あのラベルは文字列の直書きではなくマクロの対です。カウンタは enumi、enumii、enumiii、enumiv。\theenumi はカウンタの読み方(\arabic{enumi})を決め、\labelenumi は項目の前での印字のされ方(\theenumi.)を決めます。itemize 側の対応物が \labelitemi から \labelitemiv までで、裏にカウンタはありません。
この分離は、項目に \label を付けた瞬間に効いてきます。\ref が印字するのは \p@enumii\theenumii、つまり親の接頭辞(標準クラスでは空)と現在の値の組だからです。\labelenumi だけを書き換えるとラベルは新しくなりますが参照は旧いまま。\theenumi を書き換えると両方変わります。副項目への参照を「c」ではなく「2.3」にしたいなら望む動作がこれで、マクロを二つに分けてあるのは使われるためです、\renewcommand{\theenumii}{\theenumi.\arabic{enumii}} のあとに \renewcommand{\labelenumii}{(\theenumii)} と書きます。
深さは吸収されず検査されます。どちらの環境でも五段目を入れるとビルドが ! Too deeply nested. で止まります。1 以外の値から始めるには正しい段のカウンタをセットします。\begin{enumerate}\setcounter{enumi}{4} なら最初の項目が 5 で始まり、\begin{enumerate} 単体でも enumi は 0 へ戻る——リセットとセットは同じ仕組みの両面です。
\begin{array}{c|c|c|c}\text{depth} & \text{counter} & \text{\textbackslash the…} & \text{printed label} \\\hline 1 & \texttt{enumi} & \texttt{\textbackslash arabic\{enumi\}} & \texttt{1.} \\ 2 & \texttt{enumii} & \texttt{\textbackslash alph\{enumii\}} & \texttt{(a)} \\ 3 & \texttt{enumiii} & \texttt{\textbackslash roman\{enumiii\}} & \texttt{iii.} \\ 4 & \texttt{enumiv} & \texttt{\textbackslash Alph\{enumiv\}} & \texttt{A.}\end{array}
enumitem:全体の作り替えをやめてリスト単位の指定へ
\usepackage{enumitem} が標準的なアップグレードで、手順そのものを変えます。\begin{enumerate}[label=(\alph*),leftmargin=*] はそのリストだけを設定し、* が現在のカウンタ値の置き印です。たいてい望んでいるのはこちらのほうで、\renewcommand{\labelenumi} は文書中のすべてのリストを変え、次に触る人の目にも見えなくなります。shortlabels オプションを付けて読むと、簡潔な \begin{enumerate}[(a)] 形も使えるようになります。
よく使う鍵は下の表に出しています。label と ref は \labelenumi と \theenumi の代わり、label* は親のラベルに継ぎ足す形で、親の部分を書かずに 1.1、1.2 を得られます。start と resume/series はカウンタの制御、noitemsep と nosep は既成の詰め指定、wide は標準の緩い空きへ戻し、align=left と align=parbox はラベルが割り当ての \labelwidth を超えたときの振る舞いを決めます。
文書全体の既定は作り替えではなく「セット」します。\setlist[enumerate,1]{label=\arabic*.} は一段目のすべての列挙、\setlist[itemize]{topsep=4pt} はどんな段の列挙も、そして \setlist{noitemsep} だけなら文書中の全リストを意味します。これらは導言部で宣言として働くので、リストの空きを変える正直な通路でもあります。標準クラスはリスト開始時に自身の topsep、parsep から itemsep、\@listi、\@listii を再割り当てするため、導言部に置いた \setlength{\topsep}{…} は静かに捨てられます。
発明する前に知っておきたい切換子が二つ。\usepackage[inline]{enumitem} は itemize*、enumerate*、description* を追加します。段落の内部を走るリストで、「(a) 速度、(b) 費用、(c) 重量をテストした」をアルファベットの手書きなしに組める正しい道具です。もう一つ、\newlist{checklist}{itemize}{2} は既存環境の上に別の深さと別の形を持つ新しい名前を宣言するので、組織固有の書式を本文に書き込まずに済みます。
\begin{array}{ll}\texttt{label} & \text{what prints before each item} \\ \texttt{ref} & \text{what \textbackslash ref\ shows for that item} \\ \texttt{start} & \text{first value of the counter} \\ \texttt{series} & \text{a named list you can resume later} \\ \texttt{leftmargin=*} & \text{flush with the text block} \\ \texttt{noitemsep} & \text{itemsep and parsep to zero}\end{array}
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb} % for \square
\usepackage[inline,shortlabels]{enumitem}
\setlist[enumerate,1]{label=\textbf{\arabic*.},leftmargin=*}
\setlist[enumerate,2]{label=\textbf{\theenumi.\arabic*}}
\setlist[itemize]{topsep=4pt,itemsep=2pt,parsep=0pt}
\setlist[description]{style=nextline}
\newlist{checklist}{itemize}{2}
\setlist[checklist,1]{label=$\square$,leftmargin=*}
\newlist{questions}{enumerate}{2}
\setlist[questions,1]{label=Q\arabic*,ref=Q\arabic*}
\setlist[questions,2]{label=(\alph*),ref=\arabic{questionsi}(\alph*)}
\begin{document}
\section*{Per-instance options}
\begin{enumerate}[label=\textbf{\arabic*.},start=3]
\item Third in the sequence, because \texttt{start=3}.
\item \begin{enumerate}[label*=\arabic*] % label* appends to the parent
\item prints 3.1, where \texttt{label=\arabic*} on its own would
have restarted at 1.
\end{enumerate}
\end{enumerate}
\begin{checklist}
\item Power budget signed off
\item Rack space measured
\end{checklist}
\begin{questions}
\item Which port is upstream? \label{q:one}
\begin{questions}
\item Justify with the diagram. \label{q:onea}
\end{questions}
\item See question~\ref{q:one} and part~\ref{q:onea}.
\end{questions}
\section*{Inline lists}
Three candidates were screened \begin{enumerate*}[label=(\roman*)]
\item by price \item by lead time \item by warranty
\end{enumerate*}, and only the last two survived.
\section*{Broken across a page}
\begin{enumerate}[series=steps]
\item Unpack
\item Mount
\end{enumerate}
Text on the next page continues the same numbering:
\begin{enumerate}[resume*=steps]
\item Commission
\end{enumerate}
\end{document}
description:ラベルはカウンタではなく内容
description 環境は \list{}{\labelwidth\z@ \itemindent-\leftmargin \let\makelabel\descriptionlabel} と定義されています。そのまま読むと帰結が二つ。\labelwidth がゼロ、つまりラベルは固定幅の箱に納められず、組まれたあと本文がその後ろへ続く形なので、長い用語はその項目の本文だけを右へ押します。\itemindent は \leftmargin の符号を反転したもので、ラベルを余白の外側まで引き戻しているのはこの値です。
カーネルの \descriptionlabel は \hspace\labelsep\normalfont\bfseries #1。列挙のラベルが太字で出てくる理由がこの一行で、斜体・スモールキャップ・大文字に変えたければ書き換えるのもここです。enumitem なら同じ仕事は鍵一つ、\setlist[description]{font=\normalfont\itshape}、あるいは既成の style=nextline で、用語の下に説明を置く後者のほうが記号表を読みやすくできます。
ラベルには段落中で動くものなら何でも書けます。数式も可、\item[$\alpha$-decay] …。相性が悪いのは脚注と \verb で、省略可能引数が状況次第で動く引数になるためです。そのまま打った風な見出し語が必要なら \texttt{} が安全な側です。
\item[]、つまり空の省略可能引数は間違いではなく已成語です。ラベルを持たない項目を作るので、列挙の字下げだけ保って太い用語を落とす定型になり、見出し風のラベルの下に続く段落に便利です。
リストの形を決めるレジスタ
水平方向でリストは長さの組です。\leftmargin(段ごとの \leftmargini から \leftmarginiv)が塊全体を本文幅の内側へ動かし、\labelwidth がラベルを入れる箱の幅、\labelsep がラベルと本文の間の空き、\itemindent が各項目の第一行をそこから動かし、\listparindent は項目内の第二段落以降の字下げです。\rightmargin は右側を削ります。enumitem はこれらを同名で全部さらしています。
縦方向の距離は四つで、この取り違えが空きに関する訴えの最頻品です。\topsep はリスト全体の上下のグルー、\partopsep は \begin の前に空行があるとき——リストが段落の先頭から始まるとき——だけ足される追加分、\itemsep は項目の間、\parsep は一つの項目内の段落の間に入ります。article の一段目はおおむね \topsep が 8pt、\itemsep と \parsep が各 4pt で、すべて伸びと縮みを持ち、深い段ほどゼロへ寄ります。四段目のリストが締まって見える理由です。
これらの数値はリスト開始の瞬間に \@listi たちが代入するので、enumitem(\setlist[enumerate]{topsep=6pt})がきれいな通路、クラスマクロの修正が汚れ仕事です。例外は \parskip で、これは本当に全体及び標準です。ゼロでない \parskip を置いた文書では、クラスや parskip パッケージが列挙側を再調整しない限り、項目間の空きまで引き継いで二重に膨らみます。
項目はそれ自体が段落の場所なので、項目の内側の空行は誤りではなく第二段落です。\parsep がかかり、\listparindent で下がります。ただし親の \item と入れ子の \begin{itemize} の間の空行は空の段落を作り、誰も頼んでいない空きが出ます。入れ子のリストはそれを所有する項目と同じ論理行に置いてください。
\begin{array}{c}\texttt{partopsep}\quad\text{list starts a new paragraph} \\ \hline \texttt{topsep}\quad\text{above and below the whole list} \\ \hline \texttt{itemsep}\quad\text{between two items} \\ \hline \texttt{parsep}\quad\text{between two paragraphs inside one item}\end{array}
リストが不適な道具であるとき
四十語の用語集を description で組むと二箇所で壊れます。上の節で見た通り長い用語が本文と衝突し、塊を列として流し読みできないためです。代わりは、記号表なら二列の longtable か tabularx、短い項目なら二・三段組。tasks パッケージはまさにそのためにあり、\begin{tasks}(3) に \task を一各行で並べると、番号付き・記号付きのリストを三段にまたがって組み、番号は読み順を保ちます。演習プリントに必要な形です。
形が列ではなく図——申請書、住所ブロック、署名欄——なら、正しい環境は tabular、quote、あるいは \\ ブロック内の明示的な center で、一語だけの項目の連なりではありません。リストは余白と縦のグルーを連れてくるので、どちらも欲しくなければ欲しかったのは段落です。
検査表で itemize に打ち込んだ [ ] を偽の箱にしないでください。角括弧は状況次第で省略可能引数として読まれ、書式も揃いません。\newlist{checklist}{itemize}{1} に \setlist[checklist,1]{label=$\square$,leftmargin=*}、amssymb を併用して宣言すれば、箱は正しい大きさと重さを持つ文字になります。
最後に、「リスト」が実のところ他テキストから番号で参照される手順なら、道具は enumerate に ref/label で、番号こそが内容物です。読んだときに番号付きに見えるだけの列なら label=\textbf{\arabic*.} を付けた記号列表でも動きますが、enumerate のほうが正直です。
一行ずつ読む実例
以下のリストは標準クラス版の観光案内です。itemize のラベルを一つ、enumerate のマクロを二つ書き換えて、副項目への参照が「1.2」、目に見えるラベルが「(1.2)」になるようにしています。enumi のあとで \begin{enumerate} をセットして 3 から始まり、五段目まで入れ子にしつつ失敗する部分はコメント化、短い用語集には description を使っています。
見落としやすいが写す価値のある細部が二つ。まず \item Cooling, as item~\ref{itm:psu} requires のチルダで、「item」と番号が一つに組まれているので行分割で語と参照が離れません。もう一つはコメントにした五段目とその下に載せたエラー文です。このファイルは通るので、コメントを外せばログを読む 90 秒演習になります。
第三節の checklist 版と比べてください。同じ文書の形を、リスト単位の指定、名前を付けた questions、二段の ref リスト——その questionsi は \newlist が作ってくれた親カウンタ enumerate* まで届きます——文中に置く series、そして間に本文を挟んで番号を続ける resume*/\renewcommand の組で書いています。標準クラス版が導言部に四つの enumitem を要するところで、後者は決定一つなら導言部を要しません。三度目の修正のあ後に効いてくるのはこの差です。
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
% ---- labels and counters of the standard classes -------------------
% level 1: 1. level 2: (a) level 3: iii. level 4: A.
% itemize: bullet, endash, centred asterisk, centred period
\renewcommand{\labelenumi}{\theenumi)} % 1) instead of 1.
\renewcommand{\theenumii}{\theenumi.\arabic{enumii}} % refs read "1.2"
\renewcommand{\labelenumii}{(\theenumii)} % labels read "(1.2)"
\renewcommand{\labelitemii}{$\circ$} % a math ring as a bullet
\begin{document}
\section{Requirements}
\begin{enumerate}\setcounter{enumi}{2} % this list starts at 3)
\item Power supply \label{itm:psu}
\item Network
\begin{itemize}
\item Wired
\item Wireless
\begin{itemize}
\item 2.4\,GHz only, no WPA3 support in the older access points
\begin{itemize}
\item a fourth level is the last one the standard classes allow
% \begin{itemize}
% \item a fifth level stops the run with the message
% ! Too deeply nested.
% \end{itemize}
\end{itemize}
\end{itemize}
\end{itemize}
\item Cooling, as item~\ref{itm:psu} requires
\end{enumerate}
\section{Definitions}
\begin{description}
\item[Baseline] the invisible line the letters sit on; descenders go below it.
\item[Leading] the distance from one baseline to the next, stored in
\verb|\baselineskip|.
\item[Overfull] a line TeX could not fit; it sticks into the margin instead
of hyphenating.
\end{description}
An empty list is an error, not an empty space on the page:
% \begin{itemize}
% \end{itemize}
% ! LaTeX Error: Something's wrong--perhaps a missing \item.
\end{document}
このレッスンの早見表
各セクションのキーコードを一行ずつ。見出しで該当箇所へ移動、コードはそのままコピーできます。
\begin{array}{l|l}\text{environment} & \text{what it contributes} \\\hline \texttt{itemize} & \text{a symbol, no counter} \\ \texttt{enumerate} & \text{a counter you can \textbackslash ref} \\ \texttt{description} & \text{a label you type per item}\end{array}
\begin{array}{c|c|c|c}\text{depth} & \text{counter} & \text{\textbackslash the…} & \text{printed label} \\\hline 1 & \texttt{enumi} & \texttt{\textbackslash arabic\{enumi\}} & \texttt{1.} \\ 2 & \texttt{enumii} & \texttt{\textbackslash alph\{enumii\}} & \texttt{(a)} \\ 3 & \texttt{enumiii} & \texttt{\textbackslash roman\{enumiii\}} & \texttt{iii.} \\ 4 & \texttt{enumiv} & \texttt{\textbackslash Alph\{enumiv\}} & \texttt{A.}\end{array}
\documentclass[10pt]{article}
\begin{array}{c}\texttt{partopsep}\quad\text{list starts a new paragraph} \\ \hline \texttt{topsep}\quad\text{above and below the whole list} \\ \hline \texttt{itemsep}\quad\text{between two items} \\ \hline \texttt{parsep}\quad\text{between two paragraphs inside one item}\end{array}
\documentclass[11pt]{article}
よくある間違い
\begin{enumerate}[a)]を読んでいない文書でenumitemと書くこと。標準の環境は省略可能引数を取らないので、角括弧つきの文本来はリストより前の通常テキストとして組まれ、ラベルは 1.、2.、3. のままです。- 唯一の
\itemを消す、またはリストを空にして、Something's wrong--perhaps a missing \itemをクラスの欠陥として読むこと。環境は本当に項目の本文を要求しています。 \itemと、それが所有する入れ子の\begin{itemize}の間に空行を入れること。入れ子リストが新しい段落を始めてしまい、親の項目の前に\parsepの空行が現れます。\renewcommand{\labelenumi}{\arabic{enumi})}としてから、\refが旧い様式の理由を尋ねること。ラベルは\labelenumi、参照は\theenumiです。- 五段目を組んでクラスを疑うこと。構成を減らすか、
\setlistdepth{9}と\renewlist{itemize}{itemize}{9}で天井を上げ、\labelitemvを定義してください。 - 導言部の
\setlength{\topsep}{0pt}でリストを詰めようとすること。クラスはリスト開始時に\topsepから\@listiを再代入します。\setlist{topsep=0pt}かnoitemsepを使ってください。 - 項目を
\\ではなく\itemで区切ること。リスト全体が一つの項目に入り、ラベルがすべて消えます。
この課に関する質問
enumerate の数字をアルファベットに変えるには?
\begin{enumerate}[label=\alph*)] なら a) b) c)、label=\textbf{\arabic*.} なら太い数字。パッケージ無しなら導言部でクラスのマクロを書き換えますが、\renewcommand{\labelenumi}{\alph{enumi})} は一段目の全リストを変え、\ref までも新しい形にしたければ \theenumi も書き換える必要があります。5 から始まる番号付きリストは?
\begin{enumerate} の直後に \setcounter{enumi}{4} と書けば最初の項目が 5 で始まります。カウンタはラベルを組む前に進められるためです。enumitem なら同じことが鍵一つで [start=5]。以前のリストの番号を続けたければ両方に series= で名前を付け、二つ目を resume*= で開きます。Something is wrong, perhaps a missing \item とは何か?
\end より前にも \item が無かったという意味です。空のリスト、項目がすべてコメント化されたリスト、別のコマンドの引数の中へ迷い込んだ \item で出ます。環境を消すか項目を足すのが対処で、エラーがページの他の場所を指すことは一切ありません。項目と項目の空きを無くすには?
\setlist{noitemsep} で全部に適用します。nosep はリストの上下の空きも消します。これらの鍵は \itemsep と \parsep をゼロに設定しますが、まさにその二つのレジスタが隙間を作っていました。入れ子は何段まで許されますか?
\setlistdepth で天井を上げ、新しい段の見た目も宣言できますが、記号の四段入れ子はすでに読者が追える限界を越えているので、まず構成の問題として扱ってください。itemize と description の違いは?
\labelitemi から \labelitemiv まで生成された記号を出し、description は各 \item の省略可能引数をそのまま出します。後者は \descriptionlabel で組まれ、カーネル既定では太字です。description はラベルに固定幅を割り当てないので、長い用語は自分の本文だけを右へ押します。直したければ enumitem の style=nextline です。ライブ playground:LaTeX を編集して即描画
入力すると即座にプレビューが更新されます。わざと壊してエラーの見た目も確認しましょう。
続けて読む
同じ話題への三つの入口:記法そのもの、それを教える課、そして実際に使っている記事。