My Custom Latex Style File (.sty)

Introduction

In this post, I’m sharing my custom LaTeX .sty file, which I regularly use in my projects. This .sty file includes settings and macros for biblatex with biber, custom TikZ symbols, and more.

You can download the .sty file or copy the relevant parts below.

Usage Instructions

To use this style file (.sty) in your LaTeX projects, add the following line in the preamble:

1
\usepackage{mycustomstyle}

Additionally, if you would like to use biblatex, please include your .bib file (e.g., the name referenceBitex.bib) and add one line as below in the preamable.

1
2
3
4
% ===============================
% Citation and bibliography commands
% ===============================
\addbibresource{referenceBitex.bib} % Add bibliography file

Custom .Sty File

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
% biblatexCitationCusomisedTikz.sty
\ProvidesPackage{mystyle}[2024/10/16 Personal Style Package by YX]

% ===============================
% Load essential packages
% ===============================
\RequirePackage[american]{babel} % Language support
\RequirePackage[utf8]{inputenc} % UTF-8 encoding
\RequirePackage{csquotes} % Context-sensitive quotation marks

% ===============================
% Bibliography using biblatex
% - Uses biber backend
% - APA style
% - Configured for specific citation settings
% ===============================
\RequirePackage[
backend=biber, % Specify biber as backend
style=apa, % Use APA citation style
natbib=true, % Enable natbib compatibility
sorting=ynt, % Sort by year, name, title
sortcites=true, % Sort citations within one command
maxcitenames=2, % Maximum number of names in citations
date=year, % Only display year in citations
uniquename=false, % Do not distinguish authors by first names
uniquelist=false % Do not distinguish lists by first names
]{biblatex}
\DeclareLanguageMapping{american}{american-apa} % Set language mapping for APA

% ===============================
% Remove certain fields from bibliography
% - DOI, URL, ISSN, etc.
% ===============================
\DeclareFieldFormat{doi}{} % Remove DOI field
\DeclareFieldFormat{url}{} % Remove URL field
\DeclareFieldFormat{issn}{} % Remove ISSN field
%\DeclareFieldFormat{urldate}{} % (Optional) Disable URL date
%\DeclareFieldFormat{version}{} % (Optional) Disable version field

% ===============================
% Hyperref for clickable links
% ===============================
\RequirePackage{hyperref} % Enable hyperlinks
\hypersetup{
colorlinks=true, % Enable colored links
linktoc=all, % Make table of contents fully linked
citecolor=black, % Set citation link color to black
filecolor=black, % Set file link color to black
linkcolor=black, % Set hyperlink color to black
urlcolor=black % Set URL link color to black
}

% ===============================
% Cleveref for enhanced cross-referencing
% - Customize names of references
% ===============================
\RequirePackage[capitalize]{cleveref} % Capitalize cref references
\crefname{figure}{Figure}{Figures} % Custom name for figures

% ===============================
% Custom commands for references
% ===============================
\newcommand{\seecref}[1]{(see \cref{#1})} % Custom "see cref"
\newcommand{\cfcref}[1]{(cf. \cref{#1})} % Custom "cf. cref"
\newcommand{\figref}[1]{Figure~\ref{#1}} % Custom "Figure" reference

% ===============================
% Math symbols and utilities
% ===============================
\RequirePackage{upgreek} % Upright Greek symbols

% ===============================
% Custom colors (for plots or other uses)
% ===============================
\RequirePackage{tikz} % Enable TikZ for drawing
\definecolor{blue1}{rgb}{0.1216,0.4667,0.7059}
\definecolor{red1}{rgb}{0.8392,0.1529,0.1569}
\definecolor{brown1}{RGB}{140,86,76}
\definecolor{green1}{RGB}{43,160,43}
\definecolor{blue2}{RGB}{66,146,198}
\definecolor{magenta2}{RGB}{223,62,155}
\definecolor{orange2}{RGB}{239,102,71}
\definecolor{red2}{rgb}{0.9373,0.3961,0.2824}
\definecolor{magenta3}{rgb}{0.8902,0.4667,0.7608}
\definecolor{grey1}{rgb}{0.5,0.5,0.5}
\definecolor{delta1}{rgb}{0.8431,0.1882,0.1216}
\definecolor{delta2}{rgb}{0.6824,0.0039,0.4941}
\definecolor{delta3}{rgb}{0.1294,0.4431,0.7098}
\definecolor{orange1}{RGB}{255,127,14}



% ===============================
% Custom TikZ commands for shapes and symbols
% ===============================
\DeclareRobustCommand{\plusdefined}[1]{
\begin{tikzpicture}
\draw[line width=#1] (0,0) -- (0.50em,0);
\draw[line width=#1] (0.275em,0.275em) -- (0.275em,-0.275em);
\end{tikzpicture}
}

\DeclareRobustCommand{\fillddiamondColor}[2]{
\begin{tikzpicture}[line width=#1]
\node[inner sep=0pt, diamond, minimum size=0.55em, draw=none,fill=#2] (diamond) {};
\end{tikzpicture}
}

\DeclareRobustCommand{\filldsquareColor}[2]{
\begin{tikzpicture}[line width=#1]
\node[inner sep=0pt, minimum size=0.55em, draw=none,fill=#2] (square) {};
\end{tikzpicture}
}

\DeclareRobustCommand{\crossdefined}[1]{
\begin{tikzpicture}
\node[inner sep=0pt] (cross) at (0,0) {
\begin{tikzpicture}
\draw[line width=#1] (0,0) -- (0.3525em,-0.3525em);
\draw[line width=#1] (0,-0.3525em) -- (0.3525em,0);
\end{tikzpicture}
};
\end{tikzpicture}
}

\DeclareRobustCommand{\filluptriangle}[2]{
\begin{tikzpicture}[line width=#1]
\draw[fill=#2, draw = #2, line width=#1]
(0,0) -- ++(0.55em,0) -- ++(-0.275em,0.55em) -- cycle;
\end{tikzpicture}
}

\DeclareRobustCommand{\uptriangle}[2]{
\begin{tikzpicture}
\node[inner sep=0pt] (triangle) at (0,0) {
\begin{tikzpicture}
\fill[line width = #1,color = #2,fill = none,draw = #2] (0,0) -- ++(0.55em,0) -- ++(-0.275em,0.55em) -- cycle;
\end{tikzpicture}
};
\end{tikzpicture}
}

\DeclareRobustCommand{\downtriangle}[2]{
\begin{tikzpicture}
\node[inner sep=0pt] (triangle) at (0,0) {
\begin{tikzpicture}
\fill[line width = #1,color = #2,fill = none,draw = #2] (0,0) -- ++(0.55em,0) -- ++(-0.275em,-0.55em) -- cycle;
\end{tikzpicture}
};
\end{tikzpicture}
}


% ===============================
% PGFPlots setup (for data plots)
% ===============================
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
%% the following commands are needed for some matlab2tikz features
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{snakes}
\usetikzlibrary{calc,positioning,shadows.blur,decorations.pathreplacing}
\usetikzlibrary{arrows,shapes}


% ===============================
% Table styling packages
% ===============================
\RequirePackage{threeparttable} % Enable table notes
\RequirePackage{booktabs} % Professional table formatting
\RequirePackage{caption} % Advanced caption control


% ===============================
% Landscape support (for wide figures or tables)
% ===============================
\RequirePackage{pdflscape} % Support for rotating pages in landscape mode


% % Make journal titles in article references clickable
% \DeclareFieldFormat[article]{journaltitle}{\href{\thefield{url}}{\textnormal{#1}}}
% % Remove quotation marks around article titles
% \DeclareFieldFormat[article]{title}{#1}

打赏
  • © 2020-2025 Yu Xia
  • Powered by Hexo Theme Ayer
    • PV:
    • UV:

Buy me a cup of coffee~

支付宝
微信