
たとえば、ソース TeX ファイルのない 30 ページの PDF を含む論文が 5 つあるとします。LaTeX で各論文をリストする目次を作成するにはどうすればよいでしょうか。また、含まれる各 PDF にページ番号を割り当てるにはどうすればよいでしょうか。
答え1
パッケージ tocloft を使用して、\tableofcontents
マスター ドキュメント内の目次を表示する場所に追加します。
目次にセクションを追加するには、セクションが自動的に選択されない場合は、以下のコードを使用できます。目次に表示したい各セクション見出しの下にコードを追加し、セクション見出しを section_name に置き換えます。
\addcontentsline{toc}{Chapter}{\protect\numberline{}section_name}
章をセクションやサブセクションなどの別のセクション タイプに置き換えて、目次に表示されるレベルを定義することができます。
セクションが明確に定義されていない場合は、次のようなものを使用します。
\clearpage
\phantomsection\addcontentsline{toc}{chapter}{\protect\numberline{section_name}
目次のアンカー ポイントを提供し、目次への参照ポイントとして section_name を追加します。
答え2
パッケージを使用しpdfpages
て PDF を含め、コマンドpagecommand
のオプションにセクション分割またはコンテンツへの追加コマンドを含めます\includepdf
。
たとえば、サブディレクトリ.tex
にベース ファイルと添付する 2 つの PDFがあるとしますpdfs
。(必ず 2 回コンパイルしてください。)
\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\tableofcontents
\section{Main Text}
Two attachments follow. % I show two different ways below.
% (1) With a section command in the main file
% (the heading will be printed on a separate page,
% but will not overlap with inserted PDF content)
\clearpage\section{First Attachment}
\includepdf[pages=-]{pdfs/doc1} % pages=- means all pages
% (2) With a pagecommand (heading will be printed ON
% the inserted PDF, so may overlap with content)
\includepdf[pages=1, pagecommand={\section{Second Attachment}}]{pdfs/doc2}
\includepdf[pages=2-last]{pdfs/doc2}
\end{document}
PDF 1 (pdfs/doc1.tex からコンパイル)
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1-19]
\end{document}
PDF 2 (pdfs/doc2.tex からコンパイル)
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[20-29]
\end{document}