LaTeX/列表結構
方便且可預測的列表格式是使用 LaTeX 的眾多優勢之一。WYSIWYG 文字處理器的使用者有時會因為軟體試圖確定他們何時打算開始和結束列表而感到沮喪。作為一種標記語言,LaTeX 允許使用者更好地控制列表的結構和內容。
列表通常出現在文件中,尤其是學術文件,因為它們的目的是以清晰簡潔的方式呈現資訊。LaTeX 中的列表結構只是環境,本質上分為三種類型
- itemize 用於專案符號列表
- enumerate 用於編號列表,以及
- description 用於描述性列表。
所有列表都遵循基本格式
\begin{list_type}
\item {The first item}
\item The second item
\item The third etc \ldots
\end{list_type}
|
這三種列表型別都可以每個專案包含多個段落:只需以正常方式鍵入額外的段落,每個段落之間留一個空行。只要它們仍然包含在封閉環境中,它們就會自動縮排以跟隨其專案的下方。為了便於閱讀長專案,可以將專案內容放在花括號中。
嘗試以下示例,看看列表在實際文件中的樣子。
LaTeX 允許您將列表環境插入現有列表中(最多四層,使用包可以獲得更多層)。只需在當前列表中的所需位置開始相應的環境。Latex 會為您處理佈局和任何編號。
\begin{enumerate}
\item The first item
\begin{enumerate}
\item Nested item 1
\item Nested item 2
\end{enumerate}
\item The second item
\item The third etc \ldots
\end{enumerate}
|
有時您會感覺需要更好地對齊不同的列表專案。如果您使用的是 KOMA-script 類(或包 scrextend),labeling 環境非常方便。它接受一個強制引數,其中包含最長的標籤。
\documentclass[twocolumn]{article}
\usepackage{blindtext}
\usepackage{scrextend}
\addtokomafont{labelinglabel}{\sffamily}
\begin{document}
\blindtext
\begin{labeling}{alligator}
\item [ant] really busy all the time
\item [chimp] likes bananas
\item [alligator] very dangerous animal, sharp teeth, long
muscular tail and a bit of text that is longer than one
line and shows the alignment of text quite nicely
\end{labeling}
\end{document}
|
如果您空間有限,而且只有簡短的專案描述,您可能希望將列表內聯。請注意,示例還展示瞭如何更改字型。
\documentclass[twocolumn]{article}
\usepackage{blindtext}
\usepackage[inline]{enumitem}
\usepackage{xcolor}
\begin{document}
\blindtext Coco likes fruit. Her favorites are:
\begin{enumerate*}[label={\alph*)},font={\color{red!50!black}\bfseries}]
\item bananas
\item apples
\item oranges and
\item lemons.
\end{enumerate*}
\blindtext
\end{document}
|
如果您想要水平列表,包 tasks 非常方便。結合像 exsheets 這樣的包,您可以為學生準備考試卷。
\documentclass[12pt]{article}
\usepackage{tasks}
\usepackage{exsheets}
\SetupExSheets[question]{type=exam}
\begin{document}
\begin{question}
Which one of the entries does not fit with the others?
\begin{tasks}(4)
\task mercury
\task iron
\task lead
\task zinc
\end{tasks}
\end{question}
\settasks{
label=(\roman*),
label-width=4ex
}
\begin{question}
What is a funkyton?
\begin{tasks}(2)
\task A dancing electron
\task A dancing proton
\task A dancing neutron
\task A Dixie Dancing Duck
\end{tasks}
\end{question}
\end{document}
|
當處理每個專案只包含幾個單詞的列表時,標準列表通常會佔用太多空間。包 enumitem 為您提供了一個簡單的介面來自定義列表的外觀。
您可以在序言中全域性更改列表的外觀,或者只使用環境的可選引數為單個列表更改外觀。看看下面的示例,其中右側的列表使用 noitemsep 更加緊湊。
\documentclass[twocolumn]{article}
\usepackage{blindtext}
\usepackage{enumitem}
\begin{document}
\blindtext
\begin{itemize}
\item more work
\item more responsibility
\item more satisfaction
\end{itemize}
\blindtext
\newpage
\blindtext
\begin{itemize}[noitemsep]
\item more work
\item more responsibility
\item more satisfaction
\end{itemize}
\blindtext
\end{document}
|
對齊和標籤寬度的示例。
\documentclass[twocolumn]{article}
\usepackage{blindtext}
\usepackage{enumitem}
\begin{document}
\blindtext Coco likes fruit. Her favourites are:
\begin{description}[align=left]
\item [Kate] some detail
\item [Christina]some detail
\item [Laura]some detail
\end{description}
\begin{description}[align=right]
\item [Kate] some detail
\item [Christina]some detail
\item [Laura]some detail
\end{description}
\begin{description}[align=right,labelwidth=3cm]
\item [Kate] some detail
\item [Christina]some detail
\item [Laura]some detail
\end{description}
\blindtext
\end{document}
|
包 enumitem 的文件詳細介紹了可以更改的內容和方法。您甚至可以定義自己的列表。像 labeling 和 tasks 這樣的環境可以以不同的方式進行更改,具體細節可以在相應的包文件中找到。
easylist 包允許您使用更方便的語法和無限巢狀層級來建立列表。它也非常可定製。
使用控制字元作為可選引數載入包
\usepackage[ampersand]{easylist}
|
easylist 環境預設使用編號。
\begin{easylist}
& Main item~:
&& Sub item.
&& Another sub item.
\end{easylist}
|
它具有預定義的樣式,您可以將其設定為可選引數。
\begin{easylist}[itemize]
% ...
\end{easylist}
|
可用樣式
- tractatus
- checklist - 所有專案旁邊都有空的複選框
- booktoc - 大致是 book 類目錄使用的格式
- articletoc - 大致是 article 類目錄使用的格式
- enumerate - 預設值
- itemize
您可以使用 \ListProperties(...) 命令自定義列表,並使用 \NewList 恢復自定義。是的,\ListProperties 引數使用的是括號。
Style 引數設定計數器和文字的樣式,Style* 引數設定計數器的樣式,Style** 引數設定文字的樣式。引數 Numbers 決定數字的顯示方式,可能的取值為 r 或 R (對於小寫和大寫羅馬數字)、l 或 L (對於小寫和大寫字母)、a (對於阿拉伯數字,預設值)和 z (對於 Zapf 的 Dingbats)。
FinalMark 引數設定最後一個計數器的標點符號(例如:FinalMark3={)}),而 FinalSpace 設定專案和專案文字之間的空格量。引數 Margin 設定距離左側邊距的距離(例如:FinalSpace2=1cm)。引數 Progressive 設定所有專案的左側邊距距離,與它們所在的層級成比例。
Hide = n 引數阻止前 n 個計數器出現在所有層級中。如果引數後面有一個數字(例如:Style3*),則這個數字表示它將影響的層級(例如:Style3=\color{red})。
自定義 enumerate 的示例
\begin{easylist}[enumerate]
\ListProperties(Style2*=,Numbers=a,Numbers1=R,FinalMark={)})
& Main item~:
&& Sub item.
&& Another sub item.
\end{easylist}
|
請注意,我們將 FinalMark 引數放在 {} 之間,以避免 LaTeX 將其理解為屬性列表的結尾。現在我們更改預設屬性以列印自定義專案符號列表
\usepackage{amssymb}
\ListProperties(Hide=100, Hang=true, Progressive=3ex, Style*=-- ,
Style2*=$\bullet$ ,Style3*=$\circ$ ,Style4*=\tiny$\blacksquare$ )
% ...
\begin{easylist}
& Blah
& Blah
&& Blah
&&& Blah
&&&& Blah
&&&&& Blah
\end{easylist}
|
– Blah |
在 Style 引數中的空格很重要。 Style* 引數充當預設值,easylist 將為第 1 級、第 5 級及以後的級別使用中劃線。
您還可以使用 LaTeX 宏定義自定義樣式
\newcommand\myitemize{\ListProperties(Hide=100, Hang=true, Progressive=3ex, Style*=$\star$ )}
\newcommand\myenumerate{\ListProperties(Space=2\baselineskip)}
% ...
\begin{easylist} \myitemize
& Blah
\end{easylist}
|
重要說明:easylist 有一些缺點。 首先,如果您需要將 easylist 放置在使用與為 easylist 指定的相同控制字元的環境中,您可能會遇到錯誤。 為了避免這種情況,請使用 easylist 提供的以下命令
\Activate
\begin{easylist}
& ...
\end{easylist}
\Deactivate
|
除了使用 easylist 以及圖形可能會給佈局和縮排帶來一些麻煩。 LaTeX 列表沒有此問題。
要將 easylist 與 Beamer 一起使用,使用 easylist 的每個幀都必須標記為易碎的
\begin{frame}[fragile]
...
\begin{easylist}[itemize]
...
\end{easylist}
...
\end{frame}
|


