Tex 真的是一个用起来非常舒服的排版工具(对于排版要求高的人来说),去比赛前一天放弃了markdown转pdf来生成代码模板,现学Tex(其实美赛已经用过了:P)。
推荐一个链接:TeX — Beauty and Fun,可以了解一下Tex。
我用的工具是Mac下的TexShop,排版时选择XeLaTeX。
基本模板:
% !TEX encoding = UTF-8 Unicode
documentclass[a4paper,11pt,twoside,fontset = fandol,UTF8]{ctexbook} % 页面A4纸大小,11 磅大小的字体,式样为双面,字体集为Fandol,编码为UTF8,文档类型为cTex的book(支持中文)
usepackage[a4paper,scale=0.8,hcentering,bindingoffset=8mm]{geometry} % A4纸大小,缩放80%,设置奇数页右边留空多一点
usepackage{hyperref} % 超链接
usepackage{listings} % 代码块
usepackage{courier} % 字体
usepackage{fontspec} % 字体
usepackage{fancyhdr} % 页眉页脚相关宏包
usepackage{lastpage} % 引用最后一页
usepackage{amsmath,amsthm,amsfonts,amssymb,bm} %数学
usepackage{graphicx} % 图片
usepackage{subcaption} % 图片描述
usepackage{longtable,booktabs} % 表格
setmonofont{Consolas} %设置字体为Consolas
lstset{ %设置代码块
basicstyle=footnotesize tfamily,% 基本风格
numbers=left, % 行号
numbersep=10pt, % 行号间隔
tabsize=2, % 缩进
extendedchars=true, % 扩展符号?
breaklines=true, % 自动换行
language=C++,
frame=leftline, % 框架左边竖线
xleftmargin=19pt,% 竖线左边间距
showspaces=false,% 空格字符加下划线
showstringspaces=false,% 字符串中的空格加下划线
showtabs=false, % 字符串中的tab加下划线
}
pagestyle{fancy} % 页眉页脚风格
fancyhf{} % 清空当前设置
fancyfoot[C]{ hepage / pageref{LastPage}}%页脚中间显示 当前页 / 总页数,把label{LastPage}放在最后
fancyhead[LO,RE]{ hepage}% 页眉奇数页左边,偶数页右边显示当前页
egin{document}
egin{titlepage} % 封面
centering
vspace*{aselineskip}
ule{ extwidth}{1.6pt}vspace*{-aselineskip}vspace*{2pt}
ule{ extwidth}{0.4pt}\[aselineskip]
{LARGE Algos @BY 2017\[aselineskip]small for ACM ICPC}
\[0.2aselineskip]
ule{ extwidth}{0.4pt}vspace*{-aselineskip}vspace{3.2pt}
ule{ extwidth}{1.6pt}\[aselineskip]
scshape
egin{figure}[!htb]
centering
includegraphics[width=0.3 extwidth]{icpc} % 当前tex文件同一目录下名为icpc的任意格式图片
end{figure}
vspace*{3aselineskip}
Edited by \[aselineskip] {向饿势力低头par}
{Team Large Bow to hungrY
ormalsize{at BUPT}par }
vfill
{scshape 2017} \{large BEIJING}par
end{titlepage}
ewpage % 封面背后空白页
ableofcontents % 目录
chapter{计算几何} % 第一章
setcounter{page}{1} % 这里页数从1开始计算
section{ 几何基础} % 第一节
% 代码块
egin{lstlisting}
代码内容
end{lstlisting}
% ...其它内容
end{document}
label{LastPage}
章节层次
- chapter
- section
- subsection
图片
如果需要几张图片并排显示,可用subfigure宏包。
egin{figure}[h]
centering
egin{subfigure}[h]{0.2 extwidth}
includegraphics[width= extwidth]{平移} % 名为'平移'的图片文件放在同一目录
end{subfigure}
~
egin{subfigure}[h]{0.2 extwidth}
includegraphics[width= extwidth]{缩放}
end{subfigure}
~
egin{subfigure}[h]{0.5 extwidth}
includegraphics[width= extwidth]{旋转}
end{subfigure}
\
egin{subfigure}[h]{0.8 extwidth}
includegraphics[width= extwidth]{3D绕轴翻转}
end{subfigure}
end{figure}
表格
用了longtable宏包
setlengthLTleft{0pt}
setlengthLTright{0pt}
egin{longtable}[]{@{}llll@{}}
oprule
(rcdot 2 ^ k + 1) & r & k & g abularnewline
midrule
endhead
3 & 1 & 1 & 2 abularnewline
5 & 1 & 2 & 2 abularnewline
17 & 1 & 4 & 3 abularnewline
97 & 3 & 5 & 5 abularnewline
193 & 3 & 6 & 5 abularnewline
257 & 1 & 8 & 3 abularnewline
7681 & 15 & 9 & 17 abularnewline
12289 & 3 & 12 & 11 abularnewline
40961 & 5 & 13 & 3 abularnewline
65537 & 1 & 16 & 3 abularnewline
786433 & 3 & 18 & 10 abularnewline
5767169 & 11 & 19 & 3 abularnewline
7340033 & 7 & 20 & 3 abularnewline
23068673 & 11 & 21 & 3 abularnewline
104857601 & 25 & 22 & 3 abularnewline
167772161 & 5 & 25 & 3 abularnewline
469762049 & 7 & 26 & 3 abularnewline
1004535809 & 479 & 21 & 3 abularnewline
2013265921 & 15 & 27 & 31 abularnewline
ottomrule
end{longtable}
代码
用的是listings宏包。具体配置可看wiki-Source_Code_Listings,要求多的可查阅文档
Markdown 转换到 LaTex
原来的 Markdown 的代码模板里大部分就是 ###
标题和代码块,手动加入 LaTex 里太辛苦了,用 typora 转的 LaTex 内容太复杂了,所以我写了个 c++ 程序来转:P,不过也许 python更适合写这种程序。