如何在LaTeX中实现以下目录格式
作者查阅了很多包的说明,勉强做出一点形式,但是并没有完全解决这个问题,现在给出一种定制的目录格式,涉及到etoolbox包的一些打补丁挂钩子的方法:
\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}
未解决的问题是无法做到将目录中的章名称居中用带颜色的盒子包住,退而求其次,画了一整条带子。
发表评论 取消回复