# Spacing, Lengths, and Tables

(URL http://www.cs.cornell.edu/Info/Misc/LaTeX-Tutorial/Tables.html)

The topics to be covered in this section of the LaTeX tutorial include fullpage, double spacing, blank space, and tables.

# Using the Full Page

LaTeX doesn't use much of the page when it formats text, only about 4.8 x 7.3 inches. Therefore, to really make use of the page to conserve paper and get more ideas per page, you want to use fullpage as one of your optional arguments to the \documentstyle commands. It appears next to the 12pt specification you have been using throughout this tutorial.

\documentstyle[12pt,fullpage]{article}

That will set the margins to about 6.5 x 8.9 inches.

# Double Spacing

There are several ways to change to double spacing for your document. Probably the most reliable and best looking is the doublespace style option. It goes up there with the 12pt and the fullpage options.

\documentstyle[12pt,fullpage,doublespace]{article}

Note that this does not doublespace footnotes or figures and tables. If the spacing is too wide, you can put the following command in your preamble:

\setstretch{1.7}

That will decrease the stretch between lines. The setstretch in double spacing is normally set to "2." If you change it to "1," you will be back into single spacing again.

You can create a single spaced environment by using:

\begin{singlespace}
\end{singlespace}

Note that the singlespace environment is not valid unless the doublespace style option has been used.

Use the file called down.tex that you created earlier and make it doublespaced. While you are at it, make the two parts into separate paragraphs.

Here's the dvi output.

# Tables

There are three similar constructs for doing tables in LaTeX. They are:

Table
A floating "thing" in a paper.
Usually "see Table 3" or something in the text.
Tabular
A bunch of rows and columns.
Width of columns determined automatically.
Must fit on one page.
Tabbing
Power similar to tabular.
Can be many pages long.
Formatting changes more flexible.

We will cover the basic functions of tabular in this section of the tutorial.

You input a table in a \begin{tabular} environment. The alignment of the columns is specified in the environment command. The rows are separated by a line break \\, and the columns are separated by an &. For example, the following yields these results.

   \begin{tabular}{rrr}
This & Here & And the \\
is & is second & third is \\
first & column & here \\
\end{tabular}


In this example there are three columns which are all aligned on the right {rrr}. Columns can be aligned according to the following options:

r - right justify the column
l - left justify the column
c - center the column

Take the above example of the tabular environment and change the column alignments three times, stopping to format and preview the results each time.

1. all left justified
2. all centered
3. first column right justified, second column centered, and third column left justified

Use the \bigskip command to try to get some more space between the sections.

Here's the dvi output.

If you look at the output of the previous examples, you will notice that the columns are not separated by much space. You can add horizontal space between columns by using the \hspace{width} command in the table setup. For example to add 1 inch between the columns of a table, use the following construct:

\begin{tabular}{r{\hspace{1in}}rr}
. . .
\end{tabular}

Take the updated tab.tex file and add 1 in of horizontal space between each of the columns. Then format it and preview the results.

For the rest of the work to be done with tables, we will use the goal document tables.tex. The final document looks like this. To get tables.tex so you can modify it in the next few exercises, make sure you are in your "latex" directory and copy the file from ~denise/LaTeX/Samples/tables.tex into that directory.

There are two tables in the goal document tables.tex. Make the first table a 2-column table and the second a 4-column table. Do your best to guess the column alignment options.

The document will not look anything like the goal document yet, but don't worry about that at this time.

Here is the dvi output.

## Table Positioning

Tabular items can appear in-line in the text or it can be centered on the page if more appropriate. Consider the following input document and its dvi output.

You can put tabular text \begin{tabular} inline like this \end{tabular}, or you can center it. 

To center it you would use the \begin{center}  environment followed by the \begin{tabular} environment, as in:

\begin{center}
\begin{tabular}
 . .
\end{tabular}
\end{center}

## Columns as Paragraphs

Some columns in a table look more like paragraphs than single lines. You could put in explicit line breaks to break lines within the column width, but that makes it very hard to update if you add or delete text. The tabular environment provides a way for you to set a width to automatically break the lines.

Rather than using c or l or r to define the columns of the table, use p{width} which will create a column width wide where you can input a paragraph of text.

\begin{tabular}{p{1in}p{2in}}

The previous example creates two columns, of which the left is one inch wide, and the right is two inches wide.

In tables.tex, make the description column of the first table a paragraph which is 3 1/2 inches wide. Make the first column of the second table 2.2 inches wide. Center both tables.

Here is the dvi output.

The LaTeX command \hline puts a line after any row of a table. It can be used only at the start of a line or just after a row separator (\\). For example, the following input file produces these results.

\begin{tabular}{rrr}
\hline
This & Here & And the \\
\hline
is & is second & third is \\
\hline
first & column & here \\
\hline \hline
\end{tabular}

## Lines Between Columns

To put vertical bars between columns, you simply add a vertical bar between the column alignment letters, as in

\begin{tabular}{|r|r|r|}
\hline
This & Here & And the \\
\hline
is & is second & third is \\
\hline
first & column & here \\
\hline \hline
\end{tabular}

which produces these results.

## Lines Between Some Rows

You can put a horizontal line between some rows and not others by using the \cline{m-n}  command. In the format of the command, m starts the line in column m, and n ends the line in column n. Obviously, n must be greater than or equal to m, and both m and n are required by the command. Therefore,

\begin{tabular}{|r|r|r|}
\hline
This & Here & And the \\
\cline{1-2}
is & is second & third is \\
\cline{1-1} \cline{3-3}
first & column & here \\
\hline \hline
\end{tabular}

In tables.tex, put the lines around both tables. Then, in the second table, include the pair of lines that cross just the column headed by E2.

Here is the dvi output.

Now, put the double lines under the column headings of the second table, and then add the extra line separating the last row of the second table and preview the results.

Here is the dvi output.

## Changing Columns for One Row Only

If a row is slightly unusual, you can use the \multicolumn command in your table. The format for the command is:

\multicolumn{n}{code}{text}

What it does is replace the next n columns with one column. The new column is aligned as the code which is one of r, l, or c. You can use vertical bars within multicolumn alignments as well. The text to be placed in the column goes in text. Consider the following:

\begin{tabular}{|r|r|r|}
\hline
This & Here & And the \\
\cline{1-2}
\multicolumn{3}{|c|}{$x+y=3$} \\
\cline{1-1} \cline{3-3}
first & column & here \\
\hline \hline
\end{tabular}

which produces this table.

Go to Math-Mode
Go to Introducing LaTeX