Lists: Enumerate, itemize, description and how to change them

October 16, 2008 by thurnherr

Latex distinguishes between three different enumeration/itemization environments. Each of them provide four levels, which means you can have nested lists of up to four levels.

Enumerate:

\begin{enumerate}
\item ...
\end{enumerate}

The enumerate-environment is used to create numbered lists.
If you like to change the appearance of the enumerator, the simplest way to change is to use the enumerate-package, giving you the possibility to optionally choose an enumerator.


\usepackage{enumerate}
...
\begin{enumerate}[I]%for capital roman numbers.
\item
\end{enumerate}

\begin{enumerate}[(a)]%for small alpha-characters within brackets.
\item
\end{enumerate}

Itemize:

\begin{itemize}
\item ...
\end{itemize}

Itemization is probably the mostly used list in Latex. It also provides four levels. The bullets can be changed for each level using the following command:

\renewcommand{\labelitemi}{$\bullet$}
\renewcommand{\labelitemii}{$\cdot$}
\renewcommand{\labelitemiii}{$\diamond$}
\renewcommand{\labelitemiv}{$\ast$}

Amongst the more commonly used ones are $\bullet$ (\bullet), $\cdot$ (\cdot), $\diamond$ (\diamond), $-$ (-), $\ast$ (\ast) and $\circ$ (\circ).

Description:

\begin{description}
\item[] ...
\end{description}

The description list might be the least known. It comes in very handy if you need to explain notations or terms. Its neither numbered nor bulleted.

Example:

\begin{description}
\item[Biology] Study of life.
\item[Physics] Science of matter and its motion.
\item[Psychology] Scientific study of mental processes and behaviour.
\end{description}

And in a PDF it would look like this:

Example of a description list.

Example of a description list.

Note:

The space between different items can be controlled with the \itemsep command (can only be added just after “begin”):

\begin{itemize}\itemsep2pt
\item
\end{itemize}

Tip: Showing page 4 of 65

October 15, 2008 by thurnherr

Showing the total number of pages in addition to the actual page number is straight forward using the “lastpage” package.

\usepackage{lastpage}

Now you can simply access the number of pages using:

\pageref{LastPage}

Note: You will have to typeset the DVI/PDF twice in order to get the number right.

Example:

\usepackage{fancyhdr, lastpage}
\pagestyle{fancy}
\fancyfoot[C]{{\thepage} of \pageref{LastPage}}
\begin{document}
...

Note: See this recent comment on how to count the number of figures within your document.

“umlaut” in Latex using inputenc

October 2, 2008 by thurnherr

Some Latex editors (like WinEdt) internally convert your umlauts to Lamport’s umlaut format, e.g. ä \to \"a
Now, if your editor is not doing it automatically (like Vim :-) ), you basically have two possibilities

  1. Use Lamport’s umlaut format: \"{}
  2. Use a package that can handle umlauts and all characters having a code > 127

The inputenc package:

The inputenc package recognizes all characters that have an ascii code > 127 and hence is able to parse umlauts:

\usepackage[option]{inputenc}

The following options are available and have to be used depending on your operating system:

  • latin1/latin9: Most Unix system and VMS.
  • applemac/macce: Older Mac systems/current mac systems
  • ansinew: Used on Windows, similar to latin1.
  • cp437de: MSDOS.
  • cp850: OS/2 and with MSDOS, if the codepage IBM-850 is explicitely used.
  • utf8: Can be used on most systems (e.g. all newer Linux distributions).

Difference between latin1 and latin9:

The ISO latin9 character set replaces a few less commonly used characters with characters that gained importance recently. If you need the euro sign € or Caron (háček), which replace e.g. the broken vertical bar (¦) or encoded fractions.

Source: http://www.cs.tut.fi/~jkorpela/latin9.html

Displaying text inside the math-environment

October 1, 2008 by thurnherr

By default, Latex will print text within formulas in italics, omitting white spaces. Now if you need to add normal text into a formula or even write a formula using words, you can do this with the text-command inside the math-environment:

\text{...}

Example:

\text{velocity} = \frac{\text{distance}} {\text{unit of time}}

velocity=\frac{distance}{unit of time} \to \text{velocity} = \frac{\text{distance}}{\text{unit of time}}

Btw. The “text-command” will also take care of the spaces, which would otherwise be ignored.

Note:
Spaces in the math-environment can be produced using:

  • \; for a thick space,
  • \: for a medium space,
  • \, for a thin space and
  • \! for a negative thin space.
Intertext

Using the math-environment align to display a series of equations, whole lines of text can be added in between using the “intertext”-command without affecting the alignment of the equations:

\begin{align}
...
\intertext{...}
...
\end{align}

Example:

\begin{align}
F = f_1+f_2+f_3+...+f_n
\intertext{can be written as}
\sum_1^n{f_i}
\end{align}

Margin notes in Latex

September 26, 2008 by thurnherr

Adding margin notes to a document is more convenient and better noticable than comments between the lines. Latex provides a very easy way to add margin notes without changing the margins of your document.

You can add anything you like, e.g. a formula in the math environment, etc. And you don’t even need to use a package. Adding margin notes is a standard command in Latex, you just have to know it :-) . There you go:

\marginpar{Add formula for curvature}

Latex for Chemists, Chefs, Managers and Paparazzi

September 17, 2008 by thurnherr

This post is not to be taken too seriously, but to show that Latex is not only used by mathematicians and engineers, but actually has a very broad field of application with its thousands of packages available.

Latex for Chemists:

Helping chemists type their chemical symbols. chemsym

Latex for Chefs:

Helping chefs type their recipies. cuisine

Latex for Psychologists:

Helping psychologists to follow their bibliography guidelines. apacite

Latex for Managers:

Helping managers to remember their meetings, appointments and deadlines. schedule

Latex for Paparazzi:

Helping paparazzi to arrange their photos. photo

Latex for Unemployed:

Helping unemployed to spend their time. cwpuzzle

Latex for Tex-ters:

List of available packages. CTAN package directory.

Save the planet using Latex, print 2in1!

September 16, 2008 by thurnherr

I just found this very cool package which lets you easily print two pages in one. I have only tested it for articles and reports and it works perfectly for articles. Using the document-class report, the content is perfectly structured, but not the table of contents, which still takes the entire page. The package also messes up with the page numbers whenever you start a new chapter. So it basically only works with sections, but not chapters.

First tell Latex to turn the page to landscape:

\documentclass[a4paper, landscape]{article}

Next include the necessary packages:

\usepackage{2in1, lscape}

The latter is needed, as you not only want the paper layout, but also the content to be in “landscape-mode”.

Now add your document content and have fun printing (and saving the planet ;-) )!

The standard distributions have this package included, but just in case you can get it from here.

Create small TOCs/LOFs/LOTs using \minitoc

September 15, 2008 by thurnherr

In large documents, it is helpful to add a “mini-table-of-contents” at the beginning of every chapter in order to get a better overview of the chapter. The minitoc-package provides a nice, easy-to-use and customizable layout for TOCs on a chapter level.

How to crate a minitoc:

\usepackage{minitoc}

Any minitoc can only be created if you have a “global” table-of-contents, its content is used for generation. So in your document, you first have to notify Latex you want to use minitoc and then create the overall table of contents:

\dominitoc
\tableofcontents

Now you can add minitocs at the beginning of your chapters:

\chapter{...}
\minitoc
\section{...}

Minilofs and minilots:

Similarly, \minilof and minilot will create list-of-figures and list-of-tables for your chapters.

Remarks:

Obviously, this only makes sense in books and reports, as in articles there are no chapters available. Here the minitoc-package provides additional commands for articles:

\secttoc
\sectlof
\sectlot

and to partition books:

\parttoc
\partlof
\partlot

The complete reference and package can be found at CTAN

Define your own “list of …”

July 13, 2008 by thurnherr

I got this very interesting question lately, how to define a custom list of examples, similar to the list of figures. But as this is not only applicable to examples, but to all sorts of things (e.g. questions, theorems, proofs, lemmas, answers, etc.) and hence might be useful for other people, I decided publish a new post on that issue.

As usual, you will need to import a package.


\usepackage{tocloft}

The package lets you customise your table of contents, list of figures or list of tables (which is basically what the name stands for).

In addition, the package also lets you define your custom lists easily and hence is exactly what we were looking for.

In order to keep this as general as possible, I will use “X” instead of “example”, “proof”, etc. At the end, I will post a complete example, showing how to create a “list of examples”, which you can simply copy-paste and adapt for your needs.

After having added the package, we want to define the name that appears as a title of our list:
 
\newcommand{\listXname}{List of Xs}

Next we use the command provided by tocloft to define a new list of whatever:

\newlistof{X}{ex}{\listXname}

Now we define the actual X-command (similar to figure or table), which has a counter that is increased by one every time an X is used:

\newcommand{\X}[1]{%
\refstepcounter{X}
\par\noindent\textbf{X \theexample. #1}
\addcontentsline{exp}{example}
{\protect\numberline{\thechapter.\theexample}#1}\par}

By using the X-command (\X{Your text}), Latex will print the following:

X 1 Your text

The last line will add all your typed Xs to the list of Xs.

That’s it for the definition. The command “\listofX” will create a list of all your defined Xs similar to the ToC, LoF and LoT.

\begin{document}
\tableofcontents
\newpage
\listofX
\newpage
...
\end{document}

You can also add references to the different Xs, by adding a label just after the X-command (see example below):

Example: List of Examples

\documentclass{report}
\usepackage{tocloft}
\usepackage[english]{babel}
\newcommand{\listexamplename}{List of Examples}
\newlistof{example}{exp}{\listexamplename}
\newcommand{\example}[1]{%
\refstepcounter{example}
\par\noindent\textbf{Example \theexample. #1}
\addcontentsline{exp}{example}
{\protect\numberline{\thechapter.\theexample}#1}\par}
\begin{document}
\tableofcontents
\newpage
\listofexample
\chapter{Two examples}
\example{Your first example}
\label{1st_ex}
\example{Your second example}
\label{2nd_ex}
\chapter{One example}
\example{Your third example. (See example \ref{1st_ex} \& \ref{2nd_ex})}
\end{document}

If you want to reset your example counter for new chapters, you would need to add the following lines before the beginning of your document:

\makeatletter
\@addtoreset{example}{chapter}
\makeatother

 

Click here for the complete tocloft documentation as well as the package.

Cont: Equal cell width (right and centre aligned content)

May 7, 2008 by thurnherr

One of my last posts was on how to define the width of a column in a table (see here).

The parbox (p), which is used by Latex when you define the column width, will by default align its content on the left. This can be changed, but is a bit tricky.

The keyword is:

\raggedleft, \centering or \raggedright

Raggedleft will align text on the right-hand side, leaving whatever white space remains (ragged) on the left.
For a better understanding, let’s define right alignment of the text as a new column type, which can than be used in the very same way as pre-defined column types.
Defining a new column type needs the following package:

\usepackage{array}

\newcolumntype{x}[1]{%
>{\raggedleft\hspace{0pt}}p{#1}}%

The argument is the width of the column.

Now simply use “x{2cm}” instead of “p{2cm}”, for columns which align text on the right. By changing \raggedleft to \centering, you can align text in the centre.

Example:

\begin{table}\centering
\begin{tabular}{|l|x{4.5cm}|x{4.5cm}|}\hline
Nb. & Advantage & Disadvantage\tabularnewline\hline
1 & a & b \tabularnewline\hline
2 & b & a \tabularnewline\hline
\end{tabular}
\end{table}

Note:
An important last thing to mention, you cannot end lines with “\\”, as you defined your own column type. Therefore, I am using \tabularnewline in the example. If you want to save time, you might define your own command as follows:

\newcommand{\tn}{\tabularnewline}

Or even:

\newcommand{\tnhl}{\tabularnewline\hline}