我需要将一些默认目录结构中不包含的内容,诸如图目录、参考文献等加入到目录中。一种方案是使用tocbibind宏包。这一方案的好处是在加入hyperref宏包下,PDF正文中目录的超链接可以正确跳转至所在页面。但是这一方案有一个问题,比如,如果我对listfigurename进行了额外的样式设计,那么这一宏包会将这种样式设计带入到目录中,而这并非是我想要的结果:如图
我希望目录中的内容保持统一的字号等风格。
另外一种方案是使用addcontentsline。这一方案的优缺点正好跟上一方案相反,即其能在目录中保持统一风格,但超链接跳转未必正常。比如点击图中的ABSTRACT(目录中所有全大写标题均由addcontentsline生成),其并不能直接跳转至Abstract所在页面,反而跳转至了PDF的首页。
所以我的问题是:能否有一个解决方案,使得同时具有以上方案的优点?
\documentclass[UTF8,a4paper]{book}
\usepackage{ctex}
\ctexset{
contentsname={%
\textit{Contents}
},
listfigurename={%
\zihao{3}\centering List of figures
},
bibname={%
References
},
}
\usepackage[nottoc]{tocbibind}
\usepackage[colorlinks=true]{hyperref}
\usepackage{tikz}
\usepackage{graphics}
\title{Name Name Name}
\author{}
\date{}
\begin{document}
\maketitle
WWW
QQQ
XXX
PPP
\newpage
\addcontentsline{toc}{chapter}{ABSTRACT} %点击PDF文件Contents中的ABSTRACT,无法正常定位到ABSTRACT实际所在页面
\centerline{\bfseries ABSTRACT}
AAABBBB
\tableofcontents
\listoffigures %tocbibind宏包虽然可以使得List of figures正确跳转,但是却会额外带着对其的样式设置
\addcontentsline{toc}{chapter}{LIST OF FIGURES}
\chapter{A}
\section{111}
\section{222}
\section{333}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-1}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-2}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-3}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-4}
\end{figure}
\chapter{B}
\section{111}
\section{222}
\section{333}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-1}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-2}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-3}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-4}
\end{figure}
\chapter{C}
\section{111}
\section{222}
\section{333}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-1}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-2}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-3}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-4}
\end{figure}
\chapter{D}
\section{111}
\section{222}
\section{333}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-1}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-2}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-3}
\end{figure}
\begin{figure}
\centering
\begin{tikzpicture}
\filldraw[fill=gray!30, draw=black] (0,0) circle [radius=1];
\end{tikzpicture}
\caption{A ball-4}
\end{figure}
\addcontentsline{toc}{chapter}{REFERENCES}
\begin{thebibliography}{9}
\bibitem{111} 1111
\bibitem{222} 222
\bibitem{333} 333
\bibitem{444} 444
\end{thebibliography}
\end{document}
你的问题描述以及提供的 mwe 都有些复杂,我大概认为你需要:
- 文档的各级标题的标题名虽然采用英文字母,但是在必要时正文中能够直接使用汉字;
- 目录中包含摘要、插图列表、参考文献等使用
\chapter*
创建的条目,且需要对这些条目的显示采用自定义内容,并且其字体风格与默认一致;- 正文中插图列表的标题名采用
三号居中
格式;- 目录中的摘要条目可以跳转到摘要页,而不是PDF首页。
对于第一条,我认为你可能有输入汉字的需要,但是可能并不喜欢 ctex
宏包默认的标题汉化风格。我的方法是改用 xeCJK
支持中文,如果你不用 XeLaTeX
,那么需要其他方法支持中文。
对于第二条,我的方法是使用 tocbibind
宏包,它默认会把章节目录、插图目录、表格目录、参考文献、索引等都加入章节目录,且不用做进一步更改,就能保持默认的字体、字距风格。
对于第三条,在 book
文类中, \listoffigures
以及 \tableofcontents
、\listoftables
、\begin{thebibliography}...\end{thebibliography}
在正文中的标题名都是主要通过 \chapter*
命令创建的,容易“改一发而动全身”。要实现同一层级的标题采用不同的字体 、字距风格,我的思路是局部重定义 \listoffigures 的定义
(用分组进行隔离,离开分组就会自动复原)。根据你的文档类,查找 book.cls
,可知 \listoffigures
命令的主要构成是:
\chapter*{\listfigurename}
由于 \chapter*
命令是依据 \chapter
命令创建的,而 \chapter
命令的定义的最后一行
\secdef\@chapter\@schapte
意思是:若采用 \chapter
命令创建标题,则使用 \@chapter
排版方案;若采用 \chapter*
命令创建标题,则使用 \@schapter
排版方案。显然,我们关注后者。查看 \@schapter
的定义:
\def\@schapter#1{\if@twocolumn
\@topnewpage[\@makeschapterhead{#1}]%
\else
\@makeschapterhead{#1}%
\@afterheading
\fi}
发现其主要依靠 \@makeschapterhead{#1}
这个命令排版 chapter* 。最后,查看 \@makeschapterhead
的定义:
\def\@makeschapterhead#1{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries #1\par\nobreak
\vskip 40\p@
}}
可知,这是 \listoffigures
命令的根源所在,要设置其格式为三号居中,只需要把格式添加在参数 #1
上,也就是说只要能够临时重定义 \@makeschapterhead
就能实现“同是 chapter* 层级的标题,但字体、字距风格不同”的效果。于是可以新定义一个命令,将这个重定义限制在分组内(最好保存原定义,或许有用)。因为涉及内部命令,所以需要更改 @
字符的类代码。总之,即:
\makeatletter
% 保存原始定义
\let\original@makeschapterhead\@makeschapterhead
% 创建封装环境
\NewDocumentCommand{\mylistoffigures}{}{%
\begingroup
\renewcommand{\@makeschapterhead}[1]{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\centering\fontsize{16bp}{16bp}\selectfont\bfseries ##1\par\nobreak%
\vskip 40\p@
}%% 根据 ctex 宏包手册代码实现第 4190 行,汉字三号字的字体尺寸为 16bp ,
}%% 但是英文字母的三号字是什么尺寸,我不太清楚。总之,你可以改成你喜欢的大小
\listoffigures
\endgroup
}
\makeatother
然后只要在正文中合适的地方,使用 \mylistoffigures
即可产生不同于 \listoffigures
的效果。
对于第四条,上面啸行老师已经给出了解决方案。其实在 tocbibind
的宏包手册中也有描述:
对此不再赘述。
效果图如下:
修改过的代码如下:
\documentclass[openany]{book}
\usepackage[papersize={15cm,20cm},margin=.5in]{geometry}
\usepackage{xeCJK}
\setCJKmainfont{SimSun}
\renewcommand{\contentsname}{\textit{Contents}}%% 重定义这些文本宏时若带有格式,会被 tocbibind 带进
\renewcommand{\listfigurename}{List of figures}%% 目录,但是目录本身是不进目录的,所以感觉不到这样做
\renewcommand{\bibname}{References}%% 的效果,可以取消 tocbibind 的选项 nottoc 查看效果
\usepackage[nottoc]{tocbibind}
%\usepackage{tocbibind}
\usepackage{tikz}
\usepackage[colorlinks=true]{hyperref}
\makeatletter
% 保存原始定义
\let\original@makeschapterhead\@makeschapterhead
% 创建封装环境
\NewDocumentCommand{\mylistoffigures}{}{%
\begingroup
\renewcommand{\@makeschapterhead}[1]{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\centering\fontsize{16bp}{16bp}\selectfont\bfseries ##1\par\nobreak%
\vskip 40\p@
}%% 根据 ctex 宏包手册代码实现第 4190 行,汉字三号字的字体尺寸为 16bp ,
}%% 但是英文字母的三号字是什么尺寸,我不太清楚。总之,你可以改成你喜欢的大小
\listoffigures
\endgroup
}
\makeatother
\begin{document}
\title{Title}\author{Author}\date{Date}\maketitle
\phantomsection
\addcontentsline{toc}{chapter}{ABSTRACT}
\centerline{\bfseries ABSTRACT}
My abstract.
\tableofcontents
\mylistoffigures
\chapter{chapter}
\section{section}\vskip7ex
\begin{figure}[h]
\centering
\tikz[scale=.75,every node/.append style={scale=.75}]
\foreach \x in {1,...,9}
\foreach \y in {1,...,9}
\draw (\x,\y) rectangle +(1,1)
node at (\x,\y) [shift={(.5,.5)}] {$\x\y$};
\caption{Some rectangles}
\end{figure}
\chapter{chapter}
\section{section}\vskip7ex
\begin{figure}[h]
\centering
\tikz[scale=.75,every node/.append style={scale=.75}]
\foreach \x in {1,...,9}
\foreach \y in {1,...,9}
\draw (\x+.5,\y-.5) circle (.5)
node at (\x,\y) [shift={(.5,-.5)}] {$\x\y$};
\caption{Some circles}
\end{figure}
\begin{thebibliography}{99}
\bibitem{1} Book A.
\bibitem{2} Book B.
\end{thebibliography}
\end{document}
maybe related in the hypererf
documentation:
我尝试对你的MWE缩了一下行...并试着结合啸行老师的做法给了一个尝试...
\documentclass[UTF8,a4paper,openany]{book} %% openany可以让你的页面少几面
\usepackage{ctex}
\ctexset{
contentsname={\textit{Contents}},
listfigurename={\zihao{3}\centering List of figures},
bibname={References},
}
\usepackage[colorlinks=true]{hyperref}
\usepackage{graphicx}
\begin{document}
WWW
QQQ
\newpage
\phantomsection
\addcontentsline{toc}{chapter}{ABSTRACT}
\centerline{\bfseries ABSTRACT}
AAA
\tableofcontents
\listoffigures
\addcontentsline{toc}{chapter}{LIST OF FIGURES}
\ExplSyntaxOn
\int_step_inline:nn {4}{%
\chapter{Chapter \int_to_Roman:n {#1}}
\section{111}
\section{222}
\section{333}
\int_step_inline:nn {4}{%
\begin{figure}
\centering
\includegraphics{example-image}
\caption{figure-{##1}}
\end{figure}
}
}
\ExplSyntaxOff
\begin{thebibliography}{9}
\bibitem{111} 1111
\bibitem{222} 222
\bibitem{333} 333
\bibitem{444} 444
\end{thebibliography}
\addcontentsline{toc}{chapter}{REFERENCES}
\end{document}
请看VCR:
这个MWE来源于我自行设计的毕业论文模板。然而这里的MWE一些设计样式其实是我随便写写的,并不是说我真的一定需要这种样式。我提问题的时候认为,我只需具体表现出将tocbibind宏包会将对listoffigures进行修改样式带入到目录中这一问题即可,并没有必要非得严格使用我在论文模板中相关样式设计。另外其实并不是说我不喜欢ctex宏集设计的样式。原因在于,我的毕业论文中,绝大部分都是英语,少部分是汉语,所以为了照应这种情况,我就利用了ctex宏集进行了英文样式设计,毕竟我之前在设计模板时,只知道利用ctexset来实现对章标题、节标题等内容的样式修改。另外MWE中出现对英文字体使用zihao{3}这种情况,则是因为学校毕业论文要求中只是针对中文写作来说的,虽然允许英文写作,但是并没有额外说明英文写作的要求如何,所以我就默认对中文写作的要求也适用于英文写作。
最后再次感谢您的回答!