Skip to content

Instantly share code, notes, and snippets.

@liuchengxu
Last active October 6, 2022 15:09
Show Gist options
  • Save liuchengxu/521134d09c0173d0553111ba5e631255 to your computer and use it in GitHub Desktop.
Save liuchengxu/521134d09c0173d0553111ba5e631255 to your computer and use it in GitHub Desktop.
mostly essential packages for tex writing,tested with ctexart.
% usage: \usepackage{my_utils}
% 像正常引用宏包即可: \usepackage{my_utils}
% ctexart环境下已测试
\ProvidesPackage{tex_utils}
\usepackage{bm} % 数学公式环境中粗体效果
\usepackage{url} % 网址
\usepackage{color} % 颜色包
\usepackage{float} % 图片浮动等
\usepackage{tabularx} % 表格
\usepackage{nicefrac} % 使得1/2更好看
\usepackage{makecell} % 改变表格横线样式, Xhline;Xcline
\usepackage{setspace} % 调整行间距
\usepackage{booktabs} % 书签
\usepackage{mathrsfs} % 数学花体
\usepackage[font=small]{caption} % caption字体设置小一号
\usepackage{amsmath, amssymb, amsfonts} % 数学公式
\usepackage[super,square,compress,sort]{natbib} % 参考文献样式
\usepackage[
linesnumbered,
boxed,ruled,
commentsnumbered
]{algorithm2e} % 算法包
\usepackage[
headheight=13pt,
top=0.9cm,bottom=2.5cm,
left=3cm,right=2cm,
includehead,includefoot
]{geometry} % 页面布局
% 生成书签。同时不是使用方框标识,colorlinks使用颜色标识。如果不想使用颜色,可以改为black.
% 书签可有可无。不想用直接删除即可
% colorlinks默认为false, 即使用方框区别链接。为true时使用颜色进行区别。
\usepackage[
colorlinks=true,
linkcolor=black,
anchorcolor=black,
citecolor=black
]{hyperref}
% 页面布局, 设置页眉页脚等
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{这里可以放置页眉,其他类似}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\headwidth}{\textwidth}
\renewcommand{\footrulewidth}{0pt}
% 调整目录样式
\usepackage{titletoc} % 目录包
\titlecontents{section}[0mm]
{\fontsize{12pt}{20pt}\selectfont \CJKfamily{song}}
{\filleft\contentslabel{1em}}
{\hspace*{-1em}} % 保证摘要等对齐contentslabel的距离与此处的hspace大小相等,正负相反,即可对齐
{\titlerule*{.}\contentspage}
\titlecontents{subsection}[10mm]
{\fontsize{12pt}{20pt}\selectfont \CJKfamily{song}}
{\contentslabel{2em}}
{\hspace*{-2em}}
{\titlerule*{.}\contentspage}
\titlecontents{subsubsection}[20mm]
{\fontsize{12pt}{20pt}\selectfont \CJKfamily{song}}
{\contentslabel{3em}}
{\hspace*{-3em}}
{\titlerule*{.}\contentspage}
% 方便管理图片
\usepackage[dvips]{graphicx} % 图片包
\DeclareGraphicsExtensions{.eps,.png,.jpg} % 对于同名图片的优先顺序调用
\graphicspath{{graphics/}} % 设置图片路径为当前路径下的graphics文件夹
% argmin上下排列, \underset{\alpha}{\argmin}
\usepackage{amsopn}
% 定义数学符号
\DeclareMathOperator{\argmin}{arg\,min\,}
\DeclareMathOperator{\argmax}{arg\,max\,}
\DeclareMathOperator{\sign}{sign}
% 调整段间距,在原有基础上增大0.7em
\addtolength{\parskip}{.5em}
% 详情查阅ctexart说明文档
\ctexset{
contentsname={目\quad录},
bibname={\kaishu\zihao{5}\textbf{参考文献}}
}
% 对于一些命令进行重命名
\renewcommand{\algorithmcfname}{算法}
% 简化命令
\newcommand{\beq}{\begin{equation}}
\newcommand{\eeq}{\end{equation}}
\newcommand{\eqrefm}[2]{equation(\ref{#1}{#2})}
\newcommand{\expref}[1]{(\ref{#1})}
\newcommand{\eqrefs}[1]{equations(#1)}
\renewcommand{\eqref}[1]{equation(\ref{#1})}
\newcommand{\Eqref}[1]{Equation(\ref{#1})}
\newcommand{\figref}[1]{fig(\ref{#1})}
\newcommand{\tabref}[1]{table(\ref{#1})}
\newcommand{\figrefm}[2]{fig(\ref{#1}{#2})}
\newcommand{\secref}[1]{section(\ref{#1})}
\newcommand{\secrefs}[2]{sections(\ref{#1},\ref{#2})}
\newcommand{\chapref}[1]{chapter(\ref{#1})}
\newcommand{\exref}[1]{exercise(\ref{#1})}
\newcommand{\Exref}[1]{Exercise(\ref{#1})}
\newcommand{\exampref}[1]{example(\ref{#1})}
\newcommand{\defref}[1]{definition(\ref{#1})}
\newcommand{\procref}[1]{procedure(\ref{#1})}
\newcommand{\resref}[1]{result(\ref{#1})}
\newcommand{\remref}[1]{remark(\ref{#1})}
\renewcommand{\algref}[1]{algorithm(\ref{#1})}
\newcommand{\Algref}[1]{Algorithm(\ref{#1})}
\newcommand{\tw}{\textwidth}
\endinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment