0

I would like to include pdf files for which I used the command \includepdf[]{filename}, which works fine. Basically my whole document is made up of pdf files, so I would like to include chapter titles now. However, using only \chapter{name} gives an empty page with only the chaptertitle before the pdf-file. The title does not have to be nescessarily on top of the pdf, since I can include the titlename in the pdf, but I just want the chapter title to show in the table of contents.

3
  • You can put the chapter title into the TOC using \addcontentsline. Getting it on the right page might be a problem. Dec 24, 2019 at 15:58
  • Yeah... I indeed tried that, but since I have multiple pdf files it does not work properly. Dec 24, 2019 at 16:09
  • 1
    Do you plan to use the headers and footers from the PDF or the current document? Dec 24, 2019 at 16:42

2 Answers 2

1
  • Use option addtotoc to create entries for the TOC.
  • Do not try to feed \includepdf with \chapter, \section, ... commands. This will fail.
  • Use option picturecommand* to write something on the first page of the included PDF. (It might at least look like a section title if you use \thesection, ...)

Here is an example:

\documentclass[a4paper]{article}
\usepackage{pdfpages}
\usepackage{hyperref}

\newcommand\mytitle{}
\newcommand\doctitle[1]{\def\mytitle{#1}}

\begin{document}
\tableofcontents

\doctitle{Title AAA}
\includepdf[
  pages=-,
  addtotoc={1, section, 1, \mytitle, sec:file-1},
  picturecommand*={\put(100,700){\LARGE\thesection\ \mytitle}}
]{file-1.pdf}

\doctitle{Title BBB}
\includepdf[
  pages=-,
  addtotoc={1, section, 1, \mytitle, sec:file-2},
  picturecommand*={\put(100,700){\LARGE\thesection\ \mytitle}}
]{file-2.pdf}

\end{document}
0

This trims off the old footers and headers and replaces them with new ones. It assumes a common page layout.

\documentclass{book}
\usepackage{pdfpages}

\makeatletter
\newcommand{\mychapter}[1]% #1 = short title (TOC and header only}
 {\thispagestyle{plain}%
  \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
      \refstepcounter{chapter}%
      \typeout{\@chapapp\space\thechapter.}%
      \addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
    \else
      \addcontentsline{toc}{chapter}{#1}%
    \fi
  \else
    \addcontentsline{toc}{chapter}{#1}%
  \fi
  \chaptermark{#1}%
  \addtocontents{lof}{\protect\addvspace{10\p@}}%
  \addtocontents{lot}{\protect\addvspace{10\p@}}%
 }
\makeatother

\edef\toptrim{\the\dimexpr 1in+\topmargin+\headheight+\headsep}
\edef\bottomtrim{\the\dimexpr \paperheight-\toptrim-\textheight}

\begin{document}
\tableofcontents
\cleardoublepage% [openright] doesn't show headers
\includepdf[pages={1},pagecommand={\mychapter{Title}},clip=true,trim=0 {\bottomtrim} 0 {\toptrim}]{test6}% one page only!
\includepdf[pages={2},pagecommand={},clip=true,trim=0 {\bottomtrim} 0 {\toptrim}]{test6}
\end{document}

where test6 was created using

\documentclass{book}
\usepackage{lipsum}

\begin{document}
  \chapter{Title}
  \lipsum[1-4]
\end{document}

You must log in to answer this question.

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