跳轉到內容

LaTeX/列表結構

來自華夏公益教科書

LaTeX

入門
  1. 介紹
  2. 安裝
  3. 安裝額外包
  4. 基礎
  5. 如何獲得幫助

常用元素

  1. 文件結構
  2. 文字格式
  3. 段落格式
  4. 顏色
  5. 字型
  6. 列表結構
  7. 特殊字元
  8. 國際化
  9. 旋轉
  10. 表格
  11. 標題建立
  12. 頁面佈局
  13. 自定義頁首和頁尾‎
  14. 匯入圖形
  15. 浮動體、圖形和標題
  16. 腳註和頁邊注
  17. 超連結
  18. 標籤和交叉引用
  19. 首字母縮略詞

機制

  1. 錯誤和警告
  2. 長度
  3. 計數器
  4. 方框
  5. 規則和撐條

技術文字

  1. 數學
  2. 高階數學
  3. 定理
  4. 化學圖形
  5. 演算法
  6. 原始碼列表
  7. 語言學

特殊頁面

  1. 索引
  2. 詞彙表
  3. 參考文獻管理
  4. 更多參考文獻

特殊文件

  1. 科學報告(學士報告、碩士論文、博士論文)
  2. 信件
  3. 簡報
  4. 教師專欄
  5. 簡歷
  6. 學術期刊(MLA、APA 等)

建立圖形

  1. 介紹過程式圖形
  2. MetaPost
  3. 圖片
  4. PGF/TikZ
  5. PSTricks
  6. Xy-pic
  7. 建立 3D 圖形

程式設計

  1. Plain TeX
  2. 建立包
  3. 建立包文件
  4. 主題

其他

  1. 模組化文件
  2. 協作編寫 LaTeX 文件
  3. 匯出到其他格式

幫助和建議

  1. 常見問題解答
  2. 技巧和竅門

附錄

  1. 作者
  2. 連結
  3. 包參考
  4. LaTeX 文件示例
  5. 索引
  6. 命令詞彙表

編輯此框編輯目錄


方便且可預測的列表格式是使用 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}

這三種列表型別都可以每個專案包含多個段落:只需以正常方式鍵入額外的段落,每個段落之間留一個空行。只要它們仍然包含在封閉環境中,它們就會自動縮排以跟隨其專案的下方。為了便於閱讀長專案,可以將專案內容放在花括號中。


嘗試以下示例,看看列表在實際文件中的樣子。

\documentclass{article}
\usepackage{blindtext}
\begin{document}

\begin{itemize}
  \item \blindtext
  \item \blindtext
\end{itemize}

\begin{enumerate}
  \item \blindtext
  \item \blindtext
\end{enumerate}

\begin{description}
  \item [Ant] \blindtext
  \item [Elephant] \blindtext
\end{description}

\end{document}
LaTeX 列表的示例輸出。專案符號、編號和描述。


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 的文件詳細介紹了可以更改的內容和方法。您甚至可以定義自己的列表。像 labelingtasks 這樣的環境可以以不同的方式進行更改,具體細節可以在相應的包文件中找到。

Easylist 包

[編輯 | 編輯原始碼]

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 決定數字的顯示方式,可能的取值為 rR (對於小寫和大寫羅馬數字)、lL (對於小寫和大寫字母)、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
  Blah
   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}



先前:字型 索引 下一個:特殊字元
華夏公益教科書