智朋的 LaTeX 模板

参考资料

  1. Github:Elegantbook
  2. LaTeX 工作室:浮动体环境内部内容居中的设置方法
  3. LaTeX 工作室:Elegentbook 魔改版

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
\documentclass{ctexart}
% ====目录章节设置 ====
\usepackage[center,pagestyles]{titlesec}
\usepackage{apptools}
\usepackage[toc,page,title,titletoc]{appendix}
\setcounter{secnumdepth}{5}
% ++++ 章节标题格式设置 ++++
\titleformat{\section}[hang]{\bfseries}{
\Large\bfseries{\color{structurecolor}\thesection}\enspace}{1pt}{%
\color{structurecolor}\Large\bfseries\filright}
\titleformat{\subsection}[hang]{\bfseries}{
\large\bfseries\color{structurecolor}\thesubsection\enspace}{1pt}{%
\color{structurecolor}\large\bfseries\filright}
\titleformat{\subsubsection}[hang]{\bfseries}{
\large\bfseries\color{structurecolor}\thesubsubsection\enspace}{1pt}{%
\color{structurecolor}\large\bfseries\filright}
% ====常用宏包====
\RequirePackage{makecell,lipsum,hologo,setspace}
\RequirePackage{booktabs}
\RequirePackage{multicol,multirow}
% ++++插入图片设置++++
\usepackage{graphics}
\graphicspath{{./figure/}{./figures/}{./image/}{./images/}{./graphics/}{./graphic/}{./pictures/}{./picture/}}
% ++++数学字体宏包++++
\usepackage{amsmath,mathrsfs,amsfonts,amssymb}
% ====行间距设置====
\linespread{1.3}
\renewcommand{\baselinestretch}{1.35}
% ====脚注环境设置====
\AtBeginDocument{
\setlength{\abovedisplayskip}{3pt}
\setlength{\belowdisplayskip}{3pt}
\RequirePackage[flushmargin,stable]{footmisc}
\setlength{\footnotesep}{12pt}
}
% ====设置列表环境====
\usepackage{enumerate}
\usepackage[shortlabels,inline]{enumitem}
\setlist{nolistsep}
% ====颜色设置====
\usepackage{xcolor}
\definecolor{structurecolor}{RGB}{0,120,2}
\definecolor{main}{RGB}{0,120,2}%
\definecolor{second}{RGB}{230,90,7}%
\definecolor{third}{RGB}{0,160,152}%
% ++++设置超链接的颜色++++
\definecolor{winered}{rgb}{0.5,0,0}
% ++++设置浮动体的某些主题色++++
\usepackage[font=small,labelfont={bf,color=structurecolor}]{caption}
\captionsetup[table]{skip=3pt}
\captionsetup[figure]{skip=3pt}
% ====假文宏包====
\usepackage{zhlipsum}
\usepackage{lipsum}
% ====字体设置====
\usepackage{xeCJK}
\setmainfont{Times New Roman}
% ====设置页边距 ====
\usepackage{geometry}
\geometry{
a4paper,
top=25.4mm, bottom=25.4mm,
headheight=2.17cm,
headsep=4mm,
footskip=12mm
}
% ====设置参考文献格式 ====
\usepackage[sort&compress]{natbib}
\setlength{\bibsep}{0.0pt}
\def\bibfont{\footnotesize}
% ====设置页眉页脚 ====
\usepackage{fancyhdr}
\fancyhf{}
\fancyfoot[c]{\color{structurecolor}\scriptsize\thepage}
\newcommand{\citshape}{\kaishu}
\fancyhead[R]{\color{structurecolor}--\;\thepage\;--}
\fancyhead[L]{\color{structurecolor}\citshape\rightmark}
% ++++ 设置页眉页脚 ++++
\renewcommand{\headrule}{\color{structurecolor}\hrule width\textwidth}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{1pt}
% \renewcommand{\headrule}{}
\fancypagestyle{plain}{\renewcommand{\headrulewidth}{0pt}\fancyhf{}\renewcommand{\headrule}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\, #1}{} }
%\renewcommand{\chaptermark}[1]{\markboth{\chaptername \, #1\,}{}}
% ====设置公式环境 ====
\numberwithin{equation}{section}
% ====自定义环境 ====
% +++++ note环境 +++++
\newcommand{\notename}{笔记}
\usepackage{bbding,manfnt} % 一些图标,如 \dbend
\newenvironment{note}{
\par\noindent\makebox[-3pt][r]{
\scriptsize\color{red!90}\textdbend\quad}
\textbf{\color{second}\notename} \citshape}{\par}
% +++++ introduction环境 +++++
\newcommand{\introductionname}{内容提要}
\usepackage{multicol}
\usepackage[most]{tcolorbox}
\tcbset{
introductionsty/.style={
enhanced,
breakable,
colback=structurecolor!10,
colframe=structurecolor,
fonttitle=\bfseries,
colbacktitle=structurecolor,
fontupper=\citshape,
attach boxed title to top center={yshift=-3mm,yshifttext=-1mm},
boxrule=0pt,
toprule=0.5pt,
bottomrule=0.5pt,
top=8pt,
before skip=8pt,
sharp corners
},
}
\newenvironment{introduction}[1][\introductionname]{
\begin{tcolorbox}[introductionsty,title={#1}]
\begin{multicols}{2}
\begin{itemize}[label=\textcolor{structurecolor}{\upshape\scriptsize\SquareShadowBottomRight}]}{
\end{itemize}
\end{multicols}
\end{tcolorbox}}
% ====浮动体环境设置:自动居中小一号字 ====
\usepackage{xpatch}
\makeatletter
\xpatchcmd\@floatboxreset{\normalsize}{\centering\small}{}{}
\makeatother
% ====文档超链接设置 ====
\usepackage{hyperref}
\hypersetup{
breaklinks,
unicode,
linktoc=all,
bookmarksnumbered=true,
bookmarksopen=true,
pdfkeywords={Coffeelize},
colorlinks,
linkcolor=winered,
citecolor=winered,
urlcolor=winered,
plainpages=false,
pdfstartview=FitH,
pdfborder={0 0 0},
linktocpage
}
% ==== 代码块样式设置 ====
\usepackage{listings}
\renewcommand{\ttdefault}{cmtt}
\lstdefinestyle{mystyle}{
basicstyle=%
\ttfamily
\lst@ifdisplaystyle\small\fi
}

\lstset{basicstyle=\ttfamily,style=mystyle,breaklines=true}

\definecolor{lightgrey}{rgb}{0.9,0.9,0.9}
\definecolor{frenchplum}{RGB}{190,20,83}
\lstset{language=[LaTeX]TeX,
texcsstyle=*\color{winered},
numbers=none,
mathescape,
breaklines=true,
keywordstyle=\color{winered},
commentstyle=\color{gray},
emph={elegantpaper,fontenc,fontspec,xeCJK,FiraMono,xunicode,newtxmath,figure,fig,image,img,table,itemize,enumerate,newtxtext,newtxtt,ctex,microtype,description,times,booktabs,tabular,PDFLaTeX,XeLaTeX,type1cm,BibTeX,device,color,mode,lang,amsthm,tcolorbox,titlestyle,cite,ctex,listings,base,math,scheme,toc,esint,chinesefont,amsmath,bibstyle,gbt7714,natbib},
emphstyle={\color{frenchplum}},
morekeywords={DeclareSymbolFont,SetSymbolFont,toprule,midrule,bottomrule,institute,version,includegraphics,setmainfont,setsansfont,setmonofont ,setCJKmainfont,setCJKsansfont,setCJKmonofont,RequirePackage,figref,tabref,email,maketitle,keywords,definecolor,extrainfo,logo,cover,subtitle,appendix,chapter,hypersetup,mainmatter,frontmatter,tableofcontents,elegantpar,heiti,kaishu,lstset,pagecolor,zhnumber,marginpar,part,equote,marginnote,bioinfo,datechange,listofchange,lvert,lastpage,songti,heiti,fangsong,setCJKfamilyfont,textbf},
frame=single,
tabsize=2,
rulecolor=\color{structurecolor},
framerule=0.2pt,
columns=flexible,
% backgroundcolor=\color{lightgrey}
}

\begin{document}
% ==== frontmatter ====
\title{这是智朋的自定义模板}
\author{Coffeelize}
\tableofcontents
\clearpage
% ====正文开始 ====
% ++++ mainmatter ++++

\textcolor{main}{\lipsum[1]}
\textcolor{second}{\zhlipsum[1]}
\textcolor{third}{\zhlipsum[1]}

\section{列表环境示例}
\begin{enumerate}
\item first
\item second\footnote{这是一个脚注测试}
\item third
\end{enumerate}
有序列表,参数说明如下:
\begin{enumerate}
\item 最大序号:用于测定文献列表中文献序号的最大宽度,如果你是10以内的参考文献,那就用9,超过10小于100那就填99.
\item 文献序号:可选参数,用于设定该条文献在参考文献列表中的序号。
\item 检索名:为该文献信息起的简短名称,
\item 文献信息:就是参考文献内容了。
\end{enumerate}
\section{图片环境示例}
\begin{figure}
\includegraphics{example-image-A}
\caption{这是一张实例图片}
\end{figure}
\subsection{这是一个二级标题}
\zhlipsum[1-2]
\begin{note}
这里其实容易出问题的是图片大学不一样怎么版,通常我的解决办法是,从一开始就把两图片的大小设置成一样的,或者通过改参数实现。关于参数如何改,多改改就用经验了!O(∩\_∩)O
\end{note}

\subsubsection{这是一个三级标题}

一下是一个章节的内容摘要
\begin{introduction}
\item 参考文献
\item 交叉引用
\item 代码框设计
\item 网址链接
\end{introduction}

\begin{lstlisting}
\begin{figure}[H]
\centering
\includegraphics[width=0.45\linewidth]{welt1.jpg}
%插入的第一个图片
\includegraphics[width=0.45\linewidth]{welt.jpg}
%插入的第二张图片
\caption{紫罗兰永恒花园}
\end{figure}
\end{lstlisting}

\end{document}

输出 PDF

智朋的Latex模板_页面_1.jpg
智朋的Latex模板_页面_2.jpg
智朋的Latex模板_页面_3.jpg
智朋的Latex模板_页面_4.jpg

coffeelize.sty

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
%  ====目录章节设置 ====
\usepackage[center,pagestyles]{titlesec}
\usepackage{apptools}
\usepackage[toc,page,title,titletoc]{appendix}
\setcounter{secnumdepth}{5}
% ++++章节标题格式设置++++
\titleformat{\section}[hang]{\bfseries}{
\Large\bfseries{\color{structurecolor}\thesection}\enspace}{1pt}{%
\color{structurecolor}\Large\bfseries\filright}
\titleformat{\subsection}[hang]{\bfseries}{
\large\bfseries\color{structurecolor}\thesubsection\enspace}{1pt}{%
\color{structurecolor}\large\bfseries\filright}
\titleformat{\subsubsection}[hang]{\bfseries}{
\large\bfseries\color{structurecolor}\thesubsubsection\enspace}{1pt}{%
\color{structurecolor}\large\bfseries\filright}
% ====常用宏包====
\RequirePackage{makecell,lipsum,hologo,setspace}
\RequirePackage{booktabs}
\RequirePackage{multicol,multirow}
% ++++插入图片设置++++
\usepackage{graphics}
\graphicspath{{./figure/}{./figures/}{./image/}{./images/}{./graphics/}{./graphic/}{./pictures/}{./picture/}}
% ++++数学字体宏包++++
\usepackage{amsmath,mathrsfs,amsfonts,amssymb}
% ====行间距设置====
\linespread{1.3}
\renewcommand{\baselinestretch}{1.35}
% ====脚注环境设置====
\AtBeginDocument{
\setlength{\abovedisplayskip}{3pt}
\setlength{\belowdisplayskip}{3pt}
\RequirePackage[flushmargin,stable]{footmisc}
\setlength{\footnotesep}{12pt}
}
% ====设置列表环境====
\usepackage{enumerate}
\usepackage[shortlabels,inline]{enumitem}
% ====颜色设置====
\usepackage{xcolor}
\definecolor{structurecolor}{RGB}{0,120,2}
\definecolor{main}{RGB}{0,120,2}%
\definecolor{second}{RGB}{230,90,7}%
\definecolor{third}{RGB}{0,160,152}%
% ++++设置超链接的颜色++++
\definecolor{winered}{rgb}{0.5,0,0}
% ++++设置浮动体的某些主题色++++
\usepackage[font=small,labelfont={bf,color=structurecolor}]{caption}
\captionsetup[table]{skip=3pt}
\captionsetup[figure]{skip=3pt}
% ====假文宏包====
\usepackage{zhlipsum}
\usepackage{lipsum}
% ====字体设置====
\usepackage{xeCJK}
\setmainfont{Times New Roman}

% ====设置页边距 ====
\usepackage{geometry}
\geometry{
a4paper,
top=25.4mm, bottom=25.4mm,
headheight=2.17cm,
headsep=4mm,
footskip=12mm
}
% ====设置参考文献格式 ====
\usepackage[sort&compress]{natbib}
\setlength{\bibsep}{0.0pt}
\def\bibfont{\footnotesize}
% ====设置页眉页脚 ====
\usepackage{fancyhdr}
\fancyhf{}
\fancyfoot[c]{\color{structurecolor}\scriptsize\thepage}
\newcommand{\citshape}{\kaishu}
\fancyhead[R]{\color{structurecolor}--\;\thepage\;--}
%\fancyhead[L]{\color{structurecolor}\citshape\rightmark}
% ++++ 设置页眉页脚 ++++
\renewcommand{\headrule}{\color{structurecolor}\hrule width\textwidth}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{1pt}
% \renewcommand{\headrule}{}
\fancypagestyle{plain}{\renewcommand{\headrulewidth}{0pt}\fancyhf{}\renewcommand{\headrule}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\, #1}{} }
%\renewcommand{\chaptermark}[1]{\markboth{\chaptername \, #1\,}{}}
% ====设置公式环境 ====
\numberwithin{equation}{section}
% ====自定义环境====
% +++++note环境+++++
\newcommand{\notename}{笔记}
\usepackage{bbding,manfnt} % 一些图标,如 \dbend
\newenvironment{note}{
\par\noindent\makebox[-3pt][r]{
\scriptsize\color{red!90}\textdbend\quad}
\textbf{\color{second}\notename} \citshape}{\par}
% +++++introduction环境+++++
\newcommand{\introductionname}{内容提要}
\usepackage{multicol}
\usepackage[most]{tcolorbox}
\tcbset{
introductionsty/.style={
enhanced,
breakable,
colback=structurecolor!10,
colframe=structurecolor,
fonttitle=\bfseries,
colbacktitle=structurecolor,
fontupper=\citshape,
attach boxed title to top center={yshift=-3mm,yshifttext=-1mm},
boxrule=0pt,
toprule=0.5pt,
bottomrule=0.5pt,
top=8pt,
before skip=8pt,
sharp corners
},
}
\newenvironment{introduction}[1][\introductionname]{
\begin{tcolorbox}[introductionsty,title={#1}]
\begin{multicols}{2}
\begin{itemize}[label=\textcolor{structurecolor}{\upshape\scriptsize\SquareShadowBottomRight}]}{
\end{itemize}
\end{multicols}
\end{tcolorbox}}
% ====浮动体环境设置:自动居中小一号字====
\usepackage{xpatch}
\makeatletter
\xpatchcmd\@floatboxreset{\normalsize}{\centering\small}{}{}
\makeatother
% ====文档超链接设置 ====
\usepackage{hyperref}
\hypersetup{
breaklinks,
unicode,
linktoc=all,
bookmarksnumbered=true,
bookmarksopen=true,
pdfkeywords={Coffeelize},
colorlinks,
linkcolor=winered,
citecolor=winered,
urlcolor=winered,
plainpages=false,
pdfstartview=FitH,
pdfborder={0 0 0},
linktocpage
}
% ====代码块样式设置====
\usepackage{listings}
\renewcommand{\ttdefault}{cmtt}
\lstdefinestyle{mystyle}{
basicstyle=%
\ttfamily
\lst@ifdisplaystyle\small\fi
}

\lstset{basicstyle=\ttfamily,style=mystyle,breaklines=true}

\definecolor{lightgrey}{rgb}{0.9,0.9,0.9}
\definecolor{frenchplum}{RGB}{190,20,83}
\lstset{language=[LaTeX]TeX,
texcsstyle=*\color{winered},
numbers=none,
mathescape,
breaklines=true,
keywordstyle=\color{winered},
commentstyle=\color{gray},
emph={elegantpaper,fontenc,fontspec,xeCJK,FiraMono,xunicode,newtxmath,figure,fig,image,img,table,itemize,enumerate,newtxtext,newtxtt,ctex,microtype,description,times,booktabs,tabular,PDFLaTeX,XeLaTeX,type1cm,BibTeX,device,color,mode,lang,amsthm,tcolorbox,titlestyle,cite,ctex,listings,base,math,scheme,toc,esint,chinesefont,amsmath,bibstyle,gbt7714,natbib},
emphstyle={\color{frenchplum}},
morekeywords={DeclareSymbolFont,SetSymbolFont,toprule,midrule,bottomrule,institute,version,includegraphics,setmainfont,setsansfont,setmonofont ,setCJKmainfont,setCJKsansfont,setCJKmonofont,RequirePackage,figref,tabref,email,maketitle,keywords,definecolor,extrainfo,logo,cover,subtitle,appendix,chapter,hypersetup,mainmatter,frontmatter,tableofcontents,elegantpar,heiti,kaishu,lstset,pagecolor,zhnumber,marginpar,part,equote,marginnote,bioinfo,datechange,listofchange,lvert,lastpage,songti,heiti,fangsong,setCJKfamilyfont,textbf},
frame=single,
tabsize=2,
rulecolor=\color{structurecolor},
framerule=0.2pt,
columns=flexible,
% backgroundcolor=\color{lightgrey}
}

Java 代码高亮

参考资料:Listings Highlight Java Annotations - TeX - LaTeX Stack Exchange

将以下代码添加到 coffeelize.sty 文件末尾即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
%%% Java代码高亮
\usepackage[T1]{fontenc}
\usepackage{inconsolata}
\definecolor{pblue}{rgb}{0.13,0.13,1}
\definecolor{pgreen}{rgb}{0,0.5,0}
\definecolor{pred}{rgb}{0.9,0,0}
\definecolor{pgrey}{rgb}{0.46,0.45,0.48}
\lstset{language=Java,
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
breakatwhitespace=true,
commentstyle=\color{pgreen},
keywordstyle=\color{pblue},
stringstyle=\color{pred},
basicstyle=\ttfamily,
moredelim=[il][\textcolor{pgrey}]{$$},
moredelim=[is][\textcolor{pgrey}]{\%\%}{\%\%}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\begin{lstlisting}
class Solution {
public int removeElement(int[] nums, int val) {
int slow = 0;
int fast = 0;
for (fast = 0; fast < nums.length; fast++) {
//快指针指向的不是目标元素
if (nums[fast] != val) {
// 1、将快指针指向的元素赋值给慢指针位置
// 2、赋值完成后,slow++,慢指针向前移动一个位置
nums[slow++] = nums[fast];
}
}
return slow;
}
}
\end{lstlisting}

06-Java语法高亮.png