Two complete examples
15.6.3 Two complete examples
In the previous examples, I set the values of \leftmargin and \rightmargin. The other length commands were not redefined, so their values remained the values set by the document class. In the following examples, I set the values of many more length commands.
Example 1 To get the following list,
Here are the most important L A TEX rules about spaces in text, sentences, and paragraphs:
Rule 1: Two or more consecutive spaces in text are the same as one.
Rule 2:
A blank line—that is, two end-of-line char- acters separated only by blanks and tabs— indicates the end of a paragraph.
Rules 1 and 2 make typing and copying very convenient. we type
\noindent Here are the most important \LaTeX\ rules about spaces in text, sentences, and paragraphs: \newcounter{spacerule} \begin{list}{\upshape\bfseries Rule \arabic{spacerule}:}
412 Chapter 15 Customizing L A TEX
{\setlength{\leftmargin}{1.5in} \setlength{\rightmargin}{0.6in} \setlength{\labelwidth}{1.0in} \setlength{\labelsep}{0.2in} \setlength{\parsep}{0.5ex plus 0.2ex
minus 0.1ex}
\setlength{\itemsep}{0ex plus 0.2ex
minus 0ex} \usecounter{spacerule} \itshape}
\item Two or more consecutive spaces in text are the same as one.\label{Li:Twoor} \item A blank line---that is, two end-of-line
characters separated only by blanks and
tabs---indicates
the end of a paragraph.\label{Li:blankline} \end{list} Rules \ref{Li:Twoor} and~\ref{Li:blankline} make typing and copying very convenient.
Note that
1. I declared the counter as in the previous example.
2. The last item in declarations is \itshape, which typesets the entire list in ital- ics.
3. The default label is defined as \upshape\bfseries Rule \arabic{spacerule} My first attempt was to define it as \bfseries Rule \arabic{spacerule} which typesets Rule in bold italics (because in Step 2 we set the whole list in ital-
ics). To force the label to be typeset upright, I start the default label with the \upshape command.
4. The left margin is set to 1.5 inches and the right margin to 0.6 inches:
\setlength{\leftmargin}{1.5in} \setlength{\rightmargin}{0.6in}
5. Next I set the width of the label to 1 inch, and the space between the label and the item to 0.2 inches:
15.6 Custom lists 413
\setlength{\labelwidth}{1.0in} \setlength{\labelsep}{0.2in}
6. Finally, I set the paragraph separation to 0.5 ex, allowing stretching by 0.2 ex and shrinking by 0.1 ex, and the item separation to 0 ex, allowing stretching by 0.2 ex and no shrinking, by
\setlength{\parsep}{0.5ex plus 0.2ex minus 0.1ex} \setlength{\itemsep}{0ex plus 0.2ex minus 0ex}
The actual amount of item separation is calculated by adding the values specified for \parsep and \itemsep.
A complicated list such as this should be defined as a new environment. For example, you could define a myrules environment:
\newenvironment{myrules} {\begin{list} {\upshape \bfseries Rule \arabic{spacerule}:} {\setlength{\leftmargin}{1.5in}
\setlength{\rightmargin}{0.6in} \setlength{\labelwidth}{1.0in} \setlength{\labelsep}{0.2in} \setlength{\parsep}{0.5ex plus 0.2ex minus 0.1ex} \setlength{\itemsep}{0ex plus 0.2ex minus 0ex} \usecounter{spacerule} \itshape} }
{\end{list}} and then use it anywhere, as in \begin{myrules}
\item Two or more consecutive spaces in text are the same as one.\label{Li:Twoor} \item A blank line---that is, two end-of-line characters separated only by blanks and tabs---indicates the end of a paragraph.
\label{Li:blankline}
\end{myrules} Rules \ref{Li:Twoor} and~\ref{Li:blankline} make typing and copying very convenient.
which typesets as the first example shown on page 411.
414 Chapter 15 Customizing L A TEX Example 2 In Section 5.7.2, we discussed the formatting of the following type of
glossary: sentence is a group of words terminated by a period, exclamation point, or
question mark. paragraph is a group of sentences terminated by a blank line or by the \par
command.
Now we can create the glossary as a custom list: \begin{list}{}
{\setlength{\leftmargin}{30pt} \setlength{\rightmargin}{0pt} \setlength{\itemindent}{14pt} \setlength{\labelwidth}{40pt} \setlength{\labelsep}{5pt} \setlength{\parsep}{0.5ex plus 0.2ex minus 0.1ex} \setlength{\itemsep}{0ex plus 0.2ex minus 0ex}}
\item[\textbf{sentence}\hfill] is a group of words terminated by a period, exclamation point, or question mark. \item[\textbf{paragraph}\hfill] is a group of sentences
terminated by a blank line or by the \com{par} command. \end{list}
There is nothing new in this example except the \hfill commands in the optional arguments to left adjust the labels. With the long words in the example this adjustment is not necessary, but it would be needed for shorter words.
See Section 3.3 of The L A TEX Companion, 2nd edition [46] on how to customize the three standard list environments and also for more complicated custom lists.