LaTeX/List Structures

From testwiki
Jump to navigation Jump to search

Template:LaTeX/Top


Convenient and predictable list formatting is one of the many advantages of using LaTeX. Users of WYSIWYG word processors can sometimes be frustrated by the software's attempts to determine when they intend lists to begin and end. As a mark-up language, LaTeX gives more control over the structure and content of lists.

List structures

Lists often appear in documents, especially academic, as their purpose is often to present information in a clear and concise fashion. List structures in LaTeX are simply environments which essentially come in three types:

All lists follow the basic format:

Template:LaTeX/Usage

All three of these types of lists can have multiple paragraphs per item: just type the additional paragraphs in the normal way, with a blank line between each. So long as they are still contained within the enclosing environment, they will automatically be indented to follow underneath their item. Item content could be in the curly brackets for reading convenience of long items.


Try out the examples below, to see what the lists look like in a real document.

\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}
Sample output of lists in LaTeX. Itemize, enumerate, and description.

Template:BookCat


LaTeX will happily allow you to insert a list environment into an existing one (up to a depth of four, more levels are available using packages). Simply begin the appropriate environment at the desired point within the current list. Latex will sort out the layout and any numbering for you.

\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}

Template:BookCat

Some special lists

Sometimes you feel the need to better align the different list items. If you are using a KOMA-script class (or package scrextend), the labeling environment is handy. It takes a mandatory argument that contains the longest of your labels.

\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}

Template:BookCat


If you are on tight space limitations and only have short item descriptions, you may want to have the list inline. Please note that the example also shows how to change the font.

\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}

Template:BookCat



If you want a horizontal list, package tasks can be handy. In combination with a package like exsheets, you can prepare exam papers for students.

\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}

Template:BookCat

Customizing lists

When dealing with lists containing just a few words per item, the standard lists often take up too much space. Package Template:LaTeX/Package provides you a simple interface to customize the appearance of lists.

You can change the appearance of lists globally in the preamble, or just for single lists using the optional argument of the environment. Have a look at the following example where the list on the right is more compact using 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}

Template:BookCat

An example for alignment and the width of the label.

\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}

Template:BookCat

The documentation of package enumitem goes into more detail with respect to what can be changed and how. You can even define your own lists. Environments like labeling and tasks can be changed differently, details can be found in the package documentation respectively.

Easylist package

The Template:LaTeX/Package package allows you to create list using a more convenient syntax and with infinite nested levels. It is also very customizable.

Load the package with the control character as optional argument: Template:LaTeX/Usage

The Template:LaTeX/Environment environment will default to enumerations. Template:LaTeX/Usage

It features predefined styles which you can set as optional argument. Template:LaTeX/Usage

Available styles:

You can customize lists with the Template:LaTeX/LaTeX command and revert back the customization with Template:LaTeX/LaTeX. Yes, that's parentheses for Template:LaTeX/LaTeX parameters.

The Template:LaTeX/Parameter parameter sets the style of counters and text, the Template:LaTeX/Parameter parameter sets the style of counters, and the Template:LaTeX/Parameter parameter sets the style of text. The parameter Template:LaTeX/Parameter determines the way that the numbers are displayed and the possible values are Template:LaTeX/Parameter or Template:LaTeX/Parameter (for lower and upper case Roman numerals), Template:LaTeX/Parameter or Template:LaTeX/Parameter (for lower and upper case letters), Template:LaTeX/Parameter (for Arabic numbers, the default), and Template:LaTeX/Parameter (for Zapf's Dingbats).

The Template:LaTeX/Parameter parameter sets the punctuation of the final counter (Ex: Template:LaTeX/LaTeX) while Template:LaTeX/Parameter sets the amount of space between the item and the item's text. The Template:LaTeX/Parameter parameter sets the distance from the left margin (Ex: Template:LaTeX/LaTeX). The Template:LaTeX/Parameter parameter sets the distance from the left margin of all items in proportion to their level.

The Template:LaTeX/Parameter parameter prevents the first Template:LaTeX/Parameter counters from appearing in all levels. If there is a number after a parameter (Ex: Template:LaTeX/Parameter) then this numbers indicates the level that it will affect (Ex: Template:LaTeX/LaTeX).

Example of custom enumerate: Template:LaTeX/Usage

Note that we put the Template:LaTeX/Parameter argument between Template:LaTeX/LaTeX to avoid LaTeX understanding it as the end of the properties list. Now we change the default properties to print a custom itemize:

\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
    Blah
     – Blah

Template:BookCat

Spaces in Template:LaTeX/Parameter parameters are important. The Template:LaTeX/Parameter parameter acts as a default value and Template:LaTeX/Environment will use a medium dash for level 1, 5 and onward.

You can also define custom styles using LaTeX macros: Template:LaTeX/Usage

Important note: Template:LaTeX/Package has some drawbacks. First if you need to put an easylist inside an environment using the same control character as the one specified for easylist, you may get an error. To circumvent it, use the following commands provided by easylist:

Template:LaTeX/Usage

Besides using Template:LaTeX/Environment along with figures may cause some trouble to the layout and the indentation. LaTeX lists do not have this problem.

To use easylist with Beamer, each frame that uses easylist must be marked as fragile:

Template:LaTeX/Usage



Template:LaTeX/Bottom


sr:LaTeX/Структура листи ko:LaTeX/목록