-
Notifications
You must be signed in to change notification settings - Fork 0
/
LatexHowTo_10_Tabular.tex
607 lines (555 loc) · 19.2 KB
/
LatexHowTo_10_Tabular.tex
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
\section{Tabular}
\subsection{Tabbing}
\begin{tabbing}
Form\hspace{3em} \= Author \\
Plain \TeX \> Donald Ervin Knuth \\
\LaTeX \> Leslie Lamport
\end{tabbing}
\subsection{Tabular And Array}
\subsubsection{Overview}
\begin{tabular}[b]{l|cr|p{8em}} % optional b for bottom, t for rop, no by default center
left & center & right & fixed width \\
\hline
raggedright & centering & raggedleft & \centering This can automatically line break if it is longer than the fixed width \\
\end{tabular}
Ragged bottom.
Almost the same as tabular, not repeat.
\[
\begin{array}{l|cr}
\frac{1}{2} & 1 & 0 \\
\hline
0 & 1 & -\frac{1}{2} \\
\end{array}
\]
\begin{tabular}{|c|*{3}{r@{.}l|}}
\hline
input & 12345&6 & 5000&0 & 1020&55 \\ \hline
output & 765&43 & 5120&5 & 98760&0 \\ \hline
net & 11580&17 & -120&5 & -97739&45 \\ \hline
\end{tabular}
\begin{tabular}{|c|*{3}{d|}} % must usepackage dcolumn
\hline
name & \multicolumn{1}{c|}{wjb} & \multicolumn{1}{c|}{dadadadawjb} & \multicolumn{1}{c|}{Wang Junbo} \\ \hline
input & 12345.6 & 5000 & 1020.55 \\ \hline
output & 765.43 & 5120.5 & 98760 \\ \hline
net & 11580.17 & -120.5 & -97739.45 \\ \hline
\end{tabular}
The left
\begin{tabular}{@{}c}
Hello \\
World
\end{tabular}
The right
\begin{tabular}{|c|@{\extracolsep{1em}}c|c|c|}
\hline
1 & 2 & 3 & 4 \\
\hline
\end{tabular}
\begin{tabular}[t]{|c|}
\hline
up \\ mid \\ down \\
\hline
\end{tabular}
Ragged top
\begin{tabular}[t]{|c|} % must usepackage array
\firsthline
up \\ mid \\ down \\
\lasthline
\end{tabular}
Ragged top
\subsubsection{Item Merge And Split}
Used for the horizontal merge:
\begin{tabular}{|r|r|}
\hline
\multicolumn{2}{|c|}{grades} \\ \hline
OS & CA \\ \hline
95 & 100 \\ \hline
\end{tabular}
Used for changing the ragging:
\begin{tabular}{|r|r|}
\hline
\multicolumn{1}{|c|}{input} & \multicolumn{1}{c|}{output} \\ \hline
1 & 1 \\ \hline
2 & 4 \\ \hline
3 & 9 \\ \hline
\end{tabular}
Used for the vertical merge:
\begin{tabular}{|c|r|r|}
\hline
& \multicolumn{2}{c|}{grades} \\ \cline{2-3}
name & OS & CA \\ \hline
wjb & 95 & 100 \\ \hline
\end{tabular}
\begin{tabular}{|c|r|r|} % must usepackage multirow
\hline
\multirow{2}*{name} & \multicolumn{2}{c|}{grades} \\ \cline{2-3}
& OS & CA \\ \hline
wjb & 95 & 100 \\ \hline
\end{tabular}
Used for the horizontal split:
\begin{tabular}{|c|}
\hline
1 \\ \hline
1 \vline\ 2 \\ \hline
1 \vline\ 2 \vline\ 3 \\ \hline
\end{tabular}
\begin{tabular}{|c|}
\hline
1 \\ \hline
\begin{tabular}{@{}c|c@{}} 1 & 2 \end{tabular} \\ \hline
\begin{tabular}{@{}c|c|c@{}} 1 & 2 & 3 \end{tabular} \\ \hline
\end{tabular}
Make item cell:
% must usepackage makecell
\begin{tabular}{|r|r|}
\hline
\makecell[c]{input\\data} & \makecell[c]{output\\data} \\ \hline
12345 & 56789 \\ \hline
\end{tabular}
\begin{tabular}{|r|r|}
\hline
\thead[c]{input\\data} & \thead[c]{output\\data} \\ \hline
12345 & 56789 \\ \hline
\end{tabular}
\settowidth\rotheadsize{\theadfont Mathematica} % set the width of the head rotated
\begin{tabular}{|c|c|}
\hline
\thead[c]{name} & \rothead{math\\grade} \\ \hline
wjb & 100 \\ \hline
\end{tabular}
\begin{tabular}{|c|r|}
% must usepackage multirow and makecell
\hline
\multirowcell{3}{multiple\\grades} & 100 \\ \cline{2-2}
& 99 \\ \cline{2-2}
& 98 \\ \hline
\end{tabular}
Diagnal split:
% must usepackage diagbox
\begin{tabular}{|c|ccc|}
\hline
\diagbox{row}{value}{column} & c1 & c2 & c3 \\ \hline
r1 & 1 & 0 & 0 \\
r2 & 0 & 1 & 0 \\
r3 & 0 & 0 & 1 \\ \hline
\end{tabular}
\subsubsection{Width}
\begin{tabular*}{\textwidth}{|c@{\extracolsep{\fill}}ccccc|}
\hline
number & 1 & 2 & 3 & 4 & 5 \\
character & A & B & C & D & E \\
\hline
\end{tabular*}
\begin{tabularx}{\textwidth}{|c|X|X|X|X|X|} % must usepackage tabularx
\hline
number & 1 & 2 & 3 & 4 & 5 \\ \hline
character & A & B & C & D & E \\ \hline
\end{tabularx} % by default ragged right
\begin{tabularx}{\textwidth}{|c|Y|Y|Y|Y|Y|}
\hline
number & 1 & 2 & 3 & 4 & 5 \\ \hline
character & A & B & C & D & E \\ \hline
\end{tabularx}
We can not deal with the too wide tabular.
\subsubsection{Length}
\begin{longtable}[c]{|c|c|} % must usepackage longtable
\caption{The Example Of Longtable} \\
\hline
\endfirsthead
\multicolumn{2}{l}{ (Continued) } \\
\hline
\endhead
\multicolumn{2}{c}{Continuing next page\ldots} \\[2ex]
\endfoot
\hline
\multicolumn{2}{r}{End Of Table} \\
\endlastfoot
name & description \\ \hline
a & the fist character in alphabet \\
b & the second character in alphabet \\
c & the third character in alphabet \\
d & the fourth character in alphabet \\
e & the fifth character in alphabet \\
f & the sixth character in alphabet \\
g & the seventh character in alphabet \\
h & the eighth character in alphabet \\
i & the ninth character in alphabet \\
j & the tenth character in alphabet \\
k & the eleventh character in alphabet \\
l & the twelfth character in alphabet \\
m & the thirdth character in alphabet \\
n & the fourteenth character in alphabet \\
o & the fifteenth character in alphabet \\
p & the sixteenth character in alphabet \\
q & the seventeenth character in alphabet \\
r & the eighteenth character in alphabet \\
s & the nineteenth character in alphabet \\
t & the twentieth character in alphabet \\
u & the twenty first character in alphabet \\
v & the twenty second character in alphabet \\
w & the twenty third character in alphabet \\
x & the twenty fourth character in alphabet \\
y & the twenty fifth character in alphabet \\
z & the twenty sixth character in alphabet \\
\end{longtable}
\LTXtable{\textwidth}{LTXTable.tex} % must usepackage ltxtable
\begin{VerbatimOut}{LTXTable.vrb}
\begin{longtable}{|X|X|}
\caption{The Example Of LTXTable With Fancyvrb} \\
\hline
\endfirsthead
\multicolumn{2}{l}{ (Continued) } \\
\hline
\endhead
\multicolumn{2}{c}{Continuing next page\ldots} \\[2ex]
\endfoot
\hline
\multicolumn{2}{r}{End Of Table} \\
\endlastfoot
Name & Description \\ \hline
A & The 1st character in alphabet \\
B & The 2nd character in alphabet \\
C & The 3rd character in alphabet \\
D & The 4th character in alphabet \\
E & The 5th character in alphabet \\
F & The 6th character in alphabet \\
G & The 7th character in alphabet \\
H & The 8th character in alphabet \\
I & The 9th character in alphabet \\
J & The 10th character in alphabet \\
K & The 11th character in alphabet \\
L & The 12th character in alphabet \\
M & The 13th character in alphabet \\
N & The 14th character in alphabet \\
O & The 15th character in alphabet \\
P & The 16th character in alphabet \\
Q & The 17th character in alphabet \\
R & The 18th character in alphabet \\
S & The 19th character in alphabet \\
T & The 20th character in alphabet \\
U & The 21st character in alphabet \\
V & The 22nd character in alphabet \\
W & The 23rd character in alphabet \\
X & The 24th character in alphabet \\
Y & The 25th character in alphabet \\
Z & The 26th character in alphabet \\
\end{longtable}
\end{VerbatimOut}
\LTXtable{\textwidth}{LTXTable.vrb} % must usepackage ltxtable and fancyvrb
\begin{longtabu} to \textwidth {|X|X|} % must usepackage tabu and longtable
\caption{The Example Of Longtabu} \\
\hline
\endfirsthead
\multicolumn{2}{l}{ (Continued) } \\
\hline
\endhead
\multicolumn{2}{c}{Continuing next page\ldots} \\[2ex]
\endfoot
\hline
\multicolumn{2}{r}{End Of Table} \\
\endlastfoot
Name & Description \\ \hline
a & The 1st character in alphabet \\
b & The 2nd character in alphabet \\
c & The 3rd character in alphabet \\
d & The 4th character in alphabet \\
e & The 5th character in alphabet \\
f & The 6th character in alphabet \\
g & The 7th character in alphabet \\
h & The 8th character in alphabet \\
i & The 9th character in alphabet \\
j & The 10th character in alphabet \\
k & The 11th character in alphabet \\
l & The 12th character in alphabet \\
m & The 13th character in alphabet \\
n & The 14th character in alphabet \\
o & The 15th character in alphabet \\
p & The 16th character in alphabet \\
q & The 17th character in alphabet \\
r & The 18th character in alphabet \\
s & The 19th character in alphabet \\
t & The 20th character in alphabet \\
u & The 21st character in alphabet \\
v & The 22nd character in alphabet \\
w & The 23rd character in alphabet \\
x & The 24th character in alphabet \\
y & The 25th character in alphabet \\
z & The 26th character in alphabet \\
\end{longtabu}
\begin{center}
\tablecaption{The Example Of Xtab}
\tablefirsthead{\hline}
\tablehead{\multicolumn{2}{l}{ (Continued) } \\ \hline}
\tabletail{\multicolumn{2}{c}{Continuing next page\ldots} \\[2ex]}
\tablelasttail{\hline \multicolumn{2}{r}{End Of Table} \\}
\begin{xtabular}{|c|c|} % must usepackage xtab, if `*` then fix width like tabular*
name & description \\ \hline
a & The 1st character in alphabet \\
b & The 2nd character in alphabet \\
c & The 3rd character in alphabet \\
d & The 4th character in alphabet \\
e & The 5th character in alphabet \\
f & The 6th character in alphabet \\
g & The 7th character in alphabet \\
h & The 8th character in alphabet \\
i & The 9th character in alphabet \\
j & The 10th character in alphabet \\
k & The 11th character in alphabet \\
l & The 12th character in alphabet \\
m & The 13th character in alphabet \\
n & The 14th character in alphabet \\
o & The 15th character in alphabet \\
p & The 16th character in alphabet \\
q & The 17th character in alphabet \\
r & The 18th character in alphabet \\
s & The 19th character in alphabet \\
t & The 20th character in alphabet \\
u & The 21st character in alphabet \\
v & The 22nd character in alphabet \\
w & The 23rd character in alphabet \\
x & The 24th character in alphabet \\
y & The 25th character in alphabet \\
z & The 26th character in alphabet \\
\end{xtabular}
\end{center}
\subsubsection{Thickness}
\begin{tabular}{*{6}{c}} % must usepackage booktabs
\toprule
\multirow{2}*{Name} & \multicolumn{2}{c}{CS} & \multicolumn{2}{c}{SE} & \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule{6-6}\morecmidrules\cmidrule{6-6}
& OS & CA & SEP & CSE & All \\
\midrule
wjb & 100 & 100 & 100 & 100 & A+ \\
dadadadawjb & 99 & 99 & 99 & 99 & A+ \\
Wang Junbo & 98 & 98 & 98 & 98 & A+ \\
\bottomrule
\end{tabular}
\begin{tabular}{c|cc} % must usepackage makecell
\Xhline{2pt}
input & \multicolumn{2}{c}{output} \\
\Xcline{2-3}{0.4pt}
x & y & z \\
\Xhline{1pt}
1 & 1 & 1 \\
2 & 4 & 8 \\
\Xhline{2pt}
\end{tabular}
\begin{tabular}{vc|ccv} % must usepackage array, bug exists
\hline
input & \multicolumn{2}{cv}{output} \\
\cline{2-3}
x & y & z \\
\hline
1 & 1 & 1 \\
2 & 4 & 8 \\
\hline
\end{tabular}
\subsubsection{Double Lines}
Should omit double lines in tabular
\begin{tabular}{|c||cc|}
\hline\hline
input & \multicolumn{2}{c|}{output} \\
\cline{2-3}
x & y & z \\
\hline\hline
1 & 1 & 1 \\
2 & 4 & 8 \\
\hline\hline
\end{tabular}
\begin{tabular}{|c||cc|} % must usepackage hhline
\hhline{|=:t:==|}
x & y & z \\
\hhline{|=::==|}
1 & 1 & 1 \\
2 & 4 & 8 \\
\hhline{|=:b:==|}
\end{tabular}
\subsubsection{Dash Line}
% conflict with hhline and makecell
% \begin{tabular}{:c:cc:} % must usepackage arydshln and array
% \firsthdashline
% input & \multicolumn{2}{c:}{output} \\
% \cdashline{2-3}
% x & y & z \\
% \hdashline
% 1 & 1 & 1 \\
% 2 & 4 & 8 \\
% \lasthdashline
% \end{tabular}
% \begin{tabular}{;{8pt/2pt}c;{2pt/2pt}cc;{8pt/2pt}} % must usepackage arydshln and array
% \firsthdashline
% input & \multicolumn{2}{c;{8pt/2pt}}{output} \\
% \cdashline{2-3}[2pt/2pt]
% x & y & z \\
% \hdashline[8pt/2pt]
% 1 & 1 & 1 \\
% 2 & 4 & 8 \\
% \lasthdashline
% \end{tabular}
\subsection{Float Table}
\subsubsection{Overview}
\begin{table}[!htbp]
\centering
\bicaption[Tabular In Table]{\label{tab-float} Tabular In Table - Example Of Float Table}[浮动表格]{浮动表格的例子}
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}
\end{table}
\subsubsection{Rotated Table}
% must usepackage rotfloat
\begin{sidewaystable}
\centering
\begin{tabular}{ccccccccc}
\hline
Left & LEFT & left & Middle & MIDDLE & middle & Right & RIGHT & right \\ \hline
$-4$ & $-3$ & $-2$ & $-1$ & $0$ & $1$ & $2$ & $3$ & $4$ \\ \hline
\end{tabular}
\end{sidewaystable}
\subsubsection{Side By Side}
\paragraph{Table With Words}
\begin{table}[H]
\centering
\caption{Table With Words Example}
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}
\qquad
\parbox[b]{0.4\textwidth}{This is the comment on the table.}
\end{table}
\paragraph{Tables Side By Side}
\begin{table}[H]
\centering
\caption{Table Side By Side Example}
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}
\qquad
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}
\end{table}
\paragraph{Captions For Side By Side}
\begin{table}[H]
\caption{Title For Both}
\parbox[b]{0.5\textwidth}{\centering
\caption{Title For Left}
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}}
\parbox[b]{0.5\textwidth}{\centering
\caption{Title For Right}
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}}
\end{table}
\begin{table}[H]
% must usepackage subcaption
\caption{Title For Both}
\begin{subtable}[b]{0.5\textwidth}
\centering
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}
\caption{Title For Left}
\end{subtable}
\begin{subtable}[b]{0.5\textwidth}
\centering
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}
\caption{Title For Right}
\end{subtable}
\end{table}
\subsubsection{Table Arrounded By Words}
\begin{tabwindow}[2, r,
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}, Title Of Arounded Table] % must usepackage picinpar
% bug exists
These are the words around the table, and the table will appear below two lines,
lying in the right of the words, rather than left. The following will be fillings.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
\end{tabwindow}
\begin{wraptable}[10]{r}[1.5cm]{5cm} % must usepackage wrapfig
\centering
\caption{Title Of Arounded Table}
\begin{tabular}{|c|c|c|}
\hline
left & center & right \\ \hline
item1 & item2 & item3 \\ \hline
\end{tabular}
\end{wraptable}
These are the words around the table, and the table will appear with height of 10 lines,
lying in the right of the words, rather than left, and it will extend out 1.5cm, and has width of 5cm.
The following will be fillings.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
Hello world. Hello world. Hello world. Hello world. Hello world. Hello world. Hello world.
\subsection{Color Table}
% bug exists
% \begin{tabular}{>{\columncolor{gray}}c | >{\columncolor{lightgray}}c}
% darker & lighter \\
% gray & gray \\
% \end{tabular}
% \begin{tabular}{c|c}
% \rowcolor{lightgray} light & gray \\
% just & white \\
% \end{tabular}
% \begin{tabular}{cccc}
% No & No & \cellcolor{lightgray}Yes & No \\
% \cellcolor{lightgray}Yes & No & No & No \\
% \end{tabular}
% \arrayrulecolor{gray}
% \doublerulesepcolor{lightgray}
% \begin{tabular}{cc}
% \hline\hline
% gray line & lightgray doubleline \\
% \arrayrulecolor{black}
% \doublerulesepcolor{white}
% \hline
% original black line & original white double line \\
% \hline\hline
% \end{tabular}
% \arrayrulecolor{black} % restore
% \doublerulesepcolor{white}
% \rowcolors[\hline]{2}{black!20}{black!10}
% \begin{tabular}{crr}
% \rowcolor{black!30} person & OS & CA \\ % set the color of table header separately
% dadadadawjb & 100 & 100 \\
% Junbo Wang & 99 & 99 \\
% wjb & 98 & 98 \\
% \end{tabular}