Chapter 5
Tables

Tables are prominent features of many technical documents. Image provides two environments for typesetting tabular data. The first, the tabbing environment, is appropriate for simple tables. The second, the tabular environment, is designed for producing more elaborate tables. However, to create very complex tables, it is best to employ special sets of macros. One such set, Michael Wichura’s Image macros, is highly recommended for producing tables that have many intricate formatting requirements. All three of these methods for producing tables are summarized in this chapter.

5.1 Types of Tables

Tables can either be positioned in the main text where they are defined or created as floating objects. Except for very small tables, it is generally better to place a table in the floating table environment in order to allow Image to pick the best position for the table and also to allow Image to create the table caption and table number. The left example below shows the structure used for a typical fixed-position table, while the right example is for a typical floating table. Both examples use the tabular environment to define the table contents.

Image

5.1.1 Captions and Reference Labels

In the floating table environment, the caption command is used to place a caption next to the table (usually above it). The form of this command is

                              caption [list-of-tables-entry] {caption-text}

where the optional list-of-tables-entry is an alternative caption for the list of tables (. LOT file), and caption-text is the caption to be placed over the table. LATEX affixes to this table caption a label such as”Table 5.12:”; the number is the table number that is automatically generated by Image. The caption command cannot be used outside the table (or figure) floating environment.

A reference label may be attached to the caption with the label command. This command must come immediately after the caption command or even be placed inside the caption’s argument to be safe. For example, you might use

         caption{The refined results from …}label{tblresults}
or
         caption{The refined results from ... label{tblresults}}

Then, to refer to this table in the text, you would enter something like

… the results in Table~ ef{tblresults} were obtained…

5.2 The tabbing Environment

The tabbing environment, invoked by egin{tabbing}end(tabbing}, is modeled after tabs on a typewriter, although there are important differences. Data are entered row by row, each terminated by a \ or kill command. Within each row, data are separated by tabbing environment commands. As with a typewriter, you set tabs (=) or move to the next tab (>).

This environment can be used only in normal text mode, and it creates a single paragraph that Image can break across a page. All formatting (spacing) is determined by the user, and the available formatting features are rather limited. For example, lines (rules) are not easily incorporated. By contrast, the more robust abular environment can be used in any mode, although it generates a block of output that cannot be broken across a page. The commands available in the tabbing environment are given in the accompanying table.

Commands for the tabbing Environment

Image

5.2.1 An Instructional Example

Table 5.1 is an ugly example of the use of the tabbing environment, but it demonstrates the use of all the tabbing commands. Studying this table reveals several important features of the tabbing environment and its commands.

Table 5.1: An example table, produced in the tabbing environment, that illustrates the use of the tabbing commands

Image

  • • The kill command is most often used after the first row of a table to set the scale or distance between tab stops. Rather than use fixed distances, as in this example, you could also enter a dummy row with the longest expected entry for each column used to separate the tab stops.

This example was produced with

    hrule{}  vspace{-.2in}
    egin{tabbing}
    %% -------------------- Set tab stops
    hspace*{.25in} = hspace*{lin} = hspace*{lin} =
                                        hspace*{lin} = hspace*{lin} kill
    %% -------------------- Construct Table
    %%--create table headings
    row > column 1 > column 2 > column 3 > column 4 \[. lin] %%--extra space
    1.  > aaaa     > bbbb     > cccc     > dddd     \
    %%--example of overlapping columns
    2.  > very long first item > {sl An overlapping second item -- beware} \
    3.  > aaaa     > bbbb     > cc’cc   > dddd ‘ outdent to right \
        pushtabs                     %%-- save tab stops
    4.  > > aaaa = bbbb = cccc = dddd = eeee = \   %%--set new tabs
    5.  > > a > b > c > d > e + + \   %%--move in left margin
    6.  > a > b > c > d \
    <7.> a > b > c > d - - \   %%--shift left and restore left margin
    8.  > > a > b > c \               %%--back to normal left margin
        poptabs                                           %%-- restore tab stops
    9.> aaaa > bbbb > cccc > dddd ‘ back to old tabs \
    end{tabbing} vspace{-.2in} hrule{}

  • • Row 2 illustrates that > does not behave like a typewriter’s tab key. > places the current position at the next tab stop in the numerical order in which the stops were defined. It does not move the current position to the tab immediately to the right of the last entry. Thus, for entries that overflow a column’s width, you will get overlapping of the text, as in this example.
  • • Row 3 illustrates how is used to shift text to the left and how shifts the last entry all the way to the right page margin.
  • • After the tab positions are saved, rows 4 and 5 show how new tabs stops can be inserted between old tab stops. The ++ in row 5 also shifts the left margin in two tab stops for all subsequent lines.
  • • Row 7 shows how < is used to move left by one tab stop and how -- is used to move the left margin for subsequent lines to the left by two tab stops.
  • • After poptabs restores the old tab stops (saved by pushtabs), row 9 is printed like row 1. The pushtabs and poptabs must always be used in nested pairs.

5.3 The tabular Environment

To create a table in the tabular environment, the table definition is placed between the pair of commands

            egin{tabular} [position] {format} . . . end{tabular}

The two parameters of the tabular environment are (1) position, an optional argument that indicates the vertical position of the tabular with respect to the preceding text (either top [t] or bottom [b]), and (2) format, which the number of columns and how items are to be positioned in each column. Without the optional [position] argument, the tabular is centered vertically on the current text line. Here are some examples of the format parameter.

Image

Image

Within the tabular environment, the following commands are used to construct a table.

Commands Used in the tabular Environment

Image

Table 5.2 was constructed with all these commands. Of special note in this table are the methods used to insert vertical space between rows and around the horizontal rules. The optional argument of the \ command, for example, \[.5ex], is used to insert vertical space below the current row. To increase space above the current row, a strut is added. Since several struts are used in this table, a strut command STRUT is defined by

Table 5.2: An example table, produced in the tabular environment, that illustrates the use of all the tabular commands

Extreme Ranges of Thermal Conductivities at 273 K
Material k (W m-1 K-1) Comment
hydrogen 0.175 highest for gases
low for gases
chloroform 0.0066
mercury 8.21 high for liquids
low for liquids
freon 0.0228
silver 418.0 high for solids
low for solids
pyrex glass 1.05

                 ewcommand{STRUT}{ ule{0in}{3ex}}

and then used in any row for which extra space above the row is desired.

This table was produced with

       %------------------ Example Figure
       egin{center} footnotesize
        ewcommand{STRUT}{ ule{0in}{3ex}}     %%--- Define a strut
       egin{tabular}{|l r@3{.}l |p{1.0in}|}   %%--- Set table format
          %------------------ Top Block Headings
          hline
          multicolumn{4}{|c|}
          {smalll f Extreme Ranges of Thermal STRUT} \[1.5ex]
          multicolumn{4}{|c|}
          {small f Conductivities at 273~K} \[1.3ex]
          hline hline
          %-------------------- Table Column Headings
          {em Material} hspace{.2in} vline &
               multicolumn{2}{c} {$k$ (W m$~{-1}$ K$~{-1}$)} &
               {em Comment} STRUT \[lex] hline
          %--------------- Table Contents
          hydrogenSTRUT    & 0&175  & highest for gases \
          chloroform        & 0&0066 & low for gases      \ cline{4-4}
          mercury           & 8&21   & high for liquids \
          freon             & 0&0228 & low for liquids \ cline{4-4}
          silver            & 418&0  & high for solids \
          pyrex glass &hspace{.25in} 1&05   & low for solids\[1.3ex]
          hline
       end{tabular}  ormalsize end{center}

5.3.1 Aligning Numbers on the Decimal Point

Aligning numbers in the tabular environment on the decimal point (some of which may have no decimal point) can be done in several ways. To produce

Case Numbers Aligned on Decimal
a   245.245
b      1.05
c      0.00012345
d 12,000
e     5

the easiest way may be to use the following:

        egin{center} egin{tabular}{|cr©{}c©{}l©{}|}
        hline
         Case & multicolumn{3}{c|}{Numbers Aligned on Decimal} \
        hline
        a & hspace{0.5in} 245&.&245   \
        b & 1&.&05       \
        c & 0&.&00012345 \
        d & 12,000& &    \
        e & 5&    &      \
        hline
        end{tabular} end{center}

5.3.2 Vertical Alignment of Tables Headings

In many tables with multiline column headers, the text for some headers needs to be displaced half a line downwards, such as in headers for the first and last columns in the following example.

Material Parameter Error
α     β
Aluminum 0.23 18.2 15.1%
Magnesium 0.44 14.3 18.2%
Iron 0.75 12.9 25.0%

First define in the preamble the following new command

         ewcommand{Lower}[l]{smash{lower 1.5ex hbox{#l}}}

Then use Lower{ col. header} to shift col. header downward by half a line. The above example was created with

Image

5.3.3 A Simple Floating Table Example

Table 5.3 is an example of a simple floating table produced by the following input.

Table 5.3: A simple test table

i Ei i Ei
1 0.02 6 0.1
2 0.03 7 0.2
3 0.04 8 0.4
4 0.06 9 0.7
5 0.08 10 1.0

egin{table}[htbp]
  centering
    caption{A simple test table}label{tstla}
   egin{tabular}{|rc|rc|}   hline
      $i$  &  $E_i$  &  $i$  &  $E_i$  \ hline
       1    &   0.02   &   6    &    0.1    \
       2    &  0.03    &   7    &   0.2     \
       3    &  0.04    &   8    &   0.4     \
       4    &  0.06    &   9    &   0.7     \
       5    &  0.08    &  10    &   1.0     \ hline
   end{tabular}
end{table}

Although simple to define, Table 5.3 has several shortcomings. First, the spacing between the caption and the table is far from ideal, and there is too little space around the horizontal rules. Moreover, if the caption were very long, it would be printed on several lines extending across the full width of the page.

Table 5.4 is a refinement of this table with a longer caption. Notice the use of a parbox to restrict the width of the table caption and the use of struts and vspace commands to improve the vertical spacing. It was produced with the following input.

Table 5.4: The discrete energies Ei (MeV) used for deriving the approximate line-beam response function

i Ei i Ei
1 0.02 6 0.1
2 0.03 7 0.2
3 0.04 8 0.4
4 0.06 9 0.7
5 0.08 10 1.0

egin{table}[htbp]
egin{center}
parbox{3in}{caption{The discrete energies $E_i$ (MeV) used for
           deriving the approximate line-beam response
           function}label{tstlb}}

  vspace{.lin}
  egin{tabular}{|rc|rc|}  hline
     $i$  &  $E_i$  &  $i$  &  $E_i$  ule{0in}{3ex} \[lex] hline \
      1   &  0.02   &  6    &
                 ule{0in}{3ex} 0.1  ule{0in}{3ex}  \
      2   &  0.03   &  7    & 0.2   \
      3   &  0.04   &  8    & 0.4   \
      4   &  0.06   &  9    & 0.7   \
      5   &  0.08   & 10    & 1.0   \[lex]  hline
   end{tabular}
 end{center}
end{table}

5.3.4 Tables in a Minipage

A minipage is ideally suited for tables. Not only can the caption size be constrained by the width of the minipage, but footnotes for the table can be treated as footnotes for the minipage. Moreover, footnote symbols in a minipage are letters a, b, c…, just what is needed for a table. An example is shown in Table 5.5, which was produced by the following input:

Table 5.5: A test table with footnotes that was created in a minipage environment

Number of Observed Gnarlsa
102 54 67 5 27 73 35 17
57b 38 40 45 38 54 136 357
39 12 11 55 22 0 41 18
aAn exotic bug found in Image documents
bSmith 1993: 1-3001

       egin{table}[htb]
       egin{center}
         egin{minipage}{2.65in}
             enewcommand{footnoterule}{}
            egin{center}
               caption{A test table with footnotes that was
                   created in a minipage environment} label{minitab}
               vspace{.lin}
               egin{tabular}{|rrrrrrrr|} hline
                  multicolumn{8}{|c|}{f Number of Observed Gnarls%
                     footnote{An exotic bug found in LaTeX documents}} \
                  hline
                  102  & 54 & 67 & 5 & 27 & 73 & 35 & 17 \
                  57footnote{Smith 1993: 1--3001}
                       & 38 & 40 &45 & 38 & 54 & 136 & 357 \
                  39   & 12 & 11 & 55 & 22 0 & 41 & 18 \ hline
                end{tabular} vspace{-.lin}
             end{center}
          end{minipage}
        end{center}
       end{table}
       

Several things should be noted about Table 5.5. First, the footnoterule{} statement turns off the rule usually placed above footnotes. Without this there would be two lines above the footnotes (the table frame and the footnote rule). Second, two nested centering environments are used, one to center the minipage and the other to center the table in the minipage. Third, two vspace adjustments are made above and below the table frame to position the caption and footnotes correctly. Finally, it is important to pick the width of the minipage correctly so as to have the correct horizontal placement of the footnotes.

To simplify the construction of a table in a minipage, place the following environment definition in the preamble.

     %--------- A Minipage Table Environment
      ewenvironment{mptbl}{egin{center}}{end{center}}
      ewenvironment{minipagetbl}[1]
       {egin{center}egin{minipage}{#1}
            enewcommand{footnoterule}{} egin{mptbl}}%
       {vspace{-.lin} end{mptbl} end{minipage} end{center}}

With this minipagetbl environment, Table 5.5 can be constructed more compactly as

     egin{table}[htbp]
      egin{minipagetbl}{2.65in}
        caption{A test table … }label{minitab} vspace{.lin}
         egin{tabular}{IrrrrrrrrI} hline
        
         end{tabular}
       end{minipagetbl}
     end{table}

5.3.5 Side-by-Side Tables

You can use two side-by-side minipage environments to place two tables side by side on the page. By placing both minipages in a table environment, the twin tables can be made into a single floating object. Here is an example.

Table 5.6: The discrete energies Ei (MeV) used to calculate the approximation

i   Ei

i   Ei

1   0.02

4   0.1

2   0.03

5   0.2

3   0.04

6   0.4

Table 5.7: Another set of data for Ei (MeV) used to calculate the approximation

i   Ei

i   Ei

1   0.05

4   1.0

2   0.08

5   2.0

3   0.12

6   5.0

These side-by-side tables were produced with the following

      egin{table}[htbp]
      egin{minipage}[t] {2.30in}
        centering
        parbox[t]{2.00in}{caption{The discrete energies $E_i$ (MeV) used to
                calculate the approximation}label{twinl}} \ vspace{.lin}
        egin{tabular}{|rc|rc|} hline
            $i$  K   $E_i$  K  $i$  K   $E_i$ \  hline
             1   K   0.02   K   4   K    0.1   \ 
             2   K   0.03   K   5   K    0.2   \
             3   K   0.04   K   6   K    0.4   \ hline
         end{tabular}
      end{minipage}
      hfill
      egin{minipage}[t]{2.30in}
         centering
         parbox[t]{2.00inHcaption{Another set of data for $E_i$ (MeV) used
              to calculate the approximation}label{twin2}}>\ vspace{.lin}
         egin{tabular}{|rc| |rc|} hline
            $i$  k  $E_i$  k  $i$  k  $E_i$   \  hline
             1   k  0.05   k   4   k   1.0    \
             2   k  0.08   k   5   k   2.0    \
             3   k  0.12   k   6   k   5.0    \ hline
         end{tabular}
      end{minipage}
      end{table}

5.3.6 Vertical Alignment of Column Entries

One way to align vertically the row entries in a table is to place each entry in a tabular environment. For example

First row

This is a row entry that extends over several lines so that it has a vertical length that is much longer that the first column’s entry.

This is a box of text that is only two lines deep.

Second row

This is yet another row entry that extends over several lines, and once again it has a vertical length that is much longer that the first column’s entry.

This is a box of text that is only two lines deep.

is produced by

Image

Image

5.3.7 Paragraphs in a Box

Sometimes you may want to place a box or frame around some text such as in this example. The trick is to put the text into a minipage (to justify the text) and then place the minipage into a one-column one-entry table (to create the box). With this approach you can even put equations like this into the box.

(5.1)

Image

To create boxed text like this, put the following macro in the document’s preamble.

Image

The boxed example above was then produced with

    egin{boxedtext} Sometimes you may want … end{boxedtext}

5.3.8 Controlling Spacing in Tables

Eventually, you will encounter a table that is just a bit too wide for the page. This most often occurs when trying to squeeze a table into a column of a two-column page. Two solutions are offered. First, simply decrease the size of the font used for the table (and hence the table size) by using

     egin{table}
          small %(or footonotesize or …)
          egin{tabular}
             . . .
          end{tabular}
     end{table}

The second, preferred solution is to decrease the intercolumn spacing used in the table. There are several format parameters (see Appendix B) that you can change with the enewcommand to alter the spacing in your tables.

In particular, the parameter arraystretch controls the line spacing between rows. The command { enewcommand{arraystretch}{l.5} will increase row spacing to 1.5 times the normal spacing. The horizontal space between table columns is 2 x abcolsep, which can also be changed with the enewcommand. The width between double vertical or horizontal rules can be changed to 0.1 inch by enewcommand{doublerulesep}{.lin}. The width of the rule itself is controlled by the parameter arrayrulewidth.

5.4 Image Macros

Michael Wichura has produced a set of macros called Image that provides a table environment whose many formatting features allow the construction of very complex tables. This macro set, contained in the a file called tables.tex, may be freely distributed; however, the 94-page manual with many examples and detailed instructions for using these macros must be purchased from Personal Image, Inc., 12 Madrona, Mill Valley, CA 94941. These macros allow a great deal of flexibility in formatting a table, and if you have many complex tables to produce, there is no better set of tools.

To use these macros, include input table in the preamble of your Image file to include these table macros. As with the tabular environment, tables can be created with a caption and a label so that they can be referenced in the text. Table 5.8, which resembles Table 5.4, is produced with

       egin{table}[htbp]
       centering
       parbox{3in}{caption{The discrete energies $E_i$ (MeV) used for
                    deriving the approximate line-beam response function}
                    label{tstl}}
       $$BeginTable
            defR{JustRight} defC{JustCenter}
            BeginFormat
           | n2 |   nl.2  | n2| n2.1 |
           EndFormat
           \_
           | i   " C $E_i$ | i  " R $E_i$ | \+44
           \_
           | 1  "  0.02  | 6  " 0.1  | \ + 40
           | 2  "  0.03  | 7  " 0.2  | \
           | 3  "  0.04  | 8  " 0.4  | \
           | 4  "  0.06  | 9  " 0.7  | \
           | 5  "  0.08  | 10 " 1.0  | \+04
           \_
        EndTable$$
        end{table}

Table 5.8: The discrete energies Ei (MeV) used for deriving the approximate line-beam response function

i   Ei

i   Ei

1   0.02

6   0.1

2   0.03

7   0.02

3   0.04

8   0.4

4   0.06

9   0.7

5   0.08

10   1.0

5.4.1 Using the Image Macros

To define a table with the Image macros use, the following structure:

                $$BeginTable
                   prologue section
                   format section
                   data section
                EndTable$$

The initial and final $$ are used to center the table between the left and right margins. Without them, the table is left justified on the page. The trick to using the Image macros is to master the many codes available for the three sections of the table. Following are some of the important commands and codes used; however, many features not presented in this summary are available and are described in the Image manual.

The Prologue Section

The prologue section is used (1) to define shorthand commands for use in the data section, and (2) to specify general spacing and size parameters for the table. Some examples follow.

Image

Format Section

The format section for an n column table has the form

              BeginFormat
                 | (keys1) | (keys2) | … | (keysn) |
              EndFormat

or, more compactly,

              BeginFormat   | (keys1) | (keys2) | … | (keysn) | .

where (keysi) denotes a (possibly empty) string of format keys, separated by optional blanks, that succinctly describe the layout of the ith column. The Image Macros macros have many format keys for specifying how the data entries are to be written and positioned in their columns. The following table describes some of the more important formatting keys used by Image.

Column Formatting Codes

Image

The Data Section

Part of the table definition specifies the contents of the table as well as how table lines are to be drawn. Image prefers to use single lines, although with effort double lines, dotted lines and the such can be created. A typical data line for a row in a 4-column table might look like this

     | $x_l$ " 3.2675 | $y_3$ " 1.234 imeslCr{-5} | \+2{-3}

Here the | and ″ are used to separate the data entries (I causes a vertical line to be drawn, and ″ omits such a line). If a I or ” is to be used as part of the entry for a particular column use the special macros VBar and DQuote.

Each table row is terminated by a \. If the spacing above and below the row is to be altered from the default, the \ can be followed by +/id to add h and d strut units (points) to the height and depth of the normal strut. Here h and d are positive or negative integers or zero, and the parentheses can be omitted if the number is a single unsigned digit. To prevent any strut at all from being used for a table row, use \0.

To draw a horizontal line across the table simply place \_ between the two table rows where the line is wanted.

Listed on the next page are some commands frequently used in the data section. These commands are used in defining the data entries (that is, those quantitites placed between I or ″ symbols.

Useful Commands for the Data Section

Image

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.160.216