LyXHow to paginate sections of an inserted pdf-document

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
Edulis
Posts: 16
Joined: Thu May 26, 2011 10:38 pm

How to paginate sections of an inserted pdf-document

Post by Edulis »

I have inserted several pdf-articles in my document.
Each article has their sections and subsections.
I pretend that each section appears in the TOC with their respective page.

Previous to each article if I add this one,
\addcontentsline{toc}{section}{whatever you want to appear},
these sections appear in the TOC, but all the sections-subsections of the same article appear with the same page.

Is there any way to relate one section with the corresponding page?
How could I paginate the following example:

"Introduction of the chapter... (pp.1-6)
(start of pdf document)
section 1 (p. 7)
subsection 1.1 (p. 7)
subsection 1.2 (p. 8)
Section 2 (p. 8)
(...)"
Last edited by Edulis on Mon Jun 06, 2011 6:19 pm, edited 1 time in total.

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

5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

How to paginate sections of an inserted pdf-document

Post by 5gon12eder »

I don't know exactly about the internals but it seems to me that LaTeX is not aware of the space that the included PDFs need. So one solution is to tell LaTeX about "page breaks" by inserting \clearpage commands.

In the following example, I include pages 2 and 3 from the clsguide into a document with the sections showing up correctly in the TOC. However, usually the page numbering from the included PDF won't match and the result might be distracting.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{pdfpages}

\begin{document}
  \tableofcontents
  
  \section{Some Stuff of My Own}
  Text I have written myself\dots

  \subsection{Something Else}
  More text I have written myself\dots

  \clearpage
  \addcontentsline{toc}{section}{Introduction \emph{(from the clsguide)}}
  \addcontentsline{toc}{subsection}{Writeing classes and packages for \LaTeXe}
  \includepdf[page=2]{clsguide}
  \clearpage
  \addcontentsline{toc}{subsection}{Overview}
  \addcontentsline{toc}{subsection}{Further information}
  \includepdf[page=3]{clsguide}

  \section{Again my Own Stuff}
  And my own text\dots
\end{document}
Best
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

How to paginate sections of an inserted pdf-document

Post by 5gon12eder »

Update: Sorry, the correct option to pdfpages is pages rather than page but it seems to be understood as a common misspelling...
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
Edulis
Posts: 16
Joined: Thu May 26, 2011 10:38 pm

Re: How to paginate sections of an inserted pdf-document

Post by Edulis »

It works perfectly.

Thanks a lot, 5gon12eder.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

How to paginate sections of an inserted pdf-document

Post by frabjous »

I would use separate includepdf commands for each section, and put the addtocontents stuff in using the pagecommand* option for includepdf. See the pdfpages manual. Clearpage and \addtocontents before the includepdf command might work too.
Post Reply