章節標題隱藏在 pdf 插入內容下方

章節標題隱藏在 pdf 插入內容下方

我想包含我使用命令的 pdf 文件 \includepdf[]{filename},效果很好。基本上我的整個文件都是由 pdf 文件組成的,所以我現在想包含章節標題。但是,僅使用\chapter{name}會給出一個空白頁面,其中 pdf 檔案之前僅包含章節標題。標題不一定要位於 pdf 的頂部,因為我可以在 pdf 中包含標題名稱,但我只希望章節標題顯示在目錄中。

答案1

  • 使用選項addtotoc為目錄建立條目。
  • 不是嘗試\includepdf使用\chapter, \section, ... 指令進行餵食。這將會失敗。
  • 使用選項picturecommand*在包含的 PDF 的第一頁上寫一些內容。 (如果您使用,它至少看起來像一個章節標題\thesection,...)

這是一個例子:

\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}

答案2

這會修剪掉舊的頁腳和頁眉,並用新的頁腳和頁眉替換它們。它採用通用的頁面佈局。

\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}

其中 test6 是使用建立的

\documentclass{book}
\usepackage{lipsum}

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

相關內容