summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/diagbox/diagbox.dtx
blob: e301753950dabd3864a88ef8b370bb43f5fd66e7 (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
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
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
% \iffalse meta-comment
%
% Copyright (C) 2011--2016 by Leo Liu <leoliu.pku@gmail.com>
% ---------------------------------------------------------------------------
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Leo Liu.
%
% This work consists of the files diagbox.dtx and diagbox.ins
% and the derived filebase diagbox.sty.
%
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{diagbox.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{diagbox}
%<*package>
    [2016/12/28 v2.2 Making table heads with diagonal lines]
%</package>
%
%<*driver>
\documentclass[letterpaper]{ltxdoc}
\AtBeginDocument{
  \DeleteShortVerb{\|}
  \MakeShortVerb{\"}}
\usepackage{diagbox}
\usepackage{xcolor}
\usepackage[left=1.7in,top=1in,bottom=1in]{geometry}
\usepackage{fvrb-ex}
\usepackage{amsmath}
\usepackage[UTF8]{ctex}
\makeatletter
\renewcommand\glossary@prologue{%
  \section*{版本历史}
  \markboth{版本历史}{版本历史}}
\renewcommand\index@prologue{%
  \section*{Index / 代码索引}
  \markboth{Index / 代码索引}{Index / 代码索引}
  斜体的数字表示对应项说明所在的页码。下划线的数字表示定义所在的代码行号;而直
  立体的数字表示对应项使用时所在的行号。}
\renewcommand*\title[2][]{\gdef\@title{#2}}
\renewcommand*\author[2][]{\gdef\@author{#2}}
\providecommand\eTeX{$\m@th\varepsilon$-\TeX}
\makeatother
\usepackage[numbered]{hypdoc}
\hypersetup{pdfstartview=FitH}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{diagbox.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{612}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v1.0}{2011/11/21}{初始版本。}
%
% \DoNotIndex{\newcommand, \newenvironment, \@nameuse, \@pkgextension,
% \@reserveda, \@tfor, \begin, \begingroup, \box, \csname, \def, \define@key,
% \dimexpr, \do, \dp, \edef, \else, \end, \endcsname, \endgroup, \endinput,
% \expandafter, \fi, \hbox, \ht, \ifcsname, \ifdim, \ifx, \Line, \makebox,
% \newbox, \newdimen, \p@, \PackageError, \pkg, \put, \relax, \RequirePackage,
% \setbox, \setkeys, \setlength, \strip@pt, \unexpanded, \unitlength,
% \vcenter, \wd, \xdef, \z@, \@ifnextchar, \bgroup, \FPadd, \FPmul, \FPneg,
% \FPsub, \FPupn, \let, \unless, \hspace}
%
% \providecommand*{\pkg}{\textsf}
% \GetFileInfo{diagbox.dtx}
% \title[diagbox Package (\fileversion):
%   Making Table Heads with Diagonal Lines]%
%  {\hypertarget{English}{\pkg{diagbox} Package (\fileversion)}
%   \makebox[0pt][l]{\hspace{3cm}\large
%     \hyperlink{Chinese}{$\Rightarrow$ \textsf{中文版}}}\\
%   Making Table Heads with Diagonal Lines}
% \author[Leo Liu <leoliu.pku@gmail.com>]%
%   {Leo Liu \\ \path{leoliu.pku@gmail.com}}
% \date{\filedate}
%
% \maketitle
%
% \section{Introduction}
%
% \pkg{diagbox} is a replacement of old \pkg{slashbox} package\footnote{By
% Koichi Yasuoka and Toru Sato. Available on
% \url{CTAN://macros/latex/contrib/slashbox/slashbox.sty}}. I write this
% package simply because that \pkg{slashbox} is not available in \TeX\ Live
% for licening problems. \pkg{slashbox} has no explicit license information
% available, but \pkg{diagbox} is under LPPL.
%
% \pkg{diagbox} is a modern alternative of \pkg{slashbox}. I changed the
% user interface to use a key-value syntax, get rid of some restrictions of
% \pkg{slashbox}, use \pkg{pict2e} to draw diagonal lines. Especially, this
% package also provides ability to make a box with two diagonal lines in it.
% All these can be obtained by a "\diagbox" command.
%
% As a replacement of \pkg{slashbox}, \pkg{diagbox} package also provides
% compatible macros of \pkg{slashbox}, but the result is a little different.
%
% To use \pkg{diagbox}, \eTeX{} is needed. And \pkg{diagbox} requires
% \pkg{pict2e}, \pkg{keyval}, \pkg{calc}, and \pkg{fp} packages.
%
%
% \section{Usage}
%
% \subsection{Basic usage}
%
% To load the package, just put this in the preamble:
% \begin{Verbatim}
% \usepackage{diagbox}
% \end{Verbatim}
%
% \DescribeMacro{\diagbox}
% "\diagbox" is the main command. It can take two arguments, to produce a box
% with a diagonal line from north west to south east.
%
% For example:\\
% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth]
% \begin{tabular}{|l|ccc|}
% \hline
% \diagbox{Time}{Day} & Mon & Tue & Wed \\
% \hline
% Morning   & used & used &      \\
% Afternoon &      & used & used \\
% \hline
% \end{tabular}
% \end{SideBySideExample}
% \medskip
%
% "\diagbox" can also take three arguments, to draw a table head with two
% diagbox lines. For example,
% \begin{Example}[frame=single,numbers=left]
% \begin{tabular}{|l|ccc|}
% \hline
% \diagbox{Time}{Room}{Day} & Mon & Tue & Wed \\
% \hline
% Morning   & used & used &      \\
% Afternoon &      & used & used \\
% \hline
% \end{tabular}
% \end{Example}
%
% \subsection{More options}
%
% "\diagbox" can take a key-value list as an optional argument to specify the
% width and height of the box, the direction of the diagonal line, and the
% trimming margins:
% \begin{description}
% \item[width] Specify the width of the box explicitly. If it is omitted,
% \pkg{diagbox} will calculate the width automatically.
%
% \item[height] Specify the height of the box explicitly. If it is omitted,
% \pkg{diagbox} will calculate the height automatically. In the argument, one
% can use "\line" as a line height.
%
% \item[dir] Specify the direction of the diagonal line. The value can be
% "NW", "NE", "SW" and "SE". Default value is "NW". The meaning of the values
% see below.
% \begin{itemize}
% \item "\diagbox[dir="\meta{direction}"]{A}{B}" in a table looks:\\
% \begin{tabular}{ll@{\qquad}ll}
% "NW" or "SE":&
% \begin{tabular}{|c|} \hline \diagbox[dir=SE]{A}{B} \\\hline \end{tabular} &
% "SW" or "NE":&
% \begin{tabular}{|c|} \hline \diagbox[dir=NE]{A}{B} \\\hline \end{tabular}
% \end{tabular}
% \item "\diagbox[dir="\meta{direction}"]{A}{M}{B}" in a table looks:\\
% \begin{tabular}{*4{ll@{\qquad}}}
% "NW"&
% \begin{tabular}{|c|} \hline \diagbox[dir=NW]{A}{M}{B} \\\hline \end{tabular}&
% "NE"&
% \begin{tabular}{|c|} \hline \diagbox[dir=NE]{A}{M}{B} \\\hline \end{tabular}&
% "SW"&
% \begin{tabular}{|c|} \hline \diagbox[dir=SW]{A}{M}{B} \\\hline \end{tabular}&
% "SE"&
% \begin{tabular}{|c|} \hline \diagbox[dir=SE]{A}{M}{B} \\\hline \end{tabular}
% \end{tabular}
% \end{itemize}
%
% \item[innerwidth] Specify the width of the inner content box. "innerwidth"
% option is useful when specifying column width. For example:
% \begin{Example}
% \begin{tabular}{|p{2cm}|} \hline
% \diagbox[innerwidth=2cm]{A}{B} \\ \hline
% \end{tabular}
% \end{Example}
%
% \item[innerleftsep, innerrightsep] Specify the distances between the border
% of the inner content box and the border of the diagonal box. We have:
% \[
%   "innerleftsep" + "innerwidth" + "innerrightsep" = "width".
% \]
% For example:
% \begin{Example}
% \begin{tabular}{|c|} \hline
% \diagbox[innerleftsep=.5cm,innerrightsep=0pt]{A}{B} \\ \hline
% \end{tabular}
% \end{Example}
%
% \item[outerleftsep, outerrightsep] Specify the distances between the border
% of the diagonal box and the border of the tabular cell. Usually they are
% negative values, which satisfy
% \begin{align*}
%   "outerleftsep" + "LEFTtabcolsep" &= 0\,\mathrm{pt}, \\
%   "outerrightsep" + "RIGHTtabcolsep" &= 0\,\mathrm{pt}.
% \end{align*}
% where "LEFTtabcolsep" and "RIGHTtabcolsep" are the distances between
% verticle lines and the tabular cell content (the diagonal box). For example:
% \begin{Example}
% \begin{tabular}{|r@{\hspace{20pt}}|l|} \hline
% \diagbox[outerrightsep=-20pt]{A}{B} & C \\ \hline
% AABB & CC \\ \hline
% \end{tabular}
% \end{Example}
%
% \item[leftsep, rightsep] Specify the left and right distances, which are
% equivalent to:
% \begin{align*}
% "innerleftsep" &:= "leftsep",  &  "innerrightsep" &:= "rightsep", \\
% "outerleftsep" &:= -"leftsep",  &  "outerrightsep" &:= -"rightsep".
% \end{align*}
%
% \item[trim] Specify the margin to be trimmed. The value can be "l", "r", and
% "lr", "rl". This helps the slash line exceeds the boundary when "@{}" column
% specifier is used.
%
% Note: "trim=l" has the same effect as "leftsep=0pt", and "trim=r" has the
% same effect as "rightsep=0pt".
%
% \item[font] Specify the font of the cell.
%
% "\diagbox[font=\footnotesize\itshape]{Small}{Italic}"\quad
% \begin{tabular}{|c|} \hline
% \diagbox[font=\footnotesize\itshape]{Small}{Italic} \\ \hline
% \end{tabular}
%
% \item[linewidth] Specify the line width of the diagonal lines.
% \item[linecolor] Specify the line color of the diagonal lines. (\pkg{color}
% or \pkg{xcolor} is needed.)
%
% "\diagbox[linewidth=2pt,linecolor=blue]{AAA}{BBB}"\quad
% \begin{tabular}{|c|} \hline
% \diagbox[linewidth=2pt,linecolor=blue]{AAA}{BBB} \\ \hline
% \end{tabular}
% \end{description}
%
% Here is a more complex example to show the usage of the options:
% \begin{Example}[frame=single,numbers=left]
% \begin{tabular}{|@{}l|c|c|r@{}|}
% \hline
% \diagbox[width=5em,trim=l]{Time}{Day} & Mon & Tue & Wed\\
% \hline
% Morning   & used & used & used\\
% \hline
% Afternoon &      & used & \diagbox[dir=SW,height=2em,trim=r]{A}{B} \\
% \hline
% \end{tabular}
% \end{Example}
%
% \bigskip
% What's more, you can use "\\" to break lines in "\diagbox". Manual setting
% of the height of the head may be needed. For example,
% \begin{Example}[frame=single,numbers=left]
% \begin{tabular}{|c|}
% \hline
% \diagbox[height=3\line]{line\\heads}{column\\heads} \\
% \hline
% \end{tabular}
% \end{Example}
%
% \subsection{Compatibility with \pkg{slashbox}}
%
% \pkg{diagbox} package emulates \pkg{slashbox} and also prevents
% \pkg{slashbox} to be loaded.
%
% \pkg{diagbox} package provides "\slashbox" and "\backslashbox" which syntax
% similar to \pkg{slashbox} package. However, the results of the two packages
% are a little different. These two commands are for compatibility only, it is
% better to use "\diagbox" instead for new documents.
%
% \DescribeMacro{\backslashbox}
% "\backslashbox" works as "\diagbox", but it takes two optional arguments to
% specify the "width" and "trim" options.
%
% \DescribeMacro{\slashbox}
% "\slashbox" works as "\diagbox[dir=SW]", and takes two optional arguments to
% specify the "width" and "trim" options.
%
% For example,\\
% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth]
% \begin{tabular}{|c|c|c|} \hline
% \backslashbox[2cm]{num}{alpha}
%   & A  & B  \\\hline
% 1 & A1 & B1 \\\hline
% 2 & A2 & B2 \\\hline
% \end{tabular}
% \end{SideBySideExample}
%
%
% \section{Known issues and TODO}
%
% Known issues:
% \begin{itemize}
% \item The result of "\slashbox" and "\backslashbox" is different with
% \pkg{slashbox} package. The algorithms to calculate the width and height are
% different; and the results of the second optional argument of "\slashbox"
% (i.e. "trim" key in "\diagbox") in the two packages are differernt.
%
% This is not a bug. Usually the width calculated by \pkg{diagbox} is more
% safe than \pkg{slashbox}.
%
% \item
% The cell with "\diagbox" should be the widest one of the column. Otherwise
% the slash line cannot exceeds the boundary. For example,\\[1ex]
% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth]
% \begin{tabular}{|c|}  \hline
%   \diagbox{A}{B}    \\\hline
%   Very long term    \\\hline
% \end{tabular}
% \end{SideBySideExample}
% \\[1ex]
% This can be solved by setting a wider "width" option of "\diagbox" manually.
% \end{itemize}
%
% TODO:
% \begin{itemize}
% \item
% Improve the document of the source code. The algorithm of "\diagbox@triple"
% should be explained in detail. However, the explanations would be only
% available in Chinese, I'm sorry.
% \end{itemize}
%
%
% \title[]{\hypertarget{Chinese}{\pkg{diagbox} 宏包(\fileversion)}
%   \makebox[0pt][l]{\hspace{3cm}\large
%     \hyperlink{English}{$\Rightarrow$ \textsf{English Version}}}\\
%    制做斜线表头}
% \author{刘海洋 \\ \path{leoliu.pku@gmail.com}}
% \date{\filedate}
%
% \maketitle
%
%
% \section{简介}
%
% \pkg{diagbox} 设计用来代替旧的 \pkg{slashbox} 宏包\footnote{作者 Koichi
% Yasuoka(安岡孝一)与 Sato Toru(佐藤徹)。宏包见
% \url{CTAN://macros/latex/contrib/slashbox/slashbox.sty}。}。编写这个宏包的缘
% 起是 \pkg{slashbox} 因为缺少明确的自由许可信息,被 \TeX\ Live 排除。这个宏包
% 是在 LPPL 协议下发行的。
%
% \pkg{diagbox} 是 \pkg{slashbox} 宏包的一个现代的版本。它采用了新的 key-value
% 式语法参数,去除了 \pkg{slashbox} 原有的一些长度限制,并调用 \pkg{pict2e} 宏
% 包画斜线;特别还添加了绘制两条斜线的表头的新功能。
%
% 作为 \pkg{slashbox} 的代替,\pkg{diagbox} 除了提供自己的新命令,也提供了
% \pkg{slashbox} 原有的两个命令,语法不变,编译结果略有区别。
%
% \pkg{diagbox} 依赖 \eTeX{} 扩展(这在目前总是可用的),依赖 \pkg{pict2e}、
% \pkg{keyval}、\pkg{calc} 和 \pkg{fp} 宏包。
%
% \section{用法说明}
%
% \subsection{基本用法}
%
% 要使用本宏包,首先在导言区调用:
% \begin{Verbatim}
% \usepackage{diagbox}
% \end{Verbatim}
%
% \DescribeMacro{\diagbox}
% "\diagbox" 是宏包提供的主要命令。它可以带有两个必选参数,表示要生成斜线表头的
% 两部分内容。默认斜线是从西北到东南方向的。
%
% 例如:\\
% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth]
% \begin{tabular}{|l|ccc|}
% \hline
% \diagbox{Time}{Day} & Mon & Tue & Wed \\
% \hline
% Morning   & used & used &      \\
% Afternoon &      & used & used \\
% \hline
% \end{tabular}
% \end{SideBySideExample}
% \medskip
%
% \changes{v2.0}{2011/11/22}{增加有三部分、双斜线的表头格式。}
% "\diagbox" 也可以接受三个参数,这样就会生成带有两条斜线的表头,例如:
% \begin{Example}[frame=single,numbers=left]
% \begin{tabular}{|l|ccc|}
% \hline
% \diagbox{Time}{Room}{Day} & Mon & Tue & Wed \\
% \hline
% Morning   & used & used &      \\
% Afternoon &      & used & used \\
% \hline
% \end{tabular}
% \end{Example}
%
% \subsection{更多参数设置}
%
% "\diagbox" 还可以在前面带一个可选参数,里面用 key-value 的语法设置宽度、方向
% 等更多的选项:
% \begin{description}
% \item[width] 明确指定盒子的总宽度。如果省略,则会自动计算能够放下所有内容的
% 宽度。
% \item[height] 明确指定盒子的总高度。
% \item[dir] 指定斜线方向。可以取 "NW"(西北)、"NE"(东北)、"SW"(西南)、
% "SE"(东南)四种方向。在只有一条斜线的表头中,"NE" 与 "SW"、 "SE" 与 "NW" 是
% 等价的。斜线方向的默认值是 "NW"。
%
% "\diagbox[dir="\meta{方向}"]{A}{B}" 在表格中的效果:\\
% \begin{tabular}{ll@{\qquad}ll}
% "NW" 或 "SE":&
% \begin{tabular}{|c|} \hline \diagbox[dir=SE]{A}{B} \\\hline \end{tabular} &
% "SW" 或 "NE":&
% \begin{tabular}{|c|} \hline \diagbox[dir=NE]{A}{B} \\\hline \end{tabular}
% \end{tabular}
%
% "\diagbox[dir="\meta{方向}"]{A}{M}{B}" 在表格中的效果:\\
% \begin{tabular}{*4{ll@{\qquad}}}
% "NW"&
% \begin{tabular}{|c|} \hline \diagbox[dir=NW]{A}{M}{B} \\\hline \end{tabular}&
% "NE"&
% \begin{tabular}{|c|} \hline \diagbox[dir=NE]{A}{M}{B} \\\hline \end{tabular}&
% "SW"&
% \begin{tabular}{|c|} \hline \diagbox[dir=SW]{A}{M}{B} \\\hline \end{tabular}&
% "SE"&
% \begin{tabular}{|c|} \hline \diagbox[dir=SE]{A}{M}{B} \\\hline \end{tabular}
% \end{tabular}
%
% \item[innerwidth] 设置盒子中内容的宽度。"innerwidth" 选项可以与表格的列宽度
% 一起设置并保持一致。如:
% \begin{Example}
% \begin{tabular}{|p{2cm}|} \hline
% \diagbox[innerwidth=2cm]{A}{B} \\ \hline
% \end{tabular}
% \end{Example}
%
% \item[innerleftsep, innerrightsep] 设置内间距,即内容盒子与斜线盒子边界之间
% 的距离。我们有关系式:
% \[
%   "innerleftsep" + "innerwidth" + "innerrightsep" = "width".
% \]
% 例如:
% \begin{Example}
% \begin{tabular}{|c|} \hline
% \diagbox[innerleftsep=.5cm,innerrightsep=0pt]{A}{B} \\ \hline
% \end{tabular}
% \end{Example}
%
% \item[outerleftsep, outerrightsep] 设置外间距,即斜线盒子边界到表格单元格边
% 界的距离。由于斜线是沿单元格画出而非斜线盒子本身画出,斜线通常会伸出斜线盒子
% 之外,此距离为负数,并满足如下关系式:
% \begin{align*}
%   "outerleftsep" + "LEFTtabcolsep" &= 0\,\mathrm{pt}, \\
%   "outerrightsep" + "RIGHTtabcolsep" &= 0\,\mathrm{pt}.
% \end{align*}
% 其中 "LEFTtabcolsep" 与 "RIGHTtabcolsep" 是表格竖线与表格内容(斜线例子边
% 界)之间的距离。例如:
% \begin{Example}
% \begin{tabular}{|r@{\hspace{20pt}}|l|} \hline
% \diagbox[outerrightsep=-20pt]{A}{B} & C \\ \hline
% AABB & CC \\ \hline
% \end{tabular}
% \end{Example}
%
% \item[leftsep, rightsep] 同时设置左右内外间距,满足关系式:
% \begin{align*}
% "innerleftsep" &:= "leftsep",  &  "innerrightsep" &:= "rightsep", \\
% "outerleftsep" &:= -"leftsep",  &  "outerrightsep" &:= -"rightsep".
% \end{align*}
%
% \item[trim] 设置左边界或右边界不计算额外的空白,可以取值为 "l", "r", "lr" 或
% "rl"。这个选项在列格式包含 "@{}" 时将会有用。
%
% 注:"trim=l" 与 "leftsep=0pt" 效果相同,而 "trim=r" 与 "rightsep=0pt" 效果相
% 同。
%
% \item[font] 设置单元格字体。
%
% "\diagbox[font=\footnotesize\itshape]{Small}{Italic}"\quad
% \begin{tabular}{|c|} \hline
% \diagbox[font=\footnotesize\itshape]{Small}{Italic} \\ \hline
% \end{tabular}
%
% \item[linewidth] 设置斜线宽度。
% \item[linecolor] 设置斜线颜色。(需要自行载入 \pkg{color} 或 \pkg{xcolor} 宏
% 包。)
%
% "\diagbox[linewidth=2pt,linecolor=blue]{AAA}{BBB}"\quad
% \begin{tabular}{|c|} \hline
% \diagbox[linewidth=2pt,linecolor=blue]{AAA}{BBB} \\ \hline
% \end{tabular}
% \end{description}
%
% \changes{v2.0}{2011/11/23}{变更 "trim" 选项的行为,去掉了使用 "trim" 选项时
% 内部的间距。这与 \pkg{slashbox} 行为不同。}
% 一个更复杂的例子:
% \begin{Example}[frame=single,numbers=left]
% \begin{tabular}{|@{}l|c|c|r@{}|}
% \hline
% \diagbox[width=5em,trim=l]{Time}{Day} & Mon & Tue & Wed\\
% \hline
% Morning   & used & used & used\\
% \hline
% Afternoon &      & used & \diagbox[dir=SW,height=2em,trim=r]{A}{B} \\
% \hline
% \end{tabular}
% \end{Example}
% \bigskip
%
% 此外,"\diagbox" 的表头内容还可以用 "\\" 手工换行。此时通常需要对自动计算的
% 表头高度进行手工调整。例如:
% \begin{Example}[frame=single,numbers=left]
% \begin{tabular}{|c|}
% \hline
% \diagbox[height=3\line]{line\\heads}{column\\heads} \\
% \hline
% \end{tabular}
% \end{Example}
%
% \subsection{对 \pkg{slashbox} 宏包的兼容性}
%
% 在使用 \pkg{diagbox} 宏包时,会模拟 \pkg{slashbox} 宏包的功能,并禁止
% \pkg{slashbox} 再被调用。
%
% \pkg{diagbox} 宏包提供了与 \pkg{slashbox} 大致相同的 "\slashbox" 与
% "\backslashbox" 两个命令。 "\slashbox" 与 "\backslashbox" 的语法来自
% \pkg{slashbox} 宏包,排版效果略有区别。这两个命令仅在旧文档中作为兼容命令使
% 用。实际中使用 "\diagbox" 更为方便。
%
% \DescribeMacro{\backslashbox}
% "\backslashbox" 基本功能与 "\diagbox" 类似。它带有两个可选参数,分别表示
% "\diagbox" 中的 "width" 与 "trim" 选项。
%
% \DescribeMacro{\slashbox}
% "\slashbox" 基本功能与 "\diagbox[dir=SW]" 类似。它也带有两个可选参数,表示
% "\diagbox" 中的 "width" 和 "tirm" 选项。
%
% 例如:\\
% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth]
% \begin{tabular}{|c|c|c|} \hline
% \backslashbox[2cm]{num}{alpha}
%   & A  & B  \\\hline
% 1 & A1 & B1 \\\hline
% 2 & A2 & B2 \\\hline
% \end{tabular}
% \end{SideBySideExample}
%
% \section{已知问题和未来版本}
%
% 已知问题:
% \begin{itemize}
% \item "\slashbox" 与 "\backslashbox" 命令的效果与在 \pkg{slashbox} 宏包中不
% 同。两个宏包在计算盒子宽度和高度时,使用了不同的算法;同时,在处理
% "\slashbox" 第二个可选参数(即 "\diagbox" 的 "trim" 键)时,使用的方式也不一
% 样。
%
% 这不是 bug。通常 \pkg{diagbox} 计算出的宽度比 \pkg{slashbox} 的结果更安全一
% 些。
%
% \item
% "\diagbox" 生成的单元格必须是表列中最宽的一个。如果不能达到最宽,则画出的斜
% 线不能保证在正确的位置。例如:\\[1ex]
% \begin{SideBySideExample}[frame=single,numbers=left,xrightmargin=.45\linewidth]
% \begin{tabular}{|c|}  \hline
%   \diagbox{A}{B}    \\\hline
%   Very long term    \\\hline
% \end{tabular}
% \end{SideBySideExample}
% \\[1ex]
% 此时可以手工设置较宽的 "\diagbox" 的 "width" 选项,解决此问题。
% \end{itemize}
%
% 未尽的工作:
% \begin{itemize}
% \item 源代码的文档需要改进。特别是在 "\diagbox@triple" 中的宽度和高度计算算
% 法需要详细说明。
% \end{itemize}
%
% \StopEventually{}
%
%
% \clearpage
% \section{Implementation / 代码实现}
%
% \iffalse
%<*package>
% \fi
%
% \subsection{实现依赖的工具包}
%
% 使用 key-value 界面。
%    \begin{macrocode}
\RequirePackage{keyval}
%    \end{macrocode}
% 绘图依赖 \pkg{pict2e} 宏包。
%    \begin{macrocode}
\RequirePackage{pict2e}
%    \end{macrocode}
% 计算依赖 \pkg{fp} 宏包。
% \changes{v2.2}{2016/12/28}{避免 \pkg{fp} 包的 \texttt{nomessages} 选项在使用
% \pkg{catoptions} 包时冲突}
%    \begin{macrocode}
\RequirePackage{fp}
\FPmessagesfalse
%    \end{macrocode}
% 长度计算 \pkg{calc} 宏包。
% \changes{v2.2}{2016/12/28}{使用 \pkg{calc} 包计算选项参数,以支持
% \cs{widthof} 等命令。}
%    \begin{macrocode}
\RequirePackage{calc}
%    \end{macrocode}
% 内部控制 \pkg{array} 宏包。
%    \begin{macrocode}
\RequirePackage{array}
%    \end{macrocode}
%
%
% \subsection{资源分配}
%
% 分配用到的盒子寄存器。它们分别对应于 "\diagbox" 三个必选参数的内容。
%    \begin{macrocode}
\newbox\diagbox@boxa
\newbox\diagbox@boxb
\newbox\diagbox@boxm
%    \end{macrocode}
% 分配长度变量。
%    \begin{macrocode}
\newdimen\diagbox@wd
\newdimen\diagbox@ht
\newdimen\diagbox@insepl
\newdimen\diagbox@insepr
\newdimen\diagbox@outsepl
\newdimen\diagbox@outsepr
%    \end{macrocode}
%
%    \begin{macrocode}
\def\diagbox@clear{%
  \diagbox@wd=\z@
  \diagbox@ht=\z@
  \diagbox@insepl=\tabcolsep
  \diagbox@insepr=\tabcolsep
  \diagbox@outsepl=-\tabcolsep
  \diagbox@outsepr=-\tabcolsep
}
%    \end{macrocode}
%
% \subsection{命令选项定义}
%
% 下面定义 "\diagbox" 的键值选项。
%
% \changes{v2.1}{2014/07/03}{允许在 \texttt{width} 和 \texttt{height} 的命令选项
% 中写表达式计算长度。}
% \changes{v2.1}{2016/02/24}{允许在 \texttt{height} 选项中使用
% \texttt{\textbackslash line} 表示行高。}
% 斜线盒子的总宽度。
%    \begin{macrocode}
\define@key{diagbox}{width}{%
  \unless\ifdim\diagbox@wd=\z@
    \PackageWarning{diagbox}%
      {You should not set width/innerwidth option more than once.}%
  \fi
  \setlength{\diagbox@wd}{#1}}
%    \end{macrocode}
% 斜线盒子的总高度,参数中可使用 "\line" 表示行高。
%    \begin{macrocode}
\define@key{diagbox}{height}{%
  \let\diagbox@save@line\line
  \def\line{\normalbaselineskip}%
  \setlength{\diagbox@ht}{#1}%
  \let\line\diagbox@save@line}
%    \end{macrocode}
%
% \changes{v2.1}{2014/08/15}{盒子内容与斜线框距离 \texttt{innerleftsep},
% \texttt{innerrightsep} 命令选项。}
% 盒子内容与斜线框左右的距离。
%    \begin{macrocode}
\define@key{diagbox}{innerleftsep}{%
  \setlength{\diagbox@insepl}{#1}}
\define@key{diagbox}{innerrightsep}{%
  \setlength{\diagbox@insepr}{#1}}
%    \end{macrocode}
%
% \changes{v2.1}{2016/02/24}{盒子内容宽度 \texttt{innerwidth} 命令选项。}
% 设置盒子内容的宽度(与列格式 "p{宽度}" 对应)。盒子内容宽度加上盒子与斜线框
% 左右距离之和应为斜线盒子总宽度,即有
% \[
%   "innerleftsep" + "innerwidth" + "innerrightsep" = "width".
% \]
% "innerwidth" 选项将通过设置盒子总宽度,维护上面的关系式。
%    \begin{macrocode}
\define@key{diagbox}{innerwidth}{%
  \unless\ifdim\diagbox@wd=\z@
    \PackageWarning{diagbox}%
      {You should not set width/innerwidth option more than once.}%
  \fi
  \setlength{\diagbox@wd}{#1+\diagbox@insepl+\diagbox@insepr}}
%    \end{macrocode}
%
% \changes{v2.1}{2014/08/15}{斜线盒子与表格单元边框距离 \texttt{outerleftsep},
% \texttt{outerrightsep} 命令选项。}
% 斜线盒子与表格单元边框距离。该外部间距应为实际表列内容与列分隔线之间距离的相
% 反数,以此保证斜线与表格竖线能相接,即应输入参数保证
% \begin{align*}
%   "outerleftsep" + "LEFTtabcolsep" &= 0\,\mathrm{pt}, \\
%   "outerrightsep" + "RIGHTtabcolsep" &= 0\,\mathrm{pt}.
% \end{align*}
%    \begin{macrocode}
\define@key{diagbox}{outerleftsep}{%
  \setlength{\diagbox@outsepl}{#1}}
\define@key{diagbox}{outerrightsep}{%
  \setlength{\diagbox@outsepr}{#1}}
%    \end{macrocode}
%
% \changes{v2.1}{2014/08/15}{左右边距 \texttt{leftsep}, \texttt{rightsep} 命令
% 选项。}
% 设置左右边距,它将同时设置盒子内容与斜线框的内部间距,以及斜线盒子与表格单元
% 边框的外部间距。并保持关系:
% \begin{align*}
% "innerleftsep" &:= "leftsep",  &  "innerrightsep" &:= "rightsep", \\
% "outerleftsep" &:= -"leftsep",  &  "outerrightsep" &:= -"rightsep".
% \end{align*}
%    \begin{macrocode}
\define@key{diagbox}{leftsep}{%
  \setlength{\diagbox@insepl}{#1}%
  \setlength{\diagbox@outsepl}{-(#1)}}
\define@key{diagbox}{rightsep}{%
  \setlength{\diagbox@insepr}{#1}%
  \setlength{\diagbox@outsepr}{-(#1)}}
%    \end{macrocode}
%
% 盒子计算边界时是否忽略左右的空白。"trim=l" 效果等同于 "leftsep=0pt";"trim=r"
% 效果等同于 "rightsep=0pt"。
%    \begin{macrocode}
\define@key{diagbox}{trim}{%
  \@tfor\@reserveda:=#1\do{%
    \ifcsname diagbox@insep\@reserveda\endcsname
      \setlength{\csname diagbox@insep\@reserveda\endcsname}{\z@}%
      \setlength{\csname diagbox@outsep\@reserveda\endcsname}{\z@}%
    \else
      \PackageError{diagbox}{Unknown trim option `#1'.}{l, r, lr and rl are supported.}%
    \fi}}
%    \end{macrocode}
%
% 盒子的方向。
%    \begin{macrocode}
\define@key{diagbox}{dir}{%
  \def\diagbox@dir{#1}%
  \unless\ifcsname diagbox@dir@#1\endcsname
    \PackageError{diagbox}{Unknown direction `#1'.}{NW, NE, SW, SE are supported.}%
    \def\diagbox@dia{NW}%
  \fi}
\let\diagbox@dir@SE\relax
\let\diagbox@dir@SW\relax
\let\diagbox@dir@NE\relax
\let\diagbox@dir@NW\relax
%    \end{macrocode}
%
% \changes{v2.1}{2014/07/03}{增加命令选项 \texttt{linewidth}, \texttt{linecolor}
% 设置斜线宽度与颜色。}
% 斜线宽度与颜色。
%    \begin{macrocode}
\define@key{diagbox}{linewidth}{%
  \setlength{\@tempskipa}{#1}%
  \linethickness{\@tempskipa}}
\define@key{diagbox}{linecolor}{%
  \def\diagbox@setlinecolor{\color{#1}}}
\let\diagbox@setlinecolor\empty
%    \end{macrocode}
%
% \changes{v2.1}{2014/07/03}{增加命令选项 \texttt{font} 支持设置内容字体。}
% 设置内容字体。
%    \begin{macrocode}
\define@key{diagbox}{font}{%
  \def\diagbox@font{#1}}
\let\diagbox@font\empty
%    \end{macrocode}
%
% \subsection{绘制斜线盒子}
%
% \begin{macro}{\diagbox@pict}
% 这是带斜线的盒子本身。由一个 "picture" 环境实现。
%    \begin{macrocode}
\def\diagbox@pict{%
  \unitlength\p@
  \begin{picture}
    (\strip@pt\dimexpr\diagbox@wd+\diagbox@outsepl+\diagbox@outsepr\relax,\strip@pt\diagbox@ht)
    (\strip@pt\dimexpr-\diagbox@outsepl\relax,0)
      \@nameuse{diagbox@\diagbox@part @pict@\diagbox@dir}
  \end{picture}}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\diagbox@double@pict@SE}
% 方向为 "SE" 的斜线盒子内容。
%    \begin{macrocode}
\def\diagbox@double@pict@SE{%
  \put(0,0) {\makebox(0,0)[bl]{\box\diagbox@boxa}}
  \put(\strip@pt\diagbox@wd,\strip@pt\diagbox@ht) {\makebox(0,0)[tr]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,\strip@pt\diagbox@ht)(\strip@pt\diagbox@wd,0)}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\diagbox@double@pict@NW}
% 方向 "NW" 与 "SE" 相同。
%    \begin{macrocode}
\let\diagbox@double@pict@NW\diagbox@double@pict@SE
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\diagbox@double@pict@NE}
% 方向为 "NE" 的斜线盒子内容。
%    \begin{macrocode}
\def\diagbox@double@pict@NE{%
  \put(0,\strip@pt\diagbox@ht) {\makebox(0,0)[tl]{\box\diagbox@boxa}}
  \put(\strip@pt\diagbox@wd,0) {\makebox(0,0)[br]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,0)(\strip@pt\diagbox@wd,\strip@pt\diagbox@ht)}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\diagbox@double@pict@NE}
% 方向 "SW" 与 "NE" 相同。
%    \begin{macrocode}
\let\diagbox@double@pict@SW\diagbox@double@pict@NE
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\diagbox@double}
% \changes{v2.0}{2011/11/22}{在使用 "trim" 选项时去掉内容与盒子边界的间距。这
% 与 \pkg{slashbox} 的行为不同。}
% 分成两部分的盒子。三个参数,分别为 key-value 格式的可选项、左半边内容、右半边
% 内容。这里的主要工作是读入参数并计算斜线盒子的大小。
%    \begin{macrocode}
\def\diagbox@double#1#2#3{%
  \begingroup
  \diagbox@clear
  \def\diagbox@part{double}%
  \setkeys{diagbox}{dir=NW,#1}%
  \setbox\diagbox@boxa=\hbox{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
      #2
    \end{tabular}}%
  \setbox\diagbox@boxb=\hbox{%
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
      #3
    \end{tabular}}%
  \ifdim\diagbox@wd=\z@
    \ifdim\wd\diagbox@boxa>\wd\diagbox@boxb
      \diagbox@wd=\dimexpr2\wd\diagbox@boxa+\diagbox@insepl+\diagbox@insepr\relax
    \else
      \diagbox@wd=\dimexpr2\wd\diagbox@boxb+\diagbox@insepl+\diagbox@insepr\relax
    \fi
  \fi
  \ifdim\diagbox@ht=\z@
    \diagbox@ht=\dimexpr\ht\diagbox@boxa+\dp\diagbox@boxa+\ht\diagbox@boxb+\dp\diagbox@boxb\relax
  \fi
  $\vcenter{\hbox{\diagbox@pict}}$%
  \endgroup}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\diagbox@triple@setbox@NW}
%    \begin{macrocode}
\def\diagbox@triple@setbox@NW#1#2#3{%
  \setbox\diagbox@boxa=\hbox{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
      #1
    \end{tabular}}%
  \setbox\diagbox@boxm=\hbox{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}>{\diagbox@font}l@{}}
      #2
    \end{tabular}}%
  \setbox\diagbox@boxb=\hbox{%
    \begin{tabular}{@{}>{\diagbox@font}r@{\hspace{\diagbox@insepr}}}
      #3
    \end{tabular}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\diagbox@triple@setbox@SW}
%    \begin{macrocode}
\let\diagbox@triple@setbox@SW\diagbox@triple@setbox@NW
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\diagbox@triple@setbox@NW}
%    \begin{macrocode}
\def\diagbox@triple@setbox@SE#1#2#3{%
  \setbox\diagbox@boxa=\hbox{%
    \begin{tabular}{@{\hspace{\diagbox@insepl}}l@{}}#1\end{tabular}}%
  \setbox\diagbox@boxm=\hbox{%
    \begin{tabular}{@{}r@{\hspace{\diagbox@insepr}}}#2\end{tabular}}%
  \setbox\diagbox@boxb=\hbox{%
    \begin{tabular}{@{}r@{\hspace{\diagbox@insepr}}}#3\end{tabular}}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\diagbox@triple@setbox@NE}
%    \begin{macrocode}
\let\diagbox@triple@setbox@NE\diagbox@triple@setbox@SE
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\diagbox@triple@pict@NW}
%    \begin{macrocode}
\def\diagbox@triple@pict@NW{%
  \put(0,0)   {\makebox(0,0)[bl]{\box\diagbox@boxa}}
  \put(0,\y)  {\makebox(0,0)[tl]{\box\diagbox@boxm}}
  \put(\x,\y) {\makebox(0,0)[tr]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,\yym)(\x,0)
  \Line(\xm,\y)(\x,0)}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\diagbox@triple@pict@NE}
%    \begin{macrocode}
\def\diagbox@triple@pict@NE{%
  \put(0,\y)  {\makebox(0,0)[tl]{\box\diagbox@boxa}}
  \put(\x,\y) {\makebox(0,0)[tr]{\box\diagbox@boxm}}
  \put(\x,0)  {\makebox(0,0)[br]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,0)(\xxm,\y)
  \Line(0,0)(\x,\yym)}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\diagbox@triple@pict@SW}
%    \begin{macrocode}
\def\diagbox@triple@pict@SW{%
  \put(0,\y) {\makebox(0,0)[tl]{\box\diagbox@boxa}}
  \put(0,0)  {\makebox(0,0)[bl]{\box\diagbox@boxm}}
  \put(\x,0) {\makebox(0,0)[br]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,\ym)(\x,\y)
  \Line(\xm,0)(\x,\y)}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\diagbox@triple@pict@SE}
%    \begin{macrocode}
\def\diagbox@triple@pict@SE{%
  \put(0,0)   {\makebox(0,0)[bl]{\box\diagbox@boxa}}
  \put(\x,0)  {\makebox(0,0)[br]{\box\diagbox@boxm}}
  \put(\x,\y) {\makebox(0,0)[tr]{\box\diagbox@boxb}}
  \diagbox@setlinecolor
  \Line(0,\y)(\xxm,0)
  \Line(0,\y)(\x,\ym)}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\diagbox@triplebox}
% \changes{v2.0}{2011/11/22}{新增三部分双斜线的盒子}
% 分成三部分的盒子。四个参数,分别为 key-value 格式的可选项、左半边内容、中间
% 内容、右半边内容。
%    \begin{macrocode}
\def\diagbox@triple#1#2#3#4{%
  \begingroup
  \diagbox@clear
  \def\diagbox@part{triple}%
  \setkeys{diagbox}{dir=NW,#1}%
  \@nameuse{diagbox@triple@setbox@\diagbox@dir}{#2}{#3}{#4}%
%    \end{macrocode}
% 取长宽
%    \begin{macrocode}
  \edef\xa{\strip@pt\wd\diagbox@boxa}%
  \edef\ya{\strip@pt\dimexpr\ht\diagbox@boxa+\dp\diagbox@boxa\relax}%
  \edef\xb{\strip@pt\wd\diagbox@boxb}%
  \edef\yb{\strip@pt\dimexpr\ht\diagbox@boxb+\dp\diagbox@boxb\relax}%
  \edef\xm{\strip@pt\wd\diagbox@boxm}%
  \edef\ym{\strip@pt\dimexpr\ht\diagbox@boxm+\dp\diagbox@boxm\relax}%
%    \end{macrocode}
% 列方程,求方程系数
%    \begin{macrocode}
  \FPneg\bi\yb
  \FPadd\ci\xb\xm  \FPneg\ci\ci
  \FPmul\di\xm\yb
  \FPadd\bj\ya\ym  \FPneg\bj\bj
  \FPneg\cj\xa
  \FPmul\dj\xa\ym
%    \end{macrocode}
% 解方程
%    \begin{macrocode}
  \FPsub\u\dj\di
  \FPupn{v}{bj ci * bi cj * -}%
  \FPupn{delta}{bi dj * bj di * - cj ci - * 4 * %
    v u + copy * %
    - 2 swap root}%
  \ifdim\diagbox@wd=\z@
    \FPupn{x}{2 bj bi - delta v u - + / /}%
    \diagbox@wd=\x\p@
  \else
    \edef\x{\strip@pt\diagbox@wd}%
  \fi
  \ifdim\diagbox@ht=\z@
    \FPupn{y}{2 cj ci - delta v u + - / /}%
    \diagbox@ht=\y\p@
  \else
    \edef\y{\strip@pt\diagbox@ht}%
  \fi
  \FPsub\xxm\x\xm
  \FPsub\yym\y\ym
%    \end{macrocode}
% 画盒子
%    \begin{macrocode}
  $\vcenter{\hbox{\diagbox@pict}}$%
  \endgroup}
%    \end{macrocode}
% \end{macro}
%
% \subsection{用户命令}
%
% \begin{macro}{\diagbox}
% \changes{v2.0}{2011/11/22}{判断参数个数,选择两部分或三部分盒子。}
% 主要的用户命令。判断使用两部分还是三部分的盒子。
%    \begin{macrocode}
\newcommand\diagbox[3][]{%
  \@ifnextchar\bgroup
    {\diagbox@triple{#1}{#2}{#3}}{\diagbox@double{#1}{#2}{#3}}}
%    \end{macrocode}
% \end{macro}
%
% 以下代码用来模拟 \pkg{slashbox} 宏包的功能。
%
% 禁止读入 \pkg{slashbox}。
%    \begin{macrocode}
\expandafter\xdef\csname ver@slashbox.\@pkgextension\endcsname{9999/99/99}
%    \end{macrocode}
%
%
% \begin{macro}{\slashbox}
% 模拟 "\slashbox"。
%    \begin{macrocode}
\def\slashbox{%
  \def\diagbox@slashbox@options{dir=SW,}%
  \slashbox@}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\backslashbox}
% 模拟 "\backslashbox"。
%    \begin{macrocode}
\def\backslashbox{%
  \def\diagbox@slashbox@options{dir=NW,}%
  \slashbox@}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\slashbox@}
%    \begin{macrocode}
\newcommand\slashbox@[1][]{%
  \ifx\relax#1\relax\else
    \edef\diagbox@slashbox@options{%
      \unexpanded\expandafter{\diagbox@slashbox@options}%
      \unexpanded{width=#1,}}%
  \fi
  \slashbox@@}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\slashbox@@}
%    \begin{macrocode}
\newcommand\slashbox@@[3][]{%
  \edef\diagbox@slashbox@options{%
    \unexpanded\expandafter{\diagbox@slashbox@options}%
    \unexpanded{trim=#1,}}%
  \expandafter\diagbox\expandafter[\diagbox@slashbox@options]{#2}{#3}}
\endinput
%    \end{macrocode}
% \end{macro}
%
%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput