利用titlesec
, tocloft
, tikz
包定制一个目录格式
如何在LaTeX
中实现以下目录格式
我查阅了很多包的说明,勉强做出一点形式,但是并没有完全解决这个问题,现在给出一种定制的目录格式,涉及到etoolbox
包的一些打补丁挂钩子的方法: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\documentclass[openany]{ctexbook}
\usepackage{multicol,etoolbox}
\usepackage{titletoc,titlesec,xcolor}
\usepackage[hidelinks]{hyperref}
\usepackage[centering,
top=2.54cm,bottom=2.54cm,right=2.9cm,left=2.9cm,
headsep=25pt,headheight=20pt]{geometry}
\usepackage{xcolor}
\usepackage{pgfornament}
\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}
\definecolor{gray75}{gray}{0.75}
\titleformat{\chapter}% Command
[hang]% Shape
{\Huge\bfseries\color{myred}}% Format
{\protect{\color{myyellow}\thechapter\hfil}}% Label
{1em}% Sep
{}% Before-Code
[\ifnum\value{chapter}>0 \addtocontents{toc}{\protect\begin{multicols}{2}}\fi]% After-Code
\pretocmd{\chapter}{\ifnum\value{chapter}>0 \addtocontents{toc}{\protect\end{multicols}}\fi}{}{}
\AtEndDocument{\ifnum\value{chapter}>0 \addtocontents{toc}{\protect\end{multicols}}\fi}
\renewcommand\contentsname{\centerline{目录}}
\usepackage{tocloft}
\renewcommand\cftsecnumwidth{1em}
\usepackage{tikz}
\definecolor{doc}{RGB}{0,60,110}
\definecolor{myblue}{RGB}{63,200,244}
\titlecontents{chapter}[8em]
{\filcenter
\begin{tikzpicture}[remember picture, overlay]%
\draw[fill=myblue,draw=myblue, sharp corners] (-\textwidth,-.2) rectangle (\textwidth,.5);%
\pgftext[left,x=-2.7cm,y=0.2cm]{\color{black}\Large \heiti\thecontentslabel};%
\end{tikzpicture}\color{black}\large\heiti\bfseries}%
{}
{}
{}%
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\node at([shift=(-114:6)]current page.north){\pgfornament[scale=0.3,color=blue!20]{78}};
\node at([shift=(-66:6)]current page.north){\pgfornament[scale=0.3,symmetry=v,color=blue!20]{78}};
\end{tikzpicture}
\tableofcontents
\chapter{章节}
\section{bar1}
\section{bar2}
\section{bar3}
\section{bar4}
\chapter{BAR}
\section{foo1}
\section{foo2}
\section{foo3}
\section{foo4}
\end{document}
未解决的问题是无法做到将目录中的章名称居中用带颜色的盒子包住,退而求其次,画了一整条带子。