-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathtitles-setup.tex
200 lines (178 loc) · 6.13 KB
/
titles-setup.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
% Copyright 2018 李文威 (Wen-Wei Li).
% Permission is granted to copy, distribute and/or modify this
% document under the terms of the Creative Commons
% Attribution 4.0 International (CC BY 4.0)
% http://creativecommons.org/licenses/by/4.0/
% 目的: 设置章节标题格式及目录的显示方式.
% 由 AJbook.cls 引入
\ProvidesFile{titles-setup.tex}[2018/03/04]
\RequirePackage[calcwidth, nobottomtitles, explicit, newparttoc, indentafter]{titlesec} % 标题格式: explicit 选项导致须在 titleformat 的 before-code 中加 #1. 选项 newparttoc 用来将各部分加入目录. indentafter: 首行一律缩进
\RequirePackage{titletoc} % 目录格式
% 目录部分: 章名除附录外仍用中文标号, 黑体显示. 以参数是否为大写拉丁字母来判定是否在附录 (烂招)
\if@AJ@traditional
\providecommand{\AJchapterttl}[1]{\IfSubStr{ABCDEFGHIJKLMNOPQRSTUVWXYZ}{#1}{附錄 #1 }{第\zhnumber{#1}章}}
\else
\providecommand{\AJchapterttl}[1]{\IfSubStr{ABCDEFGHIJKLMNOPQRSTUVWXYZ}{#1}{附录 #1 }{第\zhnumber{#1}章}}
\fi
\newlength{\BoxTtlwidth} % 用来计算各种盒子所需宽度
% 各章标题排版: \MakeChapBox{编号}{标题}, 除附录外, 各章用中文数字显示. 以参数是否为大写拉丁字母来判定是否在附录 (烂招)
\newcommand{\MakeChapBox}[2]{%
\settowidth{\BoxTtlwidth}{\AJchapterttl{#1}} % 计算宽度
\begin{tcolorbox}[ % 设置 tcolorbox
enhanced jigsaw,
skin = bicolor,
frame engine = path,
sharp corners = all,
width = 0.9\textwidth,
top = 4mm, bottom = 4mm,
sidebyside,
frame hidden,
boxrule = 0mm,
lefthand width = \BoxTtlwidth,
colupper = white,
colback = gray!80,
colbacklower = gray!10,
sidebyside align=center,
halign=center]
\AJchapterttl{#1}
\tcblower
#2
\end{tcolorbox}%
}
% 无编号标题排版: \MakeChapBox{标题}
\newcommand{\MakeChapBoxSingle}[1]{%
\begin{tcolorbox}[
enhanced,
width = 0.7\textwidth,
sharp corners = all,
top = 4mm, bottom = 4mm,
frame hidden,
boxrule = 0mm,
colback = gray!10,
halign=center]
#1
\end{tcolorbox}
}
% 各节标题排版: \MakeSectBox{文字}, 问题: 不允许断行
\newtcbox{\MakeSectBox}{
enhanced,
arc = 0pt, outer arc = 0pt,
before skip = 0pt, after skip = 0.4em, left skip = 0pt, right skip = 0pt,
top = 0pt, left = 0pt, right = 0pt, bottom = 1.5mm,
sharp corners = all,
valign=bottom,
colback = white,
colframe = white,
boxsep = 0pt, leftrule = 0pt, rightrule=0pt, toprule=0pt, bottomrule = 0pt,
overlay = { \draw[line width=1pt] (interior.south west) -- (interior.south east); }
}
% 用 titlesec 设置各章标题
\titleformat{name=\chapter}
{\filright\sffamily\CJKfamily{hei2}\bfseries\Huge} % Format
{} % Label
{0mm} % Sep
{\MakeChapBox{\thechapter}{#1}} % Before-code
[] % After-code
\titlespacing*{name=\chapter} % 设置间隔
{1pc}{*4}{1em} % {left}{before-sep}{after-sep}
\titleformat{name=\chapter, numberless}
{\filcenter\sffamily\CJKfamily{hei2}\bfseries\Huge} % Format
{} % Label
{0mm} % Sep
{\MakeChapBoxSingle{#1}} % Before-code
[{\if@mainmatter
\addcontentsline{toc}{chapter}{#1}
\markboth{#1}{}
\fi}] % After-code: 无号章如果出现在正文中, 就加入目录并相应地设置天眉.
\titlespacing*{name=\chapter, numberless} % 设置间隔
{1pc}{*4}{1em} % {left}{before-sep}{after-sep}
\titleformat{name=\section} % 各节标题
{\filleft\normalfont\sffamily\bfseries\CJKfamily{sectionfont}}
{}
{0mm}
{ \settowidth{\BoxTtlwidth}{\Huge \thesection \hspace{0.7em} \Large #1} % 首先计算宽度
\ifdim \BoxTtlwidth < \textwidth % 一般情形下调用 \MakeSectBox
\MakeSectBox{\Huge \thesection \hspace{0.7em} \Large #1}\vskip-18pt%
\else % 万一标题过长则不用 \MakeSectBox (烂招)
\Huge \underline{\thesection} \hspace{0.7em} \Large #1%
\fi %
}
[]
\titleformat{name=\section, numberless} % 各节标题: 无编号情形
{\filleft\normalfont\sffamily\bfseries\CJKfamily{sectionfont}}
{}
{0mm}
{ \settowidth{\BoxTtlwidth}{\Large #1} % 首先计算宽度
\ifdim \BoxTtlwidth < \textwidth % 一般情形下调用 \MakeSectBox
\MakeSectBox{\Large #1}\vskip-18pt%
\else % 万一标题过长则不用 \MakeSectBox (烂招)
\Large #1 %
\fi %
}
[]
\titlespacing*{name=\section} % 设置间隔
{1pc}{*1.3}{*1} % {left}{before-sep}{after-sep}
\titleformat{name=\subsection} % 各子节标题, 采取 runin 形式较美观
[runin]
{\filleft\normalfont\sffamily\bfseries\CJKfamily{sectionfont}}
{\Large\thesubsection} % Label
{3mm} % Sep
{#1} % Before-code
[] % After-code
\titleformat{name=\subsection, numberless}
[runin]
{\filleft\normalfont\sffamily\bfseries\CJKfamily{sectionfont}}
{} % Label
{0mm} % Sep
{#1} % Before-code
[] % After-code
\titlespacing*{name=\subsection} % 设置间隔
{0pt}{*1}{1em} % {left}{before-sep}{after-sep}
\titleformat{name=\subsubsection} % 次子节标题, 采取 runin 形式较美观
[runin]
{\filleft\normalfont\sffamily\bfseries\CJKfamily{sectionfont}}
{\thesubsubsection} % Label
{3mm} % Sep
{#1} % Before-code
[] % After-code
\titleformat{name=\subsubsection, numberless}
[runin]
{\filleft\normalfont\sffamily\bfseries\CJKfamily{sectionfont}}
{} % Label
{0mm} % Sep
{#1} % Before-code
[] % After-code
\titlespacing*{name=\subsubsection} % 设置间隔
{0pt}{*1}{1em} % {left}{before-sep}{after-sep}
% 部分编号汉化
\renewcommand{\thepart}{\zhnum{part}}
\titleformat{name=\part}[display] % 各部分标题
{\filcenter\sffamily\bfseries\CJKfamily{song}\Huge} % Format
{第{\thepart}部分} % Label
{1.5em} % Sep
{#1} % Before-code
[] % After-code
\titlecontents{chapter}
[0pt]
{\addvspace{1pc}\heiti}
{\contentsmargin{0pt}\large\AJchapterttl{\thecontentslabel} \quad}
{\contentsmargin{0pt}\large}
{\titlerule*[.7pc]{.}\contentspage}
\titlecontents{section}
[1.5em]
{}
{\thecontentslabel\quad}
{\thecontentslabel}
{\titlerule*[.7pc]{.}\contentspage}
\titlecontents{subsection}
[3.9em]
{\small}
{\thecontentslabel\quad}
{\ (\thecontentspage)}
{\titlerule*[.7pc]{.}\contentspage}
\titlecontents{part}
[0cm]
{\addvspace{1pc}\songti}
{\contentsmargin{0pt}\large{第{\thecontentslabel}部分}\quad}
{\large}
{\titlerule*[.7pc]{.}\contentspage}