Page Layout\addtocontents error while compiling

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
niner
Posts: 7
Joined: Thu Aug 04, 2011 2:10 am

\addtocontents error while compiling

Post by niner »

Hi, I want to manually add a line into toc, and I used the code

Code: Select all

\addtocontents{toc}{\contentsline{chapter}{\numberline{}APP}{}}
But in compiling (I use XeLaTeX), I got the error message as follow.

Code: Select all

! Argument of \contentsline has an extra }.
<inserted text> 
                \par 
l.104 ...ontentsline{chapter}{\numberline{}APP}{}}
                                                  %
I've checked many times but I still can't find where is the "extra }". My code is below. Does anyone know the problem? Any comment is appreciated. Thank you.

Code: Select all

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass[12pt,a4paper,twoside]{report}
\setcounter{secnumdepth}{3} 
\setcounter{tocdepth}{3}
%
\usepackage{amsmath, amsthm, amssymb, txfonts, upgreek, amsbsy, mathrsfs}
\usepackage{fontspec}
\usepackage[a4paper,top=2.54cm,bottom=3.0cm,left=2cm,right=2cm,bindingoffset=1cm]{geometry}   
\usepackage[unicode]{hyperref} 
\usepackage{type1cm}            
\usepackage{graphicx}          
\usepackage{float}
\usepackage{caption}
\usepackage{indentfirst}       
\usepackage{url}               
\usepackage{natbib}       
\bibpunct{(}{)}{;}{a}{,}{,}
\usepackage{fancyhdr}          
\usepackage{titlesec, titletoc}
\usepackage{ifthen}
%
%======================================================================
%% use xeCJK
\usepackage[BoldFont,SlantFont,CJKnumber,CJKchecksingle]{xeCJK}
\usepackage{xCJKnumb}
\setCJKmainfont{Times New Roman}
\setromanfont{Times New Roman}
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt
%
%
\setlength{\parindent}{0.85cm}
%
%==========================================================
% define headrule and footrule style
\makeatletter
\def\headrule{{%
  \if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
  \hrule\@height\footrulewidth\@width\headwidth\vskip1pt%
  \hrule\@height\headrulewidth\@width\headwidth\vskip-\headrulewidth\vskip-4pt
}}
%
\def\footrule{{%
  \if@fancyplain\let\footrulewidth\plainfootrulewidth\fi
  \vskip-\footruleskip\vskip-\footrulewidth
  \hrule\@height\headrulewidth\@width\headwidth\vskip1pt%
  \hrule\@height\footrulewidth\@width\headwidth\vskip\footruleskip
}}
\makeatother
%
%
\pagestyle{fancy}             
\renewcommand{\chaptermark}[1]{\markboth{}{}}
%
%
\fancypagestyle{plain}{%
\fancyhf[]{}
\fancyhead[LE,RO]{Project Line 1\\Proposal}
\fancyhead[LO,RE]{}
\fancyfoot[C]{\small\thepage}
}
%
\fancyhf[]{}
\fancyhead[LE,RO]{Project Line 1\\Proposal}
\fancyhead[LO,RE]{}
\fancyfoot[C]{\small\thepage}
%
\renewcommand{\headrulewidth}{1.5pt}
\renewcommand{\footrulewidth}{0.5pt}
%
% 
\setlength{\headheight}{30pt}
%
%
%======================================================
\begin{document}
%
\pagenumbering{roman}    
%
\tableofcontents
\listoffigures
\listoftables
\clearpage
%
% ================================================================================
\pagenumbering{arabic}             
\fontsize{12pt}{18pt}\selectfont    
% 
%%===========================================================================
%
%
% for testing
\chapter{TEST 1}
\section{test test}

\chapter{TEST 2}
\section{test test test test}

%
%======= Appendix ========================
%
%\addcontentsline{toc}{chapter}{\textbf{APP}}%
\addtocontents{toc}{\contentsline{chapter}{\numberline{}APP}{}}%
%
\end{document}

Last edited by niner on Fri Aug 12, 2011 2:57 am, edited 1 time in total.
Niner@Taiwan

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

\addtocontents error while compiling

Post by Stefan Kottwitz »

Hi,

as you use hyperref, \contentsline requires one more argument, it's redefined by hyperref. If you don't provide a real argument, use {} as further argument, such as

Code: Select all

\addtocontents{toc}{\contentsline{chapter}{\numberline{}APP}{}{}}
Stefan
LaTeX.org admin
niner
Posts: 7
Joined: Thu Aug 04, 2011 2:10 am

Re: \addtocontents error while compiling

Post by niner »

Hi Stefan,

The code works. Thank you so much! :D
Niner@Taiwan
Post Reply