• (0, 1) is an open interval

• [0, 1] is a closed interval

So, why the dollars around (0,1) also? Since (0,1) and [0,1] are mathematical entities,

the correct way to typeset them is to include them within braces in the input, even when

there is no trouble such as with \item as seen above. (By the way, do you notice any

difference between (0,1) produced by the input (0,1) and (0, 1) produced by $(0,1)$?)

In addition to all these tweaks, there is also provision in LTEX to design your own

A

˜custom™ lists. But that is another story.

TUTORIAL VII

ROWS AND COLUMNS

The various list environments allows us to format some text into visually distinct rows.

But sometimes the logical structure of the text may require these rows themselves to be

divided into vertically aligned columns. For example, consider the material below typeset

using the \description environment (doesn™t it look familiar?)

Let™s take stock of what we™ve learnt

Abiword A word processor

Emacs A text editor

TEX A typesetting program

A nicer way to typeset this is

Let™s take stock of what we™ve learnt

AbiWord A word processor

A text editor

Emacs

A typesetting program

TEX

Here the three rows of text are visually separated into two columns of left aligned text.

This was produced by the tabbing environment in LTEX.

A

KEEPING

VII.1. TABS

Basics

VII.1.1.

Let™s take stock of what we™ve learnt

\begin{tabbing}

\hspace{1cm}\= \textbf{AbiWord}\quad\= A word processor\\[5pt]

\> \textbf{Emacs} \> A text editor\\[5pt]

\> \textbf{\TeX} \> A typesetting program

\end{tabbing}

Let™s analyze it line by line. In the ¬rst line the ¬rst tab is put at a distance of 1 cm. from

the left margin so that the text following it (˜AbiWord™ in boldface roman) starts from

this point. The second tab is put at a distance of one \quad (this is an inbuilt length

speci¬cation in TEX roughly equal to one space) after the word ˜Abiword™ in boldface

roman so that the text following it (˜A word processor™ in ordinary roman face) start

from this point. The \\[5pt] command signi¬es the end of the ¬rst line and also asks

for a vertical space of 5 points between the ¬rst and the second lines. In the second line,

57

58 ROWS COLUMNS

VII. AND

the ¬rst \> command makes the text following it (˜Emacs™ in boldface roman) to start

from the ¬rst tab (already set in the ¬rst line), namely, 1 cm. from the left margin. The

second \> line makes the text following it (˜A text editor™ in ordinary roman face) at the

second tab already set, namely at a distance 1 cm plus the length of the word ˜AbiWord™

in boldface roman plus a \quad. The third line follows suit. The picture below will make

this clear.

tab 1 tab 2

“ “

AbiWord A word processor

left margin

A text editor

Emacs

A typesetting program

TEX

One should be careful in setting tabs. For example to typeset

A typesetting program

TEX

A text editor

Emacs

AbiWord A word processor

if you type

\begin{tabbing}

\textbf{\TeX}\quad\= A typesetting program\\[5pt]

\textbf{Emacs}\quad\> A text editor\\[5pt]

\textbf{AbiWord}\quad\> A word processor

\end{tabbing}

then you end up with the output

TEX A typesetting program

EmacsA text editor

AbiWordword processor

A

Do you see what happened? The ¬rst line set the ¬rst tab (the only tab in this example) at

a distance of the length of the word ˜TEX™ in boldface roman plus a ˜quad™ from the left

margin and the \> command in the second line makes the text following to atart from

this tab, which is right next to the word ˜Emacs™ in this line. the same thing happens

in the third line, which is worse, since the position of the tab is at the ˜o™ of ™AbiWord™

and the next word ˜A word processor™ starts from this point, and overwrites the previous

word. The correct way to obtain the output we want is to use a dummy line to mark the

tabs, without actually typesetting that line. This is achieved by the \kill command in

the tabbing environment, as shown below

\begin{tabbing}

\textbf{AbiWord}\quad\= A word processor\kill

\textbf{\TeX}\quad \> A typesetting program\\[5pt]

59

KEEPING

VII.1. TABS

\textbf{Emacs}\quad \> A text editor\\[5pt]

\textbf{AbiWord}\quad\> A word processor

\end{tabbing}

New tabs, in addition to the ones already set by the ¬rst line (dummy or otherwise),

can be set in any subsequent line. Thus the output

: A typesetting program

TEX

: A text editor

Emacs

a programming environment

a mail reader

and a lot more besides

AbiWord : A word processor

is obtained from the source

\begin{tabbing}

\textbf{AbiWord}\quad\= : \= A word processor\kill\\

\textbf{\TeX}\quad \> : \> A typesetting program\\[5pt]

\textbf{Emacs}\quad \> : \> A text editor\\[5pt]

\> \> \quad\= a programming environment\\[5pt]

\> \> \> a mail reader\\[5pt]

\> \> \> and a lot more besides\\[5pt]

\textbf{AbiWord}\quad\> : \> A word processor

\end{tabbing}

Here the ¬rst line sets two tabs and the fourth line sets a third tab after these two. All the

three tabs can then be used in the subsequent lines. New tab positions which change the

ones set up by the ¬rst line, can also be introduced in any line by the \= command. Thus

we can produce

Program : TEX

Author : Donald Knuth

Manuals :

Title Author Publisher

The TEXBook Donald Knuth Addison-Wesley

The Advanced TEX Book David Salomon Springer-Verlag

by the input

\begin{tabbing}

Program\quad \= : \= \TeX\\[5pt]

Author \> : \> Donald Knuth\\[5pt]

Manuals \> :\\

\quad\= The Advanced \TeX\ Book\quad\= David Salomon\quad

\= Springer-Verlag\kill\\

\>\textsf{Title} \>\textsf{Author} \>\textsf{Publisher}\\[8pt]

60 ROWS COLUMNS

VII. AND

\>The \TeX Book \>Donald Knuth \>Addison-Wesley\\[5pt]

\>The Advanced \TeX\ Book \>David Salomon \>Springer-Verlag

\end{tabbing}

Here the ¬rst line sets teo tabs and the next two lines use these tabs. The third line sets

three new tabs which replace the original tab positions. The next three lines use these

new tab positions.

Pushing and popping

VII.1.2.

What if you change the tab positions and then want the original settings back? Here™s

where the command pair \pushtabs ... \poptabs ia useful. Thus to typeset

Program : TEX

Author : Donald Knuth

Manuals :

Title Author Publisher

The TEXBook Donald Knuth Addison-Wesley

The Advanced TEX Book David Salomon Springer-Verlag

Tutorial : http://tug.org.in/tutorial

we type

\begin{tabbing}

Program\quad \= : \= \TeX\\[5pt]

Author \> : \> Donald Knuth\\[5pt]

Manuals \> :\\

\pushtabs

\quad\= The Advanced \TeX\ Book \quad \= David Salomon \quad

\= Springer-Verlag\kill\\

\>\textsf{Title} \>\textsf{Author} \>\textsf{Publisher}\\[8pt]

\>The \TeX Book \>Donald Knuth \>Addison-Wesley\\[5pt]

\>The Advanced \TeX\ Book \>David Salomon \> Springer-Verlag\\[8pt]

\poptabs

Tutorial \> : \> "http://tug.org.in/tutorial"

\end{tabbing}

Here the ¬rst three lines follow a tabbing scheme, the next three lines follow another

tabbing scheme and the last line reverts back to the original scheme. Here the \pushtabs

command stores the current tabbing scheme and removes it so that a new tabbing scheme

can be set up; and the \poptabs commands reactivates the original scheme. These com-

mands can be nested.

More commands

VII.1.3.

There are some more useful commands available in the tabbing environment. The \+

command given at the end of a line makes every subsequent line start at the ¬rst tab;

with \+\+ at the end of a line, all subsequent lines start at the second tab and so on.

The effect of each \+ can be neutralized by one \- command at the end of a line. The

61

KEEPING

VII.1. TABS

command \< at the beginning of a line neutralizes the effect of one \+ command for that

particular line.

The command \˜ (left quote) puts the text following ¬‚ush right against the right

margin. Naturally we cannot use a \= or \> after this in a line.

Another interesting command is \™ (right quote). Within the tabbing environment

an input of the form left text\™right text puts the right text at the current tab and

the left text just before this tab with a bit of spacing (preassigned by the parameter

\tabbingsep).

The example below illustrates all the tabbing commands we™ve discussed

\begin{tabbing}

Row 1 Column 1\hspace{2cm}

\= Row 1 Column 2\\[5pt]

\> Row 2 Column 2\hspace{1.5cm}\=Row 2 Column 3\+\+\\[5pt]

Row 3 Column 3\-\\[5pt]

Row 4 Column 2 \>Row 4 Column 3\\[5pt]

\< Row 5 Column 1 \> Row 5 Column 2 \>Row 5 Column 3\\[5pt]

Row 6 Column 2 \>Row 6 Column 3\-\\[5pt]

Row 7 Column 1 \> Row 7 Column 2 \>Row 7 Column 3\\[5pt]

Row 8 Column 1 \˜Right\\[5pt]

Row 9 Column 1 \> and\™Row 9 Column 2\\[5pt]

\pushtabs

\quad\= Row 10 New Column 1\hspace{2.5cm}\= Row 10 New Column 2\\[5pt]

\> Row 11 New Column 2 \> Row 11 New Column 2\\[5pt]

\poptabs

Row 12 Old Column 1\> Row 12 Old Column 2\>Row 12 Old Column 3

\end{tabbing}

It produces the following output

Row 1 Column 1 Row 1 Column 2

Row 2 Column 2 Row 2 Column 3

Row 3 Column3

Row 4 Column 2 Row 4 Column 3

Row 5 Column 1 Row 5 Column 2 Row 5 Column 3

Row 6 Column 2 Row 6 Column 3

Row 7 Column 1 Row 7 Column 2 Row 7 Column 3

Row 8 Column 1 Right

Row 9 Column 1 and Row 9 Column 2

Row 10 New Column 1 Row 10 New Column 2

Row 11 New Column 2 Row 11 New Column 2

Row 12 Old Column 1 Row 12 Old Column 2 Row 12 Old Column 3

Recall that the commands \=. \˜ and \™ are used for various accents outside the

tabbing environment. If these are needed within the tabbing environment, they can be

produced with the commands \a=. \a˜ or \a™ commands.

One ¬nal word. You might™ve noted in the examples above that we give a sort of

62 ROWS COLUMNS

VII. AND

˜formatting™ to the sources also. This is not really necessary from the point of view of

LTEX since the output of the last example is he same even if we input

A

\begin{tabbing}

Row 1 Column 1\hspace{2cm}\=Row 1 Column 2\\[5pt]

\>Row 2 Column 2\hspace{1.5cm}\=Row 2 Column 3\+\+\\[5pt]

Row 3 Column3\-\\[5pt]

Row 4 Column 2\>Row 4 Column 3\\[5pt]

\<Row 5 Column\>Row 5 Column 2\>Row 5 Column 3\\[5pt]

Row 6 Column 2\>Row 6 Column 3\-\\[5pt]

Row 7 Column 1\>Row 7 Column 2\>Row 7 Column 3\\[5pt]

Row 8 Column 1\˜\textbf{Flush right}\\[5pt]

Row 9 Column 1\>and\™Row 9 Column 2\\[5pt]

\pushtabs

Row 10 New Column 1\hspace{2.5cm}\=Row 10 New Column 2\\[5pt]

Row 11 New Column 2\>Row 11 New Column 2\\[5pt]

\poptabs

Row 12 Old Column 1\>Row 12 Old Column 2\>Row 12 Old Column 3

\end{tabbing}

LTEX can make sense out of this, but we humans cannot. And such a jumble makes

A

editing a hopeless task. The moral? Keep the source (humanly) readable.

TABLES

VII.2.

Another way to format text into columns and rows is to use the tabular environment.

Let™s see it in action by means of an example.

The table below shows the sizes of the planets of our solar system.

Planet Diameter(km)

Mercury 4878

Venus 12104

Earth 12756

Mars 6794

Jupiter 142984

Saturn 120536

Uranus 51118

Neptune 49532

Pluto 2274

As can be seen, Pluto is the smallest and Jupiter the largest

Now look at the source of this output

The table below shows the sizes of the planets of our solar system.

\begin{center}

\begin{tabular}{lr}

Planet & Diameter(km)\\[5pt]

Mercury & 4878\\

Venus & 12104\\

Earth & 12756\\

Mars & 6794\\

Jupiter & 142984\\

Saturn & 120536\\

63

TABLES

VII.2.

Uranus & 51118\\

Neptune & 49532\\

Pluto & 2274

\end{tabular}

\end{center}

As can be seen, Pluto is the smallest and Jupiter the largest

The \begin{center} ... \end{center} commands centralize the table. The table itself is

produced by the \begin{tabular} ...\end{tabular} commands. The {lr} speci¬cation

immediately after the \begin{tabular} indicates there are two columns in the table with

the entries in the ¬rst column aligned on the left and the entries in the second column

aligned on the right. The entries in each column are separated by the & symbol and the

terminatio of each row is signalled by the \\ symbol. The \\[5pt] after the ¬rst row

speci¬es as usual, an additional vertical space of 5 points after this row in the output.

In addition to the column speci¬ers l and r we also have a speci¬er c which makes

the entries in the corresponding column centrally aligned. For example the input

\begin{center}

\begin{tabular}{cr}

Planet & Diameter(km)\\[5pt]

Mercury & 4878\\

Venus & 12104\\

Earth & 12756\\

Mars & 6794\\

Jupiter & 142984\\

Saturn & 120536\\

Uranus & 51118\\

Neptune & 49532\\

Pluto & 2274

\end{tabular}

\end{center}

produces the output below

Planet Diameter(km)

Mercury 4878

Venus 12104

Earth 12756

Mars 6794

Jupiter 142984

Saturn 120536

Uranus 51118

Neptune 49532

Pluto 2274

There™s yet another column speci¬er p which allows us to set column entries in a box

of speci¬ed width (technically a “parbox””see Chapter X). Suppose you want something

like this

64 ROWS COLUMNS

VII. AND

Planet Features

Mercury Lunar like crust, crustal faulting, small magnetic ¬elds.

Venus Shrouded in clouds, undulating surface with highlands, plains, lowlands

and craters.

Earth Ocens of water ¬lling lowlands between continents, unique in supporting

life, magnetic ¬eld.

Mars Cratered uplands, lowland plains, volcanic regions.

Jupiter Covered by clouds, dark ring of dust, magnetic ¬eld.

Saturn Several cloud layers, magnetic ¬eld, thousands of rings.

Uranus Layers of cloud and mist, magentic ¬eld, some rings.

Neptune Unable to detect from earth.

Pluto Unable to detect from earth

It is produced from the input

\begin{center}

\begin{tabular}{lp{.8\linewidth}}

Planet & Features\\[5pt]

Mercury & Lunar like crust, crustal faulting, small magnetic

fields.\\

Venus & Shrouded in clouds, undulating surface with highlands,

plains, lowlands and craters.\\

Earth & Ocens of water filling lowlands between continents,

unique in supporting life, magnetic field.\\

Mars & Cratered uplands, lowland plains, volcanic regions.\\

Jupiter & Covered by clouds, dark ring of dust, magnetic field.\\

Saturn & Several cloud layers, magnetic field, thousands

of rings.\\

Uranus & Layers of cloud and mist, magentic field, some rings.\\

Neptune & Unable to detect from earth.\\

Pluto & Unable to detect from earth

\end{tabular}

\end{center}

Here the speci¬cation p{6cm} shows that in a “paragraph box” of width 6 cm. In a p-type

column, if a \raggedright or \centering is given, then we can induce explicit line breaks

within that column by the \\ command. If such commands are used in the last column

of a row, then the command \tabularnewline should be used to terminate that row as in

this example:

\begin{center}

\begin{tabular}{lp{6cm}}

Planet & Features\tabularnewline[8pt]

Mercury & \raggedright Lunar like crust\\

Crustal faulting\\

Small magnetic fiels\tabularnewline[3pt]

Venus & \raggedright Shrouded in clouds\\

Undulating surface\tabularnewline[3pt]

Earth & \raggedright Ocens of water\\

Unique in supporting life\\

Magnetic field\tabularnewline[3pt]

Mars & \raggedright Cratered uplands\\

65

TABLES

VII.2.

Lowland plains\\

Volcanic regions\tabularnewline[3pt]

Jupiter & \raggedright Covered by clouds\\

Dark ring of dust\\

Magnetic field\tabularnewline[3pt]

Saturn & \raggedright Several cloud layers Magnetic field\\

Thousands of rings\tabularnewline[3pt]

Uranus & \raggedright Layers of cloud and mist\\

Magentic field\\

Some rings\tabularnewline[3pt]

Neptune & Unable to detect

from earth\tabularnewline[3pt]

Pluto & Unable to detect

from earth\tabularnewline[3pt]

\end{tabular}

\end{center}

This produces the output below

Planet Features

Mercury Lunar like crust

Crustal faulting

Small magnetic ¬els

Venus Shrouded in clouds

Undulating surface

Earth Ocens of water

Unique in supporting life

Magnetic ¬eld

Mars Cratered uplands

Lowland plains

Volcanic regions

Jupiter Covered by clouds

Dark ring of dust

Magnetic ¬eld

Saturn Several cloud layers

Magnetic ¬eld

Thousands of rings

Uranus Layers of cloud and mist

Magentic ¬eld

Some rings

Neptune Unable to detect from earth

Pluto Unable to detect from earth

Note that the last two lines don™t need a \raggedright command, since there are no

explicit linebreaks in them.

A table usually contains horizonntal and vertical lines separating the rows and

columns. These can also be produced in the tabular environment. For example, the

¬rst table we saw above can be typeset as

66 ROWS COLUMNS

VII. AND

Planet Diameter(km)

Mercury 4878

Venus 12104

Earth 12756

Mars 6794

Jupiter 142984

Saturn 120536

Uranus 51118

Neptune 49532

Pluto 2274

by the input

\begin{center}

\begin{tabular}{|l|r|}

\hline

Planet & Diameter(km)\\

\hline

Mercury & 4878\\

..............

Pluto & 2274\\

\hline

\end{tabular}

\end{center}

Do you see what produced the vertical and horizontal lines? Instead of the speci¬cation

{lr} used earlier, we now have {|l|r|} The character | causes a vertical line to be drawn

at the speci¬ed location, running down the entire height of the table. (Two |™s in succes-

sion produce a double vertical lines.) An \hline command after a row draws a horizontal

line after that row, running along the entire width of the table. (Again, two \hline™s in

succession producea double horizontal line.) Note also that because of the last \hline ,

we should give a line termination command \\ at the end of the last row also.

Now suppose we want to produce something like this

Planet Distance from sun (km)

Maximum Minimum

Mercury 69400000 46800000

Venus 109000000 107600000

Earth 152600000 147400000

Mars 249200000 207300000

Jupiter 817400000 741600000

Saturn 1512000000 1346000000

Uranus 3011000000 2740000000

Here, there are three columns and the entry Distance from the sun (km) is to span the

the last two columns below it. The command \multicolumn does the trick as shown

below

\begin{center}

\begin{tabular}{lrr}

Planet & \multicolumn{2}{c|}{Distance from sun (km)}\\

& Maximum & Minimum\\

67

TABLES

VII.2.

Mercury & 69400000 & 46800000\\

Venus & 109000000 & 107600000\\

Earth & 152600000 & 147400000\\

Mars & 249200000 & 207300000\\

Jupiter & 817400000 & 741600000\\

Saturn & 1512000000 & 1346000000\\

Uranus & 3011000000 & 2740000000\\

\end{tabular}

\end{center}

The entry \multicolumn{2}{c}{Distance from sun (km)} indicates that the item within

the last set of braces is to span two columns as speci¬ed by the 2 within the ¬rst set of

braces. The entry c within the second set of bracesindicates that this text is to be centered

within the column. Thus the general form of the command is

\multicolumn{num}{pos}}item}

where num is the number of columns to be spanned, pos is the position of the item within

the column and item is the text of the item. Note also that the input for the second row

starts with an & character. This is because there is no entry in the ¬rst column of the

second row.

Now what if you want

Planet Distance from sun (km)

Maximum Minimum

Mercury 69400000 46800000

Venus 109000000 107600000

Earth 152600000 147400000

Mars 249200000 207300000

Jupiter 817400000 741600000

Saturn 1512000000 1346000000

Uranus 3011000000 2740000000

Neptune 4543000000 4466000000

Pluto 7346000000 4461000000

Here the ¬rst few lines and the last lines of the input are as below (the other lines are the

same as in the previous example).

\begin{center}

\begin{tabular}{|l|r|r|}

\hline

Planet & \multicolumn{2}{c|}{Distance from sun (km)}\\

\cline{2-3}

& Maximum & Minimum\\

\hline

................................

\hline

\end{tabular}

\end{center}

Note that the position speci¬er in the \multicolumn command here is c|. This has to

do with the way the environment splits the column speci¬cation into various columns.

68 ROWS COLUMNS

VII. AND

For example, the speci¬cation |l|r|r| in this exaple is split into |l|, r| and r| and

the \multicolumn{2} command resets the last two columns. In particular, the ¬nal | gets

reset and we™ll have to explicitly supply it in the position speci¬cation of the \multicolumn

command as c|.

Note also the command \cline{2-3} after the ¬rst row. This draws a horizontal

line from the second to the third column. In general the command \cline{i-j} draws a

horizontal line from the ith column to the jth column.

Another feature of the \multicolumn command is that with \multicolumn{1} we can

override the position speci¬cation of any column set at the beginning of the environment.

For example, consider the input below

\begin{center}

\begin{tabular}{|l|r|r|}

\hline

& \multicolumn{2}{p{3.5cm}|}%

{\centering Distance from sun \\ (million km)}\\

\cline{2-3}

\multicolumn{1}{|c|}{Planet}

& \multicolumn{1}{c|}{Maximum}

& \multicolumn{1}{c|}{Minimum}\\

\hline

Mercury & 69.4 & 46.8\\

Venus & 109.0 & 107.6\\

Earth & 152.6 & 147.4\\

Mars & 249.2 & 207.3\\

Jupiter & 817.4 & 741.6\\

Saturn & 1512.0 & 1346.0\\

Uranus & 3011.0 & 2740.0\\

Neptune & 4543.0 & 4466.0\\

Pluto & 7346.0 & 4461.0\\

\hline

\end{tabular}

\end{center}

It produces the output below

Distance from sun

(million km)

Planet Maximum Minimum

Mercury 69.4 46.8

Venus 109.0 107.6

Earth 152.6 147.4

Mars 249.2 207.3

Jupiter 817.4 741.6

Saturn 1512.0 1346.0

Uranus 3011.0 2740.0

Neptune 4543.0 4466.0

Pluto 7346.0 4461.0

Note that even though \centering is used in the last column of the ¬rst row, no \tabularnewline

is required to terminate this row, since the scope of the \centering is limited by the

\multicolumn.

69

TABLES

VII.2.

By the way, do you feel that the tables we™ve been produced look a bit cramped? A

bit crowded vertically? Well, you can create a bit more room between rows by rede¬ning

the value of \arraystretch. By default, it™s value is 1 and if you set it to a number k,

then the interrow space is increased k-fold. Thus the input of the last example with the

command

\renewcommand{\arraystretch}{1.2}

after the \begin{center} produces

Distance from sun

(million km)

Planet Maximum Minimum

Mercury 69.4 46.8

Venus 109.0 107.6

Earth 152.6 147.4

Mars 249.2 207.3

Jupiter 817.4 741.6

Saturn 1512.0 1346.0

Uranus 3011.0 2740.0

Neptune 4543.0 4466.0

Pluto 7346.0 4461.0

Next let™s see how we produce a table like the one below

Height Ideal weight

(cm) (kg)

155 53.5“64

160 56“67

165 59“71

170 62.5“75.5

175 66“79

180 70“83.5

185 71.5“86.5

190 78“92.5

Here we want all the dashes in the second column to be vertically aligned, so that we must

set them in a separate column; but then there should be no space between the numbers

and the dashes connecting them. In such cases we can use the @ command in the column

speci¬cation as below

\begin{center}

\begin{tabular}{|c|r@{--}l|}

\hline

Height & \multicolumn{2}{c|}{Ideal weight}\\

(cm) & \multicolumn{2}{c|}{(kg)}\\

\hline

155 & 53.5 & 64\\

160 & 56 & 67\\

...............

190 & 78 & 92.5\\

70 ROWS COLUMNS

VII. AND

\hline

\end{tabular}

\end{center}

Here the speci¬cation r@{--}l indicates that there should be a right aligned column and

a left aligned column with a “ in between each pair of entries in these columns without

the intercolumn space the tabular environment leaves by default between every pair of

columns. Note that this incidently saves us the trouble of repeatedly typing --. You

can also add some space producing commands within the braces after the @ command to

produce that much space between the columns on either side of it.

Enhancements to the tabular

VII.2.1.

There are many packages which provide further facilities in forming tables. We™ll discuss

a couple of such packages here.

The array package

VII.2.2.

Look at the tables below

Planet Mean distance Mean distance

Planet

from sun from sun

( km) (km)

Mercury Mercury

58100000 58100000

Venus Venus

108300000 108300000

Earth Earth

150000000 150000000

Mars Mars

228250000 228250000

Jupiter Jupiter

779500000 779500000

Saturn Saturn

1429000000 1429000000

Uranus Uranus

2439000000 2439000000

Neptune Neptune

4504500000 4504500000

Pluto Pluto

5903500000 5903500000

The one on the right looks nicer, doesn™t it? It was produced using the column speci¬er m

available in the array package. To produce this table, we must ¬rst load the array package

by the ususl \usepackage{array} in the preamble and then type

\begin{tabular}{|l|r|}

\hline

\multicolumn{1}{|m{1.5cm}|}{\centering Planet}

&\multicolumn{1}{m{2.3cm}|}%

{\centering Mean distance from sun \\ (km)}\\

\hline

Mercury & 58100000\\

...................

Pluto & 5903500000\\

\hline

\end{tabular}

The m{wd} speci¬er produces a column of width wd just like the p speci¬er, but with the

text aligned vertically in the middle unlike the p speci¬er which aligns the text with the

topline. (The table on the left, incidently, was produced by the same input as above but

with p instead of m).

71

TABLES

VII.2.

Another interesting feature of the array package is the >{decl} command which can

be used before a column speci¬er. It inserts decl directly in front of the column. For

example look at the input below

\begin{center}

\begin{tabular}{|>{\bfseries}l|r|}

\hline

\multicolumn{1}{|m{1.5cm}|}{\centering Planet}

&\multicolumn{1}{m{2.3cm}|}%

{\centering Mean distance from sun \\ (km)}\\

\hline

Mercury & 58100000\\

Venus & 108300000\\

Earth & 150000000\\

Mars & 228250000\\

Jupiter & 779500000\\

Saturn & 1429000000\\

Uranus & 2439000000\\

Neptune & 4504500000\\

Pluto & 5903500000\\

\hline

\end{tabular}

\end{center}

which produces the output

Mean distance

Planet from sun

(km)

Mercury 58100000

Venus 108300000

Earth 150000000

Mars 228250000

Jupiter 779500000

Saturn 1429000000

Uranus 2439000000

Neptune 4504500000

Pluto 5903500000

The array package also has a ! command which works just like the @ command, but

whch does not suppress the intercolumn space.

The multirow package

VII.2.3.

Look again at the table in 68. Wouldn™t it be nice if the entry “Planet” in the ¬rst column

is vertically aligned with the center of the two rows in the next column as below?

72 ROWS COLUMNS

VII. AND

Distance from sun

Planet (million km)

Maximum Minimum

Mercury 69.4 46.8

Venus 109.0 107.6

Earth 152.6 147.4

Mars 249.2 207.3

Jupiter 817.4 741.6

Saturn 1512.0 1346.0

Uranus 3011.0 2740.0

Neptune 4543.0 4466.0

Pluto 7346.0 4461.0

The package multirow is what we need to do this painlessly. It has a command

\multirow{num}{wd}{item}

where num is the number of rows to be spanned, wd is the width of this column and item

is the text of the item in this column. This can be used as in the following example

\begin{center}

\begin{tabular}{|l|r|r|}

\hline

\multirow{3}{1.5cm}{Planet}

& \multicolumn{2}{p{3.5cm}|}%

{\centering Distance from sun \\ (million km)}\\

\cline{2-3}

& \multicolumn{1}{c|}{Maximum}

& \multicolumn{1}{c|}{Minimum}\\

\hline

Mercury & 69.4 & 46.8\\

Venus & 109.0 & 107.6\\

Earth & 152.6 & 147.4\\

Mars & 249.2 & 207.3\\

Jupiter & 817.4 & 741.6\\

Saturn & 1512.0 & 1346.0\\

Uranus & 3011.0 & 2740.0\\

Neptune & 4543.0 & 4466.0\\

Pluto & 7346.0 & 4461.0\\

\hline

\end{tabular}

\end{center}

But this code does not produce the table above, but only

73

TABLES

VII.2.

Distance from sun

Planet (million km)

Maximum Minimum

Mercury 69.4 46.8

Venus 109.0 107.6

Earth 152.6 147.4

Mars 249.2 207.3

Jupiter 817.4 741.6

Saturn 1512.0 1346.0

Uranus 3011.0 2740.0

Neptune 4543.0 4466.0

Pluto 7346.0 4461.0

The trouble is that though the entry “Planet” is vertically centered in its column, it

is not horizontally centered. The horizontal alignment is controlled by the command

\multirowsetup and this is by default st to \raggedright. So all that is needed to get the

beautiful table seen at the beginning of this section is to add the line

\renewcommand{\multirowsetup}{\centering}

at the beginning of the code above.

vs. tabular

VII.2.4. tabbing

Let™s take a quick look at the pros and cons of the tabbing and tabular environments.

• The tabbing environment can be typeset only as a separate paragraph, while the

tabular environment can be placed anywhere in text, even inside Mathematics.

• The tabbing environment can span multiple pages, but the tabular environment

cannot.

• tabbing environments cannot be nested, while tabular environments can be nested

to any number of levels.

Multipage tables”The package longtable

VII.2.5.

As we have noted, we cannot create table spanning more than one page using the tabular

environment. But the package longtable by David Carlisle can do this and it has quite a

few other tricks also. To use this package, load it as usual with the command \usepackage{longtable}

in the preamble and then to produce a no-frills “longtable” just use the commands

\begin{longtable} ... \end{longtable} instead of the \begin{tabular} ... \end{tabular}

commands. We can use footnotes and the \newpage commands inside the longtable en-

vironment. If the package array is also loaded, its extra features can be used.

Apart from this, this package has provisions to specify at the start of the input the

following items

• the rows that should appear at the top of the table; the input for these to be termi-

nated by \endfirsthead

• the rows that should appear in every page after the ¬rst, such input terminated by

\endhead

• those at the bottom of every page, the input terminated by \endfoot

74 ROWS COLUMNS

VII. AND

• those rows at the very end of the table, terminated by \endlastfoot

These are illustrated in the (long!) table below.

Science and Technology in the Twentieth Century

Year Event

Max Planck proposes quantum theory

1900

Publication of Sigmund Freud™s The Interpretation of Dreams

Discovery of principal blood groups

1901

Guglielmo Marconi transmits wireless signals across the atlantic

Wright brothers make their ¬rst ¬‚ight

1903

Albert Einstein presents Special Theory of Relativity

1905

Ernest Rutherford proposes theory of atomic structure

1911

Victor Hess discovers cosmic rays

1912

Albert Einstein presents general Theory of Relativity

1916

Radio broadcasting begins

1920

John Logie Baird demonstrates television

1926

Alexander Fleming discovers penicillin

1928

Discovery of polythene

1933

Discovery of nuclear ¬ssion

1934

Discovery of nylon

1938

Plutonium obtained by bombardment of uranium

1940

Construction of ¬rst nuclear reactor

1942

Construction of ¬rst electronic digital computer

1946

First supersonic ¬‚ight

1947

Invention of the transistor

Nuclear power stations introduced

1951

James Watson and Francis Crick show DNS molecule structure

1953

Contraceptive pill introduced

1956

Launch of the ¬rst space satellite (Sputnik 1)

1957

First photograph of the dark side of the moon (Luna 3)

1959

··· ·········

··· ·········

··· ·········

··· ·········

··· ·········

··· ·········

··· ·········

··· ·········

··· ·········

··· ·········

··· ·········

··· ·········

Yuri Gagarin becomes ¬rst man in space (Vostok 1)

1961

First lunar soft landing (Luna 9)

1966

Discovery of pulsars

1967

First manned lunar orbit (Apollo 8)

1968

First man on moon (Neil Armstrong)

1969

Pocket calculator introduced

1972

continued on the next page

75

TABLES

VII.2.

Science and Technology in the Twentieth Century (continued)

Year Event

First ˜test-tube babies™

1974

Launch of Voyager missions to outer spce

1977

IBM personal computer launched

1983

Hailey™s comet intercepted

1986

Cloning of “Dolly” the sheep

1997

Decoding of 90% of human genome completed

2000

Source : The Cambrige Fact¬nder

Part of the code to produce this is given below.

\renewcommand{\arraystretch}{1.2}

\begin{longtable}{|c|l|}

\multicolumn{2}{c}%

{\textbf{Science and Technology in the Twentieth Century}}\\[5pt]

\hline

\multicolumn{1}{|c|}{\sffamily Year}

&\multicolumn{1}{|c|}{\sffamily Event}\\

\hline

\endfirsthead

\multicolumn{2}{c}%

{\textbf{Science and Technology in the Twentieth Century}

(\textit{continued})}\\[5pt]

\hline

\multicolumn{1}{|c|}{\sffamily Year}

&\multicolumn{1}{|c|}{\sffamily Event}\\

\hline

\endhead

\hline

\multicolumn{2}{r}{\small\itshape continued on the next page}\\

\endfoot

\hline

\multicolumn{2}{r}{\small Source\,:\,\itshape The Cambrige Factfinder}

\endlastfoot

1900 & Max Planck proposes quantum theory\\

..............................................

2000 & Decoding of 90\% of human genome completed\\

\hline

\end{longtable}

And that™s not all!

VII.2.6.

There are many more packages which help to produce tables of various requirements. Be

sure to check out the pakages tabularx, delarray, dcolumn and hhline.

76

TUTORIAL VIII

TYPESETTING MATHEMATICS

Donal Knuth created TEX primarily to typeset Mathematics beautifully. LTEX includes all

A

the capabilities of TEX in Mathematics typesetting, sometimes with easier user interfaces.

Then there are packages like amsmath which enhance and re¬ne these interfaces.

THE

VIII.1. BASICS

A mathematical expression occurring in running text (called in-text math) is produced by

enclosing it between dollar signs. Thus to produce

The equation representing a straight line in the Cartesian plane is of the form ax + by + c = 0,

where a, b, c are constants.

we type

The equation representing a straight line in the Cartesian plane

is of the form $ax+by+c=0$, where $a$, $b$, $c$ are constants.

Some comments are in order. First note that the text within dollars is typeset in italic

(actually math italic). Again, even though we did not leave any spaces within ax+by+c=0,

TEX leaves spaces on either side of the addition signs and the equality sign. On the other

hand, even if we type $ax + by + c = 0$, the output would be the same: ax + by + c = 0.

The moral? TEX has its own spacing rules in math mode.

To see another instance of this, change the last part of the code above to read

... where $a, b, c$ are constants.

Saves some typing, does not it? But look at the output.

The equation representing a straight line in the Cartesian plane is of the form ax + by + c = 0,

where a, b, c are constants.

Do you see the difference? There are no spaces after the commas, though we had such

spaces in the output. So TEX swallows spaces in math mode (you can not save dollars

that way!).

Incidentally, dollar signs are TEX way of distinguishing Mathematical text. LTEX

A

has other ways also of doing it, using \( ... \) or \begin{math} ... \end{math}. Thus

either of the inputs shown below also produces the same output as above.

The equation representing a straight line in the Cartesian plane is of

the form \(ax+by+c=0\), where \(a\), \(b\), \(c\) are constants.

The equation representing a straight line in the Cartesian plane is

of the form \begin{math}ax+by+c=0\end{math}, where \begin{math} a

\end{math}, \begin{math} b \end{math}, \begin{math} c \end{math} are

constants.

77

78 TYPESETTING MATHEMATICS

VIII.

Now suppose we want to display the equation in the above output as in

The equation representing a straight line in the Cartesian plane is of the form

ax + by + c = 0

where a, b, c are constants.

This can be done by changing the input as follows:

The equation representing a straight line in the Cartesian plane is

of the form

$$

ax+by+c=0

$$

where $a$, $b$, $c$ are constants.

Again $$ ... $$ is the TEX way of producing displayed math. LTEX has the constructs

A

\[ ... \] or \begin{displaymath} ... \end{displaymath} also to do this.

Superscripts and subscripts

VIII.1.1.

Look at the text below

In the seventeenth century, Fermat conjectured that if n > 2, then there are no integers x, y, z

for which

xn + yn = zn .

This was proved in 1994 by Andrew Wiles.

This is produced by the input

In the seventeenth century, Fermat conjectured that if $n>2$, then

there are no integers $x$, $y$, $z$ for which

$$

xˆn+yˆn=zˆn.

$$

This was proved in 1994 by Andrew Wiles.

This shows that superscripts (mathematicians call them exponents) are produced by the

ˆ symbol. If the superscript is more than one character long, we must be careful to group

these characters properly. Thus to produce

It is easily seen that (xm )n = xmn .

we must type

It is easily seen that $(xˆm)ˆn=xˆ{mn}$.

Instead of $xˆ{mn}$, if we type $xˆmn$ we end up with xm n instead of the intended xmn

in the output.

We can have superscripts of superscripts (and mathematicians do need them). For

example,

n

Numbers of the form 22 + 1, where n is a natural number, are called Fermat numbers.

is produced by

79

THE

VIII.1. BASICS

Numbers of the form $2ˆ{2ˆn}+1$, where $n$ is a natural number, are

called Fermat numbers.

Note the grouping of superscripts. (What happens if you type $2ˆ2ˆn+1$ or ${2ˆ2}ˆn$?)

Now let us see how subscripts (mathematicians call them subscripts) are produced.

To get

The sequence (xn ) de¬ned by

x1 = 1, x2 = 1, xn = xn’1 + xn’2 (n > 2)

is called the Fibonacci sequence.

we must type

The sequence $(x_n)$ defined by

$$

x_1=1,\quad x_2=1,\quad x_n=x_{n-1}+x_{n-2}\;\;(n>2)

$$

is called the Fibonacci sequence.

Thus subscripts are produced by the _ character. Note how we insert spaces by the \quad

command. (The command \; in math mode produces what is known as a “thickspace”.)

Subscripts of subscripts can be produced as in the case of superscripts (with appropriate

grouping).

We can also have superscripts and subscripts together. Thus

If the sequence (xn ) converges to a, then the sequence (x2 ) converges to a2

n

is produced by

If the sequence $(x_n)$ converges to $a$, then the sequence

$(x_nˆ2)$ converges to $aˆ2$

Again, we must be careful about the grouping (or the lack of it) when typesetting

superscripts and subscripts together. The following inputs and the corresponding outputs

make the point.

$$

x_mˆn\qquad xˆn_m\qquad {x_m}ˆn\qquad {xˆn}_m

$$

xn xn xm n xn m

m m

(This has to do with the way TEX works, producing “boxes” to ¬t the output characters.

The box for xn is like xn while the box for xm n is xm n .

m m

Roots

VIII.1.2.

√

Square roots are produced by the \sqrt argument. Thus $\sqrt{2}$ produces 2. This

command has an optional argument to produce other roots. Thus

√

√ 5

4

Which is greater 5 or 4?

is produced by

80 TYPESETTING MATHEMATICS

VIII.

Which is greater $\sqrt[4]{5}$ or $\sqrt[5]{4}$?

The horizontal line above the root (called vinculum by mathematicians of yore) elon-

√

gates to accommodate the enclosed text. For example, $\sqrt{x+y}$ produces x + y.

Also, you can produce nested roots as in

The sequence

√ √ √ √

2 2, 2, 2+ 2, 2+ 2+ 2+ 2, ...

22 23 24

2’ 2’ 2’

converge to π.

by typing

The sequence

$$

2\sqrt{2}\,,\quad 2ˆ2\sqrt{2-\sqrt{2}}\,,\quad 2ˆ3

\sqrt{2-\sqrt{2+\sqrt{2}}}\,,\quad 2ˆ4\sqrt{2-

\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2}}}}}\,,\;\ldots

$$

converge to $\pi$.

The \ldots command above produces . . ., the three dots indicating inde¬nite contin-

uation, called ellipsis (more about them later). The command \, produces a “thinspace”

(as opposed to a thickspace produced by \; , seen earlier). Why all this thin and thick

spaces in the above input? Remove them and see the difference. (A tastefully applied

thinspace is what makes a mathematical expression typeset in TEX really beautiful.)

The symbol π in the output produced by $\pi$ maybe familiar from high school

mathematics. It is a Greek letter named “pi”. Mathematicians often use letters of the

Greek alphabet ((which even otherwise is Greek to many) and a multitude of other sym-

bols in their work. A list of available symbols in LTEX is given at the end of this chapter.

A

Mathematical symbols

VIII.1.3.

In the list at the end of this chapter, note that certain symbols are marked to be not avail-

able in native LTEX, but only in certain packages. We will discuss some such packages

A

later. Another thing about the list is that they are categorized into classes such as “Bi-

nary Relations”, “Operators”, “Functions” and so on. This is not merely a matter of

convenience.

We have noted that TEX leaves some additional spaces around “binary operators”

such as + and ’. The same is true for any symbol classi¬ed as a binary operator. For

example, consider the following

For real numbers x and y, de¬ne an operation —¦ by

x —¦ y = x + y ’ xy

This operation is associative.

From the list of symbols, we see that —¦ is produced by \circ and this is classi¬ed as a

binary operator, so that we can produce this by

For real numbers $x$ and $y$, define an operation $\circ$ by

$$

81

CUSTOM

VIII.2. COMMANDS

x\circ y = x+y-xy

$$

This operation is associative.

Note the spaces surrounding the —¦ symbol in the output. On the other hand suppose you

want

For real numbers x and y, de¬ne an operation by

y = x2 + y2

x

The list of symbols show that the symbol is produced by \Box but that it is avail-

able only in the package latexsym or amssymb. So if we load one of these using the

\usepackage command and then type

For real numbers $x$ and $y$, define an operation $\Box$ by

$$

x\Box y = xˆ2+yˆ2

$$

you will only get

For real numbers x and y, de¬ne an operation by

x y = x2 + y2

Notice the difference? There are no spaces around ; this is because, this symbol is

not by default de¬ned as a binary operator. (Note that it is classi¬ed under “Miscel-

laneous”.) But we can ask TEX to consider this symbol as a binary operator by the

command \mathbin before \Box as in

For real numbers $x$ and $y$, define an operation $\Box$ by

$$

x\mathbin\Box y=xˆ2+yˆ2

$$

and this will produce the output shown ¬rst.

This holds for “Relations” also. TEX leaves some space around “Relation” symbols

and we can instruct TEX to consider any symbol as a relation by the command \mathrel.

Thus we can produce

De¬ne the relation ρ on the set of real numbers by x ρ y iff x ’ y is a rational number.

by typing

Define the relation $\rho$ on the set of real numbers by

$x\mathrel\rho y$ iff $x-y$ is a rational number.

(See what happens if you remove the \mathrel command.)

CUSTOM

VIII.2. COMMANDS

We have seen that LTEX produces mathematics (and many other things as well) by means

A

of “commands”. The interesting thing is that we can build our own commands using

the ones available. For example, suppose that t the expression (x1 , x2 , . . . , xn ) occurs

frequently in a document. If we now write

82 TYPESETTING MATHEMATICS

VIII.

\newcommand{\vect}{(x_1,x_2,\dots,x_n)}

Then we can type $\vect$ anywhere after wards to produce (x1 , x2 , . . . , xn ) as in

We often write $x$ to denote the vector $\vect$.

to get

We often write x to denote the vector (x1 , x2 , . . . , xn ).

(By the way, the best place to keep such “newcommands” is the preamble, so that you

can use them anywhere in the document. Also, it will be easier to change the commands,

if the need arises).

OK, we can now produce (x1 , x2 , . . . , xn ) with $\vect$, but how about (y1 , y2 , . . . , yn )

or (z1 , z2 , . . . , zn )? Do we have to de¬ne newcommands for each of these? Not at all. We

can also de¬ne commands with variable arguments also. Thus if we change our de¬nition

of \vect to

\newcommand{\vect}[1]{(#1_1,#1_2,\dots,#1_n)}

Then we can use $\vect{x}$ to produce (x1 , x2 , . . . , xn ) and $\vect{a}$ to produce

(a1 , a2 , . . . , an ) and so on.

The form of this de¬nition calls for some comments. The [1] in the \newcommand

above indicates that the command is to have one (variable) argument. What about the

#1? Before producing the output, each occurrence of #1 will be replaced by the (single)

argument we supply to \vect in the input. For example, the input $\vect{a}$ will be

changed to $(a_1,a_2,\dots,a_n)$ at some stage of the compilation.

We can also de¬ne commands with more than one argument (the maximum number

is 9). Thus for example, if the document contains not only (x1 , x2 , . . . , xn ), (y1 , y2 , . . . , yn )

and so on, but (x1 , x2 , . . . , xm ), (y1 , y2 , . . . , yp ) also, then we can change our de¬nition of

\vect to

\newcommand{\vect}[2]{(#1_1,#1_2,\dotsc,#1_#2)}