2

I am attaching two .pdf documents to my main document, which is written in LyX. I would like that the titles of them appeared at the end of the table of contents.

So far, I've been successful in adding them by inserting with ERT

\addcontentsline{toc}{chapter}{Additional document 1}

and changing the page count using e.g.

\setcounter{page}{150}

However, if I want to add two attachments:

\setcounter{page}{104}  
\addcontentsline{toc}{chapter}{Additional doc 1}
\setcounter{page}{154}
\addcontentsline{toc}{chapter}{Additional doc 2}

Then both of them are listed as page 154 in the TOC.

It should be noted that I am using this template, and adding the ERT under the Appendix box in the main lyx file.

enter image description here

Which compiles fine (but does not have the correct page numbers)

Any advice is welcome.

4
  • This can't work. \addcontentsline is "executed" at shipout time, at the end of the page. How are you attaching the pdf? With \includepdf`? Aug 3, 2017 at 15:21
  • @Ulrike Fischer. I was planning on just manually attaching it using preview. Hence the need for manual control of page numbers. I am using this template and adding the above lines under the Appendix. It works, but, as said, the page numbers are identical.
    – tmo
    Aug 3, 2017 at 15:51
  • 1
    The commands must be on different pages. So you need something like \newpage \mbox{} <your code> for each of them. Aug 3, 2017 at 16:22
  • @UlrikeFischer do you want to write an answer?
    – scottkosty
    Aug 8, 2017 at 22:09

1 Answer 1

0

\addcontentsline is "executed" at shipout time when a page is written to the pdf. If you want them to refer to different pages the commands must be on different pages too. So one way to do it is to use

      \newpage \mbox{} <your code> 

for each of them.

Another possibility which produce less empty pages is this here. The additional code musst be at the end of document. If you are using packages which needs an unrobust \thepage at the end of the document like lastpage it will break them (but lastpage doesn't make much sense in your setup anyway).

\documentclass{article}
\usepackage{etoolbox}

\begin{document}
\tableofcontents

\section{abc}

\newpage\section{cde}

\newpage % newpage before making thepage robust!!
\mbox{}  % force a shipout 
\robustify{\thepage} % avoid that \thepage expands directly
\addtocontents{toc}{\protect\renewcommand\thepage{123}}
\addcontentsline{toc}{section}{Additional document 1}
\addtocontents{toc}{\protect\renewcommand\thepage{134}}
\addcontentsline{toc}{section}{Additional document 2}
\addtocontents{toc}{\protect\renewcommand\thepage{127}}
\addcontentsline{toc}{section}{Additional document 3}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .