LaTeX Wiki
Advertisement

The list environment can be used to insert custom lists akin to enumerate, itemize, and description.

Syntax[]

\begin{list}{labeling}{spacing}
  \item[optional label] This is the first item
  \item[optional label] This is the second item
  ...
\end{list}

Most often, however, the list environment is used in macros. For example, many standard LaTeX environments that do not immediately appear to be lists are in fact constructed using list, including quotation, quote, and center.

Defining new environments[]

This defines a new environment called mylist with Roman numerals for labbeling.

\newcounter{mycounter}               % number the items
\newenvironment{mylist}
  {\begin{list}
    { \Roman{mycounter}. }           % labeling
    { \usecounter{mycounter}         % set counter
      \setlength{\leftmargin}{3.5em} % set spacing
    }
  }
  {\end{list}}

mylist can be then be used as follows:

\begin{mylist}
  \item step 1
  \item step 2
  \item[Awesome label] Amazing description
\end{mylist}

The mandatory first argument labeling specifies the default labeling of list items. It can contain text and LaTeX commands. LaTeX forms the label by putting the labeling argument in a box of width \labelwidth. If the label is wider than that, the additional material extends to the right. When making an instance of a list you can override the default labeling by giving \item an optional argument in square brackets, e.g. \item[Awesome label].

The mandatory second argument spacing is a list of commands. This list can be empty. A command that can go in here is \usecounter{countername}. The counter will be reset to zero each time LaTeX enters the environment, and the counter is incremented by one each time LaTeX encounters an \item that does not have an optional argument.

Another command that can go in spacing is \makelabel, which constructs the label box. By default it puts the contents flush-right. Its only argument is the label, which it typesets in LR mode.

Using \makelabel we can change the definition of mylist to format all labels (not just the automatic numbering) in italics:

\newcounter{mycounter}  % number the items
\newcommand{\mymakelabel}[1]{\textit{#1}}
\newenvironment{mylist}
  {\begin{list}
    { \Roman{mycounter}. }           % labeling
    { \usecounter{mycounter}         % set counter
      \setlength{\leftmargin}{3.5em} % set spacing
      \let\makelabel\mymakelabel     % format label
    }
  }
  {\end{list}}

Similarly, with \let\makelabel\fbox the labels are put inside a framed box.

As the name implies, the spacing argument can also contain commands to redefine the spacing for the list. See here for a list of available lengths you can change.

This article includes content from the unofficial LaTeX2e reference manual, which is licensed under the old-style GNU documentation license.

Advertisement