Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to make Table of Contents for a set of PDF files?

Here's my code!

\documentclass{book}
\usepackage{pdfpages}
\usepackage[pdfauthor={<somename>},pdftitle={<sometitle>},pdftex]{hyperref}
\usepackage{fancyhdr}
\usepackage{tocloft}
\usepackage[margin=0.5in,bottom=0.75in,top=0.75in]{geometry}


\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.4pt}
\fancyhead[L]{X Y Z}
\fancyhead[R]{}
\begin{document}

\tableofcontents
\newpage

\clearpage
\phantomsection
\includepdfset{pages=-,pagecommand=\thispagestyle{fancy}}
\addcontentsline{toc}{chapter}{SAMPLE PDF 1\\ \textit{description}}
\includepdf[pages=-]{template1.pdf}

\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{SAMPLE PDF 2\\ \textit{description}}
\includepdf[pages=-]{template2.pdf}

\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{SAMPLE PDF 3\\ \textit{description}}
\includepdf[pages=-]{template3.pdf}

\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{SAMPLE PDF 4\\ \textit{description}}
\includepdf[pages=-]{template4.pdf}

\clearpage
\phantomsection
\addcontentsline{toc}{chapter}{SAMPLE PDF 5\\ \textit{description}}
\includepdf[pages=-]{template5.pdf}

\end{document}

Here's the output.

enter image description here

My problem is that the page number is not aligned with the title, it is aligned with the description. Also I'd like to put dots.

My desired output looks like this:enter image description here

share|improve this question
2  
Please don't use an external reference for your question. Linking to it is ok if you really want to, but try to make the question self-contained, so that answerers don't need to work simply to understand the question. –  T. Verron May 3 '13 at 6:31

2 Answers 2

up vote 3 down vote accepted

This is adapted from some code I wrote once for a similar purpose. You simply call the macro \insertmydocument instead of \includepdf.

For the description, it turns out tocloft can handle the typesetting of a "chapter precis" in toc, in text or both. It seems to be exactly what you are looking for.

%The default settings should add dots, but for whatever reason it doesn't. This fixes it.
\renewcommand{\cftchapleader}{\cftdotsfill{\cftchapdotsep}}

\newcommand{\insertmydocument}[4]%
           { % Syntax: \insertmydocument{Toc level}{Title}{Subtitle}{File}
             % Requires: tocloft hyperref pdfpages
             \newpage
             \phantomsection
             \cftaddtitleline{toc}{#1}{#2}{\thepage}
             \cftchapterprecistoc{#3}
             \includepdf[pages=-]{#4}
           }

I suggest you add colorlink to the hyperref options, so that the links are colored instead of boxed. This will get rid of the big box on the first line.

Full example

\documentclass{report}

\usepackage{pdfpages}

\usepackage{tocloft}

\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}

\usepackage[colorlinks]{hyperref}


\newcommand{\insertmydocument}[4]%
           { % Syntax: \insertmydocument{Toc level}{Title}{Subtitle}{File}
             % Requires: tocloft hyperref pdfpages
             \newpage
             \phantomsection
             \cftaddtitleline{toc}{#1}{#2}{\thepage}
             \cftchapterprecistoc{#3}
            \includepdf[pages=-]{#4}
           }


\begin{document}


\tableofcontents

\chapter{A regular chapter}

\insertmydocument{chapter}{A pdf}{Description}{document.pdf}

\chapter{Another chapter}

\end{document}

enter image description here

share|improve this answer
    
@ScareCrow : I hadn't understood the layout you were after. I edited my answer. –  T. Verron May 3 '13 at 9:51
    
@ T.Verron i want a layout like this: i.imgur.com/7tmSrId.png?1. im a newbie i want to try your code but i dont know where to put your codes in my codes. can you give me an example of a whole code? –  Scare Crow May 4 '13 at 3:37
    
@ScareCrow: Added the full code for the picture, you might need to change the name of the inserted pdf of course. –  T. Verron May 4 '13 at 5:15

for each PDF you can use the option addtotoc from pdfpages:

\includepdf[addtotoc={1,chapter,0,SAMPLE PDF 1,chap:samplepdfone}]{template1.pdf} 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.