ma-cb-en-tables.tex /size: 11 Kb    last modification: 2020-07-01 14:35
1\startcomponent ma-cb-en-tables
2
3% AFO: the \start ... \stoplinetable mechanism is not stable enough
4
5\enablemode[**en-us]
6
7\project ma-cb
8
9\startchapter[reference=tables,title=Tables]
10
11\index{tables}
12\index{natural tables}
13\index{extreme tables}
14\index{floating blocks}
15
16\Command{\tex{placetable}}
17\Command{\tex{setuptables}}
18\Command{\tex{starttable}}
19\Command{\tex{startcombination}}
20\Command{\tex{setupfloats}}
21\Command{\tex{setupcaptions}}
22\Command{\tex{NR}}
23\Command{\tex{FR}}
24\Command{\tex{LR}}
25\Command{\tex{MR}}
26\Command{\tex{SR}}
27\Command{\tex{VL}}
28\Command{\tex{NC}}
29\Command{\tex{HL}}
30\Command{\tex{DL}}
31\Command{\tex{DC}}
32\Command{\tex{DR}}
33\Command{\tex{LOW}}
34\Command{\tex{TWO}}
35\Command{\tex{THREE}}
36\Command{\tex{bTABLE}}
37\Command{\tex{eTABLE}}
38\Command{\tex{bTR}}
39\Command{\tex{eTR}}
40\Command{\tex{bTD}}
41\Command{\tex{eTD}}
42\Command{\tex{setupTABLE}}
43\Command{\tex{startxtable}}
44\Command{\tex{stopxtable}}
45\Command{\tex{startxcell}}
46\Command{\tex{startxrow}}
47\Command{\tex{setupxtable}}
48
49There are a number of ways to define a table:
50
51\startitemize[packed]
52\item the \type{\start ... \stoptable} mechanism, based on the work of M. Wichura
53\item the \type{\bTABLE ... \eTABLE} mechanism (natural tables)
54\item the \type{\start ... \stopxtable} mechanism (extreme tables)
55\stopitemize
56
57In the next sections we describe the principles of the three table mechanisms.
58
59\startsection[title=Simple tables]
60
61For defining the table you use:
62
63\shortsetup{starttable}
64
65The definition of a table could look something like this:
66
67\startbuffer
68\placetable
69  [here]
70  [tab:ships]
71  {Ships that moored at Hasselt.}
72  {\starttable[|c|c|]
73  \HL
74  \NC \bf Year \NC \bf Number of ships \NC\SR
75  \HL
76  \NC 1645     \NC 450                 \NC\FR
77  \NC 1671     \NC 480                 \NC\MR
78  \NC 1676     \NC 500                 \NC\MR
79  \NC 1695     \NC 930                 \NC\LR
80  \HL
81  \stoptable}
82\stopbuffer
83
84\typebuffer
85
86This table is typeset as \in{table}[tab:ships].
87
88\getbuffer
89
90Although this table mechanism is still available and supported in \CONTEXT\
91it is better to use one of the other mechanisms.
92
93\stopsection
94
95\startsection[title=Natural tables]
96
97The natural table mechanism (\type{\bTABLE ... \eTABLE}) is developed for more
98complex tables and has features of the general interface of \CONTEXT.
99
100\startbuffer
101\placetable
102  [here,force]
103  [tab:votedivision]
104  {Division of votes over political parties.}
105  {\bTABLE[align=middle,offset=4pt]
106   \bTABLEhead
107     \bTR[width=6cm] \bTD [nc=5] Elections City Council \eTD      \eTR
108   \eTABLEhead
109   \bTABLEbody
110     \bTR \bTD[nr=2,align={right,lohi}] Party \eTD
111          \bTD[nc=3,foregroundstyle=bold] Districts \eTD
112          \bTD[nr=2,align={middle,lohi}] Total \eTD                \eTR
113     \bTR \bTD 1   \eTD \bTD 2   \eTD \bTD 3   \eTD                \eTR
114     \bTR \bTD[align=right] PvdA \eTD
115          \bTD 351 \eTD \bTD 433 \eTD \bTD 459 \eTD \bTD 1243 \eTD \eTR
116     \bTR \bTD[align=right] CDA  \eTD
117          \bTD 346 \eTD \bTD 350 \eTD \bTD 285 \eTD \bTD ~981 \eTD \eTR
118     \bTR \bTD[align=right] VVD  \eTD
119          \bTD 140 \eTD
120          \bTD[offset=2pt,background=color,
121               backgroundcolor=red,foregroundcolor=white,
122               foregroundstyle=bold,framecolor=blue,
123               rulethickness=2pt] 113 \eTD
124          \bTD 132 \eTD \bTD ~385 \eTD                             \eTR
125     \bTR \bTD[align=right] SGP  \eTD
126          \bTD 348 \eTD \bTD 261 \eTD \bTD 158 \eTD \bTD ~767 \eTD \eTR
127     \bTR \bTD[align=right] GPV  \eTD
128          \bTD 117 \eTD \bTD 192 \eTD \bTD 291 \eTD \bTD ~600 \eTD \eTR
129  \eTABLEbody
130  \eTABLE}
131\stopbuffer
132
133\start
134\switchtobodyfont[8pt]
135\typebuffer
136\stop
137
138In the last column a \type{~} is used to simulate a four digit number. The
139\type{~} has the width of a digit.
140
141\start
142\getbuffer
143\stop
144
145The setup of the table is placed between the square brackets \type{[ ]}. To keep
146the data in the table more readable you can set up the table with the \type
147{\setupTABLE} command.
148
149\shortsetup{bTABLE}
150
151\startbuffer
152\setupTABLE[row][align=middle,offset=4pt]
153\setupTABLE[1][1][width=6cm]
154\setupTABLE[1][2][align={right,lohi}]
155\setupTABLE[5][2][align={right,lohi}]
156\setupTABLE[2][2][foregroundstyle=bold]
157\setupTABLE[1][4,5,6,7,8][align=right]
158\setupTABLE[3][6][offset=2pt,background=color,
159                  backgroundcolor=red,foregroundcolor=white,
160                  foregroundstyle=bold,framecolor=blue,
161                  rulethickness=2pt]
162
163\bTABLE
164  \bTABLEhead
165    \bTR \bTD[nc=5] Elections City Council \eTD                                  \eTR
166    \bTR \bTD[nr=2] Party  \eTD  \bTD[nc=3] Districts \eTD \bTD[nr=2] Total \eTD \eTR
167    \bTR                         \bTD 1   \eTD \bTD 2 \eTD \bTD 3 \eTD           \eTR
168  \eTABLEhead
169  \bTABLEbody
170    \bTR \bTD PvdA \eTD \bTD 351 \eTD \bTD 433 \eTD \bTD 459 \eTD \bTD 1243 \eTD \eTR
171    \bTR \bTD CDA  \eTD \bTD 346 \eTD \bTD 350 \eTD \bTD 285 \eTD \bTD ~981 \eTD \eTR
172    \bTR \bTD VVD  \eTD \bTD 140 \eTD \bTD 113 \eTD \bTD 132 \eTD \bTD ~385 \eTD \eTR
173    \bTR \bTD SGP  \eTD \bTD 348 \eTD \bTD 261 \eTD \bTD 158 \eTD \bTD ~767 \eTD \eTR
174    \bTR \bTD GPV  \eTD \bTD 117 \eTD \bTD 192 \eTD \bTD 291 \eTD \bTD ~600 \eTD \eTR
175  \eTABLEbody
176\eTABLE
177\stopbuffer
178
179\start
180\switchtobodyfont[8pt]
181\typebuffer
182\stop
183
184The meaning of the \CONTEXT\ commands are indicated in \in {table}
185[tab:tablecommands02].
186
187\placetable
188  []
189  [tab:tablecommands02]
190  {Commands to define natural tables.}
191  {\starttable[|l|l|]
192  \HL
193  \NC \bf Command \NC \bf Meaning  \NC\SR
194  \HL
195  \NC \type{\bTABLE ... \eTABLE}         \NC begin end table     \NC\FR
196  \NC \type{\bTR ... \eTR}               \NC begin end row       \NC\MR
197  \NC \type{\bTD ... \eTD}               \NC begin end column    \NC\MR
198  \NC \type{\bTABLEhead ... \eTABLEhead} \NC begin end tablehead \NC\MR
199  \NC \type{\bTABLEbody ... \eTABLEbody} \NC begin end tablebody \NC\MR
200  \NC \type{\bTABLEfoot ...\eTABLEfoot}  \NC begin end tablefoot \NC\MR
201  \NC \type{\setupTABLE}                 \NC table setup         \NC\LR
202  \HL
203  \stoptable}
204
205You can find more information on this table mechanism on the \CONTEXTWIKI\ and
206examples in the \goto {\em Natural Tables} [ url (manual:nattab) ] manual.
207
208\stopsection
209
210\startsection[title=Extreme tables]
211
212For large tables that extend over a number of pages and where you want the
213table head repeated after each pagebreak \CONTEXT\ has the {\em extreme table}
214mechanism.
215
216\shortsetup{startxtable}
217
218\startbuffer
219\setupxtable[split=yes,header=repeat]
220\setupxtable[offset=4pt]
221
222\placetable
223  []
224  [tab:wealthdecline]
225  {Decline of wealth through the ages.}
226  {\startxtable
227    \startxtablehead[align=middle,foregroundstyle=bold]
228      \startxrow
229        \startxcell[nx=6]
230            Decline of wealth in Dutch florine (Dfl)
231        \stopxcell
232      \stopxrow
233      \startxrow[foregroundstyle=bold]
234        \startxcell[width=1.2cm] Year \stopxcell
235        \startxcell 1.000--2.000      \stopxcell
236        \startxcell 2.000--3.000      \stopxcell
237        \startxcell 3.000--5.000      \stopxcell
238        \startxcell 5.000--10.000     \stopxcell
239        \startxcell   over 10.000     \stopxcell
240      \stopxrow
241    \stopxtablehead
242    \startxtablenext
243        \startxrow
244          \startxcell[nx=6,align=middle,foregroundstyle=bold]
245              Decline of wealth in Dutch florine (Dfl) / Continued
246          \stopxcell
247        \stopxrow
248        \startxrow[foregroundstyle=bold]
249          \startxcell Year          \stopxcell
250          \startxcell 1.000--2.000  \stopxcell
251          \startxcell 2.000--3.000  \stopxcell
252          \startxcell 3.000--5.000  \stopxcell
253          \startxcell 5.000--10.000 \stopxcell
254          \startxcell   over 10.000 \stopxcell
255        \stopxrow
256    \stopxtablenext
257    \startxtablebody[align=middle]
258      \startxrow
259        \startxcell 1675 \stopxcell
260        \startxcell 22   \stopxcell
261        \startxcell ~7   \stopxcell
262        \startxcell ~5   \stopxcell
263        \startxcell ~4   \stopxcell
264        \startxcell ~5   \stopxcell
265      \stopxrow
266      \startxrow
267        \startxcell 1724 \stopxcell
268        \startxcell ~4   \stopxcell
269        \startxcell ~4   \stopxcell
270        \startxcell --   \stopxcell
271        \startxcell ~4   \stopxcell
272        \startxcell ~3   \stopxcell
273      \stopxrow
274      \startxrow
275        \startxcell 1750 \stopxcell
276        \startxcell 12   \stopxcell
277        \startxcell ~3   \stopxcell
278        \startxcell ~2   \stopxcell
279        \startxcell ~2   \stopxcell
280        \startxcell --   \stopxcell
281      \stopxrow
282      \startxrow
283        \startxcell 1808 \stopxcell
284        \startxcell ~9   \stopxcell
285        \startxcell ~2   \stopxcell
286        \startxcell --   \stopxcell
287        \startxcell --   \stopxcell
288        \startxcell --   \stopxcell
289      \stopxrow
290    \stopxtablebody
291  \stopxtable}
292\stopbuffer
293
294\start
295\switchtobodyfont[8pt]
296\typebuffer
297\stop
298
299With the \type{\setupxtable} it is indicated that the table is allowed to split
300at a pagebreak and that the head should contain the content of the \type {\start
301... \stopxtablenext}.
302
303The result of this definition is shown in \in {table} [tab:wealthdecline].
304
305\getbuffer
306
307The meaning of the commands are explained \in {table} [tab:tablecommands03].
308
309\placetable
310  []
311  [tab:tablecommands03]
312  {Commands to define extreme tables.}
313  {\starttable[|l|l|]
314  \HL
315  \NC \bf Command \NC \bf Meaning                                         \NC\SR
316  \HL
317  \NC \type{\startxtable ... \stopxtable}         \NC begin end table     \NC\FR
318  \NC \type{\startxrow ... \stopxrow}             \NC begin end row       \NC\MR
319  \NC \type{\startxcell ... \stopxcell}           \NC begin end column    \NC\MR
320  \NC \type{\startxtablehead ... \stopxtablehead} \NC begin end tablehead \NC\MR
321  \NC \type{\startxtablebody ... \stopxtablebody} \NC begin end tablebody \NC\MR
322  \NC \type{\startxtablefoot ... \stopxtablefoot} \NC begin end tablefoot \NC\MR
323  \NC \type{\setupxtable}                         \NC table setup         \NC\LR
324  \HL
325  \stoptable}
326
327More information and examples can be found in the \goto {\em Extreme Tables} [
328url (manual:extab) ] manual.
329
330\stopsection
331
332\startsection[title=Placing tables]
333
334In all examples you see the command \type{\placetable}. This command has
335the same function as \type{placefigure}. It takes care of the vertical
336spacing and numbering. The float mechanism is invoked and the table will
337end up on the most optimal location in your document.
338
339\shortsetup{placefloat}
340
341You can also set up the layout of tables with:
342
343\shortsetup{setupfloats}
344
345You can set up the numbering and the labels with:
346
347\shortsetup{setupcaptions}
348
349These commands are typed in the set up area of your input file and have a global
350effect on all floating blocks.
351
352\startbuffer
353\setupfloats[location=left]
354\setupcaptions[style=boldslanted,location={right,middle}]
355
356\placetable[here][tab:opening hours]{Library opening hours.}
357  {\bTABLE[offset=4pt]
358  \bTR \bTD \bf Day   \eTD \bTD[nx=2,align=middle] \bf Opening hours    \eTD \eTR
359  \bTR \bTD Monday    \eTD \bTD 14.00 -- 17.30 \eTD \bTD 18.30 -- 20.30 \eTD \eTR
360  \bTR \bTD Tuesday   \eTD \bTD                \eTD \bTD                \eTD \eTR
361  \bTR \bTD Wednesday \eTD \bTD 10.00 -- 12.00 \eTD \bTD 14.00 -- 17.30 \eTD \eTR
362  \bTR \bTD Thursday  \eTD \bTD 14.00 -- 17.30 \eTD \bTD 18.30 -- 20.30 \eTD \eTR
363  \bTR \bTD Friday    \eTD \bTD 14.00 -- 17.30 \eTD \bTD                \eTD \eTR
364  \bTR \bTD Saturday  \eTD \bTD 10.00 -- 12.30 \eTD \bTD                \eTD \eTR
365  \eTABLE}
366\stopbuffer
367
368\start
369\switchtobodyfont[8pt]
370\typebuffer
371\stop
372
373The result is displayed in \in{table}[tab:opening hours].
374
375\start
376\getbuffer
377\stop
378
379\stopsection
380
381% AFO: the \start ... \stoplinetable mechanism is not stable enough
382
383\stopchapter
384
385\stopcomponent
386