<< . .

. 9
( : 23)



. . >>


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

<< . .

. 9
( : 23)



. . >>