作者Ninerh (小九)
看板LaTeX
标题[问题] \addtocontents 编译问题
时间Wed Aug 10 20:08:06 2011
各位高手大家好,小弟又来请教了,
这次问题是有关 \addtocontents 这个命令
我想在 toc 的最後加上 附件一 的字样,但
不要编号及页码,因此参考版上 po 文,加了
这一行
\addtocontents{toc}{\contentsline{chapter}{\numberline{}附件一}{}}%
可是在 XeLeTeX 下编译,会出现以下错误
! Argument of \contentsline has an extra }.
<inserted text>
\par
l.174 ...sline{chapter}{\numberline{}附件一}{}}
%
指出 \contentsline 多了个 } ,可是我怎麽看
都找不出是多那一个,曾试着从最右边拿掉一个 }
但会编译失败,请各位高手帮小弟看看,到底原因
是出在那里呢?附上原始码,请参考。
谢谢,感激不尽。
=====原始码 ==========
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
%
\documentclass[12pt,a4paper,twoside]{report}
\setcounter{secnumdepth}{3} %设定章节层级至 1.1.1.1
\setcounter{tocdepth}{3}
%
\usepackage{amsmath, amsthm, amssymb, txfonts, upgreek, amsbsy, mathrsfs}
\usepackage{fontspec}
\usepackage[a4paper,top=3.0cm,bottom=2.54cm,left=2cm,right=2cm,bindingoffset=1cm]{geometry} % 边界设定,bindingoffset表示装订边
\usepackage[unicode]{hyperref} % 为 pdf 设定页签,开启 pdf 档案检视时左侧会有 bookmark 可用
\usepackage{type1cm} % 使 Type1 字型可以无段放大缩小
\usepackage{graphicx} % 可直接插入图片
\usepackage{float}
\usepackage{caption}
\usepackage{indentfirst} % 首段缩排
\usepackage{url} % 文稿中出现的 \url{网址} 能够随文断行
\usepackage{natbib} % 增加更多文献引用细节功能
\bibpunct{(}{)}{;}{a}{,}{,}
\usepackage{fancyhdr} % 设定页首页尾用的套件
\usepackage{titlesec, titletoc}
\usepackage{appendix}
\usepackage{ifthen}
%
%======================================================================
%% use xeCJK
\usepackage[BoldFont,SlantFont,CJKnumber,CJKchecksingle]{xeCJK}
\usepackage{xCJKnumb}
\setCJKmainfont{BiauKai}%{标楷体}
\setromanfont{Times New Roman}
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt
%
\newboolean{isAppendix}
\setboolean{isAppendix}{false}
%
%\titleformat{\chapter}{\centering\Huge\bfseries}{第\,\xCJKnumber{\thechapter}\,章}{1em}{} %设定章标题 (\chapter) 格式
%
\titleformat{\chapter}% %设定章标题 (\chapter) 格式
{\centering\Huge\bfseries}{%
\ifthenelse{\boolean{isAppendix}}%
{附件\thechapter}%
{第\,\xCJKnumber{\thechapter} \,章}%
}{1em}{}
%
\titlespacing{\chapter}{0pt}{0em}{2em} %设定章标题 (\chapter)上下间距
%
\titlecontents{chapter}[0em]
{}{\normalfont\normalsize\bfseries\makebox[4.1em][l]
{第\xCJKnumber{\thecontentslabel}章}}{}
{\titlerule*[0.7pc]{.}\contentspage}
%
%
%========================================================================
%
\renewcommand{\contentsname}{目\,\,\,录}
\renewcommand{\figurename}{图}
\renewcommand{\tablename}{表}
\renewcommand{\listfigurename}{图目录}
\renewcommand{\listtablename}{表目录}
\renewcommand{\bibname}{参考文献}
%
% Redefine the second level of Enumerate
\renewcommand{\theenumii}{(\arabic{enumii})} % (1) (2) (3) ...
\renewcommand{\labelenumii}{\theenumii}
% third level
\renewcommand{\theenumiii}{\Alph{enumiii}、} % A, B, C...
\renewcommand{\labelenumiii}{\theenumiii}
%
\def\bibpreamble{\protect\addcontentsline{toc}{chapter}{参考文献}} %纳入参考文献
%
%==========================================================
\pagestyle{fancy} % 设定页首页尾
\renewcommand{\chaptermark}[1]{\markboth{}{}}
%
%== 设定标题页出现页首页尾
\fancypagestyle{plain}{%
\fancyhf[]{}
\fancyhead[LE,RO]{系统扩增开发\\工作计画书}
\fancyhead[LO,RE]{}
\fancyfoot[C]{\small\thepage}
}
%
% == 设定本文页首页尾
\fancyhf[]{}
\fancyhead[LE,RO]{系统扩增开发\\工作计画书}
\fancyhead[LO,RE]{}
\fancyfoot[C]{\small\thepage}
%\renewcommand{\headrule}{\hrule width\headwidth height\1pt}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
%
%
%
%======================================================
%====== 开始本文 ========================================
\begin{document}
%
\pagenumbering{roman}
\tableofcontents
\listoffigures
\listoftables
\clearpage
%
% 正文开始的环境设定
% ================================================================================
\pagenumbering{arabic} % 页码改以阿拉伯数字表示
\captionsetup{labelsep=quad} %修改图表号,拿掉冒号, eg. 图1.1
\fontsize{12pt}{18pt}\selectfont % 行高 1.5
%
%
%===========================================================================
% for testing
\chapter{第一名}
测试测试 test test
test test 测试测试 test test测试测试 test test测试测试 test test测试测试 test test
\section{Test 测试}
test test 测试测试 test test测试测试 test test测试测试 test test测试测试 test test
\clearpage
\section{测试 Test}
test test 测试测试 test test测试测试 test test测试测试 test test测试测试 test test
123456
ABCDFG $\alpha \beta$ 测试!测试!测试!
%
%
%======= Appendix ========================
%
\addtocontents{toc}{\contentsline{chapter}{\numberline{}附件一}{}}%
%
\end{document}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.33.24.122
1F:→ uranusjr:\protect\contentsline{... 08/10 20:18