I want to add custom lines for my appendices, produced in external software, to the table of contents. Furthermore it should be possible to specify the number of pages of any particular appendix. How can I achieve this?
As MWE I will use my best try.
\documentclass{report}
\newcommand{\append}[2]{%
\stepcounter{chapter}%
\newpage\thispagestyle{empty}\phantom{-}%
\addcontentsline{toc}{chapter}{\protect\numberline{\Alph{chapter}}{#1}}%
\newpage\addtocounter{page}{-1}\addtocounter{page}{#2}%
}
\begin{document}
\tableofcontents
\chapter{Chapter 1}
Bla bla
\chapter{Chapter 2}
Bla bla bla
\appendix
\chapter{Appendix 1}
Blah
\append{Extra 1}{2}
\append{Extra 2}{1}
\end{document}
Generated TOC:
Unfortunately to work it needs to insert a blank page for every single appendix.
How can I get rid of those extra blank pages, while keeping other traits of the \input
command?
Best Answer
Since you don't want any blank page at all to be included, because you are going to plot some big format cad drawings separately, I looked at how
\cftaddtitleline{toc}{chapter}{<text>}{<page>}
is defined in the documentation of thetocloft
package, page 49:Thus, you just have to use
\addtocontents
instead of\addcontentsline
. In order to get it displayed the same as the otherchapter
entries, you should define the title as\protect\numberline{\Alph{chapter}}#1}
, which will produce this entry in your*.toc
file:However, you cannot use
\thepage
and increment it in the following line, because all the sections will get the same number:I added a counter which is set with
\thepage
before calling\append
, and it is modified not to affect the number of the previous chapter (Appendix 1).