summaryrefslogtreecommitdiff
path: root/Master/texmf-doc/doc/english/latex2e-html/ltx-68.html
blob: 3926aafd6530b82623b1c08c90e4f01a18f9ff85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<html>
<head><title>Help On LaTeX tabular</title></head>
<body bgcolor="#ffffff" text="#000000" link="#000099" vlink="#cc0000" alink="#cc0000">
<h1><font size="-2">Hypertext Help with LaTeX</font><br><font color="#cc0000">tabular</font></h1>
<pre>
 \begin{tabular}[pos]{cols}
 column 1 entry & column 2 entry ... & column n entry \\
 ...
 ...
 \end{tabular}
</pre>

or

<pre>
 \begin{tabular*}{width}[pos]{cols}
 column 1 entry & column 2 entry ... & column n entry \\
 ...
 ...
 \end{tabular*}
</pre>
Note that the *-form takes an additional <tt>width</tt> mandatory argument
which specifies the width of the tabular environment; in the regular form
the width is determined by LaTeX from the contents of the tabular environment.
<p>
 These environments  produce a box consisting  of a sequence of rows of
 items,  aligned  vertically  in columns.   The mandatory  and optional
 arguments consist of:
<ul>
  <li><TT>cols</TT>  Specifies  the  column  formatting.   It  consists  of  a
     sequence  of  the  following  specifiers, at least one for each 
    of the columns.
  <ul>
    <li><tt>l</tt> - A column of left-aligned items.
    <li><tt>r</tt> - A column of right-aligned items.
    <li><tt>c</tt> - A column of centered items.
  <li><tt>p{wd}</tt> - Produces a column which can be multiple lines, 
         with each item typeset in a  parbox
         of  width  wd. It works  as if each item were the argument of a 
         <a href="ltx-294.html"><tt>\parbox[t]{wd}</tt></a>
         command.  However, a 
         <a href="ltx-181.html"><tt>\\</tt></a>
         may not appear in the item, except in
         the  following  situations:   (i)  inside an environment like
         minipage, array, or tabular, (ii) inside an explicit <tt>\parbox,</tt>
         or  (iii)  in  the  scope  of  a 
         <a href="ltx-30.html"><tt>\centering</tt></a>, 
         <a href="ltx-300.html"><tt>\raggedleft</tt></a>, or
         <a href="ltx-301.html"><tt>\raggedright</tt></a> 
         declaration.  The latter declarations must appear
         inside  braces  or  an  environment  when  used in a <tt>p</tt>-column
         element.
<p>
    <li><tt>|</tt> - A  vertical  line  the  full  height  and  depth  of  the
         environment.
    <li><tt>@{text}</tt> - This inserts <tt>text</tt> in every  row.
         An  @-expression
         suppresses  the  intercolumn  space normally inserted between
         columns; any desired space between the inserted text and  the
         adjacent items must be included in <tt>text</tt>.
         To force the spacing between two columns to be <tt>wdth</tt>, 
         use an <tt>@{\hspace{wdth}}</tt> between the column specifiers.
         An <tt>\extracolsep{wd}</tt>
         command in an @-expression causes an extra space of width <tt>wd</tt>
         to  appear  to  the  left  of  all  subsequent columns, until
         countermanded  by  another  <tt>\extracolsep</tt>   command.    Unlike
         ordinary   intercolumn   space,   this  extra  space  is  not
         suppressed by an @-expression.  An <tt>\extracolsep</tt>  command  can
         be used only in an @-expression in the <tt>cols</tt> argument.
  <li><tt>*{num}{cols}</tt> - Equivalent to num copies of cols, where num is
         any    positive   integer   and   cols   is   any   list   of
         column-specifiers, which may contain another *-expression.
  </ul>
<p>
  <li><TT>pos</TT> Specifies the  vertical position of the whole tabular
 environment (recall that it is a <a href="ltx-143.html">box</a>). 
 The  default is to align the box on the center of the environment.
  <ul>
    <li><tt>t</tt> - align on top row
    <li><tt>b</tt> - align on bottom row
  </ul>
<p>
  <li><TT>width</TT> Specifies the width of the tabular*  environment.   There
     must be rubber space between columns that can stretch to fill out
     the specified width.
</ul>

 Note that <a href="ltx-181.html"><tt>\\</tt></a>
 must be used to specify the end of each line of the table, except the last.
 (It must be used after the last line if an 
 <a href="ltx-239.html"><tt>\hline</tt></a> command is used to put a line
 at the bottom of the table.)  

<h2>Aligning on decimal points: an example of the @ specifier</h2>
In scientific tables it is often desirable to align the columns on a decimal
point.  This can be done using the <tt>@</tt> <tt>col</tt> specifier and 
breaking the number into the integral part in a right-justified column and
the fractional part in a left-justified column:
<pre>
  The following input:          will display as:

  <tt>\begin{tabular}{r@{.}l}
  3&14159\\                         3.14159
  16&2\\                           16.2
  123$456\\ \end{tabular}         123.456  </tt>
</pre>
Note that the decimal point is replaced by the column separator, <tt>&amp;</tt>
and that the <tt>@</tt>suppresses the intercolumn space

<h2>Another example: centering and controlling table width</h2>
LaTeX normally sets the width of the tabular environment to "natural" 
width, i.e., determined from the contents of the columns.  For narrow 
tables it is sometimes more pleasing to make them wider.  The 
<tt>tabular*</tt> environments allows for setting a width; however, it
is necessary to have rubber space between colunmns that can expand to the
specified width.  This can often be most easily accomplished by using
an <tt>\extracolsep{wdth}</tt> command in an @ specifier as shown in the
example below which sets the table width to 75% of the text width.  
<p>
This example also centers the table.
<pre>
  <tt><a href="ltx-29.html">\begin{center}</a>  % put inside center environment
  \begin{tabular*}{0.75<a href="textwidth.html">\textwidth</a>}%
     {@{\extracolsep{<a href="ltx-238.html">\fill</a>}}cccr}
  label 1 &amp; label 2 &amp; label 3 &amp; label 4 \\
  <a href="ltx-239.html">\hline</a>  % put a line under headers
  item 1  &amp; item 2  &amp; item 3  &amp; item 4  \\
  ...
  \end{tabular*}
  \end{center}</tt>
</pre>
<H2>See also</H2>
<ul>
<li><A href="ltx-214.html">\cline</A>
<li><A href="ltx-239.html">\hline</A>
<li><A href="ltx-268.html">\multicolumn</A>
<li><A href="ltx-346.html">\vline</A>
</ul>
<hr>
See also <a href="ltx-67.html">table environment</a>,
  <a href="ltx-202.html">array environment</a>,
  <a href="ltx-58.html">tabbing environment</a>.<br>
Return to <a href="ltx-2.html">LaTeX Table of Contents</a>
<hr>
<address>
Revised: Sheldon Green, 22 Jun 1995.
</address>
</body>
</html>